From 6c69d72d34e9163ba1c90a930e70e1dd6d5af303 Mon Sep 17 00:00:00 2001 From: Kevin Froman Date: Sun, 16 Jun 2019 23:24:12 -0500 Subject: [PATCH] + added add to contact button in box message viewer * fixed/improved name setting for friends/contacts --- .../default-plugins/pms/mailapi.py | 2 + onionr/static-data/www/mail/index.html | 4 +- onionr/static-data/www/mail/mail.css | 5 ++- onionr/static-data/www/mail/mail.js | 38 ++++++++++++++++--- 4 files changed, 41 insertions(+), 8 deletions(-) diff --git a/onionr/static-data/default-plugins/pms/mailapi.py b/onionr/static-data/default-plugins/pms/mailapi.py index c9df3a52..2ba99d08 100755 --- a/onionr/static-data/default-plugins/pms/mailapi.py +++ b/onionr/static-data/default-plugins/pms/mailapi.py @@ -60,4 +60,6 @@ def list_sentbox(): for x in list_copy: if x['hash'] in deleted: sentbox_list.remove(x) + continue + x['name'] = contactmanager.ContactManager(c, x['peer'], saveUser=False).get_info('name') return json.dumps(sentbox_list) diff --git a/onionr/static-data/www/mail/index.html b/onionr/static-data/www/mail/index.html index 81a0128e..4a671ab5 100755 --- a/onionr/static-data/www/mail/index.html +++ b/onionr/static-data/www/mail/index.html @@ -22,7 +22,7 @@ API server either shutdown, has disabled mail, or has experienced a bug.
-
Current Used Identity:
+
🕵️‍♂️ Current Used Identity:


@@ -34,7 +34,7 @@
- From: Signature: + From: Signature:
Subject: diff --git a/onionr/static-data/www/mail/mail.css b/onionr/static-data/www/mail/mail.css index 88afc0b9..32999440 100755 --- a/onionr/static-data/www/mail/mail.css +++ b/onionr/static-data/www/mail/mail.css @@ -54,10 +54,13 @@ input{ } .mailPing{ - display: none; color: orange; } + #addUnknownContact, .mailPing{ + display: none; + } + .danger{ color: red; } diff --git a/onionr/static-data/www/mail/mail.js b/onionr/static-data/www/mail/mail.js index fb7b2b3a..cc4895a1 100755 --- a/onionr/static-data/www/mail/mail.js +++ b/onionr/static-data/www/mail/mail.js @@ -24,6 +24,19 @@ threadPlaceholder = document.getElementById('threadPlaceholder') tabBtns = document.getElementById('tabBtns') threadContent = {} 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){ var inbox = document.getElementsByClassName('threadEntry') @@ -53,6 +66,7 @@ function openReply(bHash, quote, subject){ } function openThread(bHash, sender, date, sigBool, pubkey, subjectLine){ + addUnknownContact.style.display = 'none' var messageDisplay = document.getElementById('threadDisplay') var blockContent = httpGet('/getblockbody/' + bHash) @@ -62,6 +76,11 @@ function openThread(bHash, sender, date, sigBool, pubkey, subjectLine){ var sigEl = document.getElementById('sigValid') 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){ sigMsg = 'Good ' + sigMsg sigEl.classList.remove('danger') @@ -76,6 +95,13 @@ function openThread(bHash, sender, date, sigBool, pubkey, subjectLine){ replyBtn.onclick = function(){ 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){ @@ -144,6 +170,7 @@ function loadInboxEntries(bHash){ var humanDate = new Date(0) var metadata = resp['metadata'] humanDate.setUTCSeconds(resp['meta']['time']) + humanDate = humanDate.toString() validSig.style.display = 'none' if (resp['meta']['signer'] != ''){ senderInput.value = httpGet('/friends/getinfo/' + resp['meta']['signer'] + '/name') @@ -162,7 +189,7 @@ function loadInboxEntries(bHash){ entry.setAttribute('data-hash', bHash) entry.setAttribute('data-pubkey', resp['meta']['signer']) senderInput.readOnly = true - dateStr.innerText = humanDate.toString() + dateStr.innerText = humanDate.substring(0, humanDate.indexOf('(')) deleteBtn.innerText = 'X' deleteBtn.classList.add('dangerBtn', 'deleteBtn') if (metadata['subject'] === undefined || metadata['subject'] === null) { @@ -237,14 +264,15 @@ function getSentbox(){ var sentDate = document.createElement('span') var humanDate = new Date(0) humanDate.setUTCSeconds(resp[i]['date']) + humanDate = humanDate.toString() var preview = document.createElement('span') var deleteBtn = document.createElement('button') var message = resp[i]['message'] deleteBtn.classList.add('deleteBtn', 'dangerBtn') deleteBtn.innerText = 'X' toEl.readOnly = true - sentDate.innerText = humanDate - if (resp[i]['name'] == null){ + sentDate.innerText = humanDate.substring(0, humanDate.indexOf('(')) + if (resp[i]['name'] == null || resp[i]['name'].toLowerCase() == 'anonymous'){ toEl.value = resp[i]['peer'] } else{ @@ -266,7 +294,7 @@ function getSentbox(){ e.target.parentNode.parentNode.removeChild(e.target.parentNode) return } - showSentboxWindow(resp[i]['peer'], message) + showSentboxWindow(toEl.value, message) } })(i, resp) threadPart.appendChild(entry) @@ -319,7 +347,7 @@ fetch('/friends/list', { friendSelectParent.appendChild(document.createElement('option')) for (var i = 0; i < keys.length; i++) { var option = document.createElement("option") - var name = resp[keys[i]]['name'] + var name = resp[keys[i]]['name'] || "" option.value = keys[i] if (name.length == 0){ option.text = keys[i]