+ added add to contact button in box message viewer

* fixed/improved name setting for friends/contacts
master
Kevin Froman 2019-06-16 23:24:12 -05:00
parent b377890a79
commit 6c69d72d34
4 changed files with 41 additions and 8 deletions

View File

@ -60,4 +60,6 @@ def list_sentbox():
for x in list_copy: for x in list_copy:
if x['hash'] in deleted: if x['hash'] in deleted:
sentbox_list.remove(x) sentbox_list.remove(x)
continue
x['name'] = contactmanager.ContactManager(c, x['peer'], saveUser=False).get_info('name')
return json.dumps(sentbox_list) return json.dumps(sentbox_list)

View File

@ -22,7 +22,7 @@
API server either shutdown, has disabled mail, or has experienced a bug. API server either shutdown, has disabled mail, or has experienced a bug.
</div> </div>
<br> <br>
<div>Current Used Identity: <input class='myPub' type='text' readonly></div> <div>🕵️‍♂️ Current Used Identity: <input class='myPub' type='text' readonly></div>
<br><br> <br><br>
<div class="btn-group" id='tabBtns'> <div class="btn-group" id='tabBtns'>
<button class='activeTab'>Inbox</button><button>Sentbox</button><button>Send Message</button> <button class='activeTab'>Inbox</button><button>Sentbox</button><button>Send Message</button>
@ -34,7 +34,7 @@
<div class='overlayContent'> <div class='overlayContent'>
<span class='closeOverlay' overlay='messageDisplay'></span> <span class='closeOverlay' overlay='messageDisplay'></span>
<div> <div>
From: <input type='text' id='fromUser' readonly> Signature: <span id='sigValid'></span> From: <input type='text' id='fromUser' readonly> Signature: <span id='sigValid'></span> <span id='addUnknownContact'><button>Add to Contacts</button></span>
</div> </div>
<div class='break-up'> <div class='break-up'>
Subject: <span id='subjectView'></span> Subject: <span id='subjectView'></span>

View File

@ -54,10 +54,13 @@ input{
} }
.mailPing{ .mailPing{
display: none;
color: orange; color: orange;
} }
#addUnknownContact, .mailPing{
display: none;
}
.danger{ .danger{
color: red; color: red;
} }

View File

@ -24,6 +24,19 @@ threadPlaceholder = document.getElementById('threadPlaceholder')
tabBtns = document.getElementById('tabBtns') tabBtns = document.getElementById('tabBtns')
threadContent = {} threadContent = {}
replyBtn = document.getElementById('replyBtn') replyBtn = document.getElementById('replyBtn')
addUnknownContact = document.getElementById('addUnknownContact')
function addContact(pubkey, friendName){
fetch('/friends/add/' + pubkey, {
method: 'POST',
headers: {
"token": webpass
}}).then(function(data) {
if (friendName.trim().length > 0){
post_to_url('/friends/setinfo/' + pubkey + '/name', {'data': friendName, 'token': webpass})
}
})
}
function openReply(bHash, quote, subject){ function openReply(bHash, quote, subject){
var inbox = document.getElementsByClassName('threadEntry') var inbox = document.getElementsByClassName('threadEntry')
@ -53,6 +66,7 @@ function openReply(bHash, quote, subject){
} }
function openThread(bHash, sender, date, sigBool, pubkey, subjectLine){ function openThread(bHash, sender, date, sigBool, pubkey, subjectLine){
addUnknownContact.style.display = 'none'
var messageDisplay = document.getElementById('threadDisplay') var messageDisplay = document.getElementById('threadDisplay')
var blockContent = httpGet('/getblockbody/' + bHash) var blockContent = httpGet('/getblockbody/' + bHash)
@ -62,6 +76,11 @@ function openThread(bHash, sender, date, sigBool, pubkey, subjectLine){
var sigEl = document.getElementById('sigValid') var sigEl = document.getElementById('sigValid')
var sigMsg = 'signature' var sigMsg = 'signature'
// show add unknown contact button if peer is unknown but still has pubkey
if (sender == pubkey){
addUnknownContact.style.display = 'inline'
}
if (sigBool){ if (sigBool){
sigMsg = 'Good ' + sigMsg sigMsg = 'Good ' + sigMsg
sigEl.classList.remove('danger') sigEl.classList.remove('danger')
@ -76,6 +95,13 @@ function openThread(bHash, sender, date, sigBool, pubkey, subjectLine){
replyBtn.onclick = function(){ replyBtn.onclick = function(){
openReply(bHash, messageDisplay.innerText, subjectLine) openReply(bHash, messageDisplay.innerText, subjectLine)
} }
addUnknownContact.onclick = function(){
var friendName = prompt("Enter an alias for this contact:")
if (friendName === null || friendName.length == 0){
return
}
addContact(pubkey, friendName)
}
} }
function setActiveTab(tabName){ function setActiveTab(tabName){
@ -144,6 +170,7 @@ function loadInboxEntries(bHash){
var humanDate = new Date(0) var humanDate = new Date(0)
var metadata = resp['metadata'] var metadata = resp['metadata']
humanDate.setUTCSeconds(resp['meta']['time']) humanDate.setUTCSeconds(resp['meta']['time'])
humanDate = humanDate.toString()
validSig.style.display = 'none' validSig.style.display = 'none'
if (resp['meta']['signer'] != ''){ if (resp['meta']['signer'] != ''){
senderInput.value = httpGet('/friends/getinfo/' + resp['meta']['signer'] + '/name') senderInput.value = httpGet('/friends/getinfo/' + resp['meta']['signer'] + '/name')
@ -162,7 +189,7 @@ function loadInboxEntries(bHash){
entry.setAttribute('data-hash', bHash) entry.setAttribute('data-hash', bHash)
entry.setAttribute('data-pubkey', resp['meta']['signer']) entry.setAttribute('data-pubkey', resp['meta']['signer'])
senderInput.readOnly = true senderInput.readOnly = true
dateStr.innerText = humanDate.toString() dateStr.innerText = humanDate.substring(0, humanDate.indexOf('('))
deleteBtn.innerText = 'X' deleteBtn.innerText = 'X'
deleteBtn.classList.add('dangerBtn', 'deleteBtn') deleteBtn.classList.add('dangerBtn', 'deleteBtn')
if (metadata['subject'] === undefined || metadata['subject'] === null) { if (metadata['subject'] === undefined || metadata['subject'] === null) {
@ -237,14 +264,15 @@ function getSentbox(){
var sentDate = document.createElement('span') var sentDate = document.createElement('span')
var humanDate = new Date(0) var humanDate = new Date(0)
humanDate.setUTCSeconds(resp[i]['date']) humanDate.setUTCSeconds(resp[i]['date'])
humanDate = humanDate.toString()
var preview = document.createElement('span') var preview = document.createElement('span')
var deleteBtn = document.createElement('button') var deleteBtn = document.createElement('button')
var message = resp[i]['message'] var message = resp[i]['message']
deleteBtn.classList.add('deleteBtn', 'dangerBtn') deleteBtn.classList.add('deleteBtn', 'dangerBtn')
deleteBtn.innerText = 'X' deleteBtn.innerText = 'X'
toEl.readOnly = true toEl.readOnly = true
sentDate.innerText = humanDate sentDate.innerText = humanDate.substring(0, humanDate.indexOf('('))
if (resp[i]['name'] == null){ if (resp[i]['name'] == null || resp[i]['name'].toLowerCase() == 'anonymous'){
toEl.value = resp[i]['peer'] toEl.value = resp[i]['peer']
} }
else{ else{
@ -266,7 +294,7 @@ function getSentbox(){
e.target.parentNode.parentNode.removeChild(e.target.parentNode) e.target.parentNode.parentNode.removeChild(e.target.parentNode)
return return
} }
showSentboxWindow(resp[i]['peer'], message) showSentboxWindow(toEl.value, message)
} }
})(i, resp) })(i, resp)
threadPart.appendChild(entry) threadPart.appendChild(entry)
@ -319,7 +347,7 @@ fetch('/friends/list', {
friendSelectParent.appendChild(document.createElement('option')) friendSelectParent.appendChild(document.createElement('option'))
for (var i = 0; i < keys.length; i++) { for (var i = 0; i < keys.length; i++) {
var option = document.createElement("option") var option = document.createElement("option")
var name = resp[keys[i]]['name'] var name = resp[keys[i]]['name'] || ""
option.value = keys[i] option.value = keys[i]
if (name.length == 0){ if (name.length == 0){
option.text = keys[i] option.text = keys[i]