Onionr/onionr/static-data/www/mail/mail.js

131 lines
4.1 KiB
JavaScript
Raw Normal View History

2019-02-04 00:31:03 +00:00
/*
Onionr - P2P Anonymous Storage Network
This file handles the mail interface
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
pms = ''
threadPart = document.getElementById('threads')
2019-02-03 18:19:50 +00:00
threadPlaceholder = document.getElementById('threadPlaceholder')
2019-02-04 00:31:03 +00:00
tabBtns = document.getElementById('tabBtns')
myPub = httpGet('/getActivePubkey')
function setActiveTab(tabName){
threadPart.innerHTML = ""
switch(tabName){
case 'inbox':
getInbox();
break
case 'sentbox':
console.log(tabName)
break
case 'drafts':
console.log(tabName)
break
case 'send message':
console.log(tabName)
break
}
}
function getInbox(){
2019-02-03 18:19:50 +00:00
var showed = false
for(var i = 0; i < pms.length; i++) {
2019-02-03 18:19:50 +00:00
if (pms[i].trim().length == 0){
continue
}
else{
threadPlaceholder.style.display = 'none'
showed = true
}
fetch('/getblockdata/' + pms[i], {
headers: {
"token": webpass
}})
.then((resp) => resp.json()) // Transform the data into json
.then(function(resp) {
var entry = document.createElement('div')
2019-02-03 18:19:50 +00:00
var bHashDisplay = document.createElement('span')
var senderInput = document.createElement('input')
var subjectLine = document.createElement('span')
var dateStr = document.createElement('span')
var humanDate = new Date(0)
humanDate.setUTCSeconds(resp['meta']['time'])
2019-02-04 00:31:03 +00:00
senderInput.value = httpGet('/getHumanReadable/' + resp['meta']['signer'])
bHashDisplay.innerText = pms[i - 1].substring(0, 10)
bHashDisplay.setAttribute('hash', pms[i - 1]);
senderInput.readOnly = true
dateStr.innerText = humanDate.toString()
if (resp['metadata']['subject'] === undefined || resp['metadata']['subject'] === null) {
subjectLine.innerText = '()'
}
else{
subjectLine.innerText = '(' + resp['metadata']['subject'] + ')'
}
//entry.innerHTML = 'sender ' + resp['meta']['signer'] + ' - ' + resp['meta']['time']
threadPart.appendChild(entry)
2019-02-03 18:19:50 +00:00
//entry.appendChild(bHashDisplay)
entry.appendChild(senderInput)
entry.appendChild(subjectLine)
entry.appendChild(dateStr)
}.bind([pms, i]))
}
2019-02-03 18:19:50 +00:00
if (! showed){
threadPlaceholder.style.display = 'block'
}
}
2019-02-04 00:31:03 +00:00
fetch('/getblocksbytype/pm', {
headers: {
"token": webpass
}})
.then((resp) => resp.text()) // Transform the data into json
.then(function(data) {
pms = data.split(',')
2019-02-04 00:31:03 +00:00
setActiveTab('inbox')
})
2019-02-04 00:31:03 +00:00
tabBtns.onclick = function(event){
var children = tabBtns.children
for (var i = 0; i < children.length; i++) {
var btn = children[i]
btn.classList.remove('activeTab')
}
event.target.classList.add('activeTab')
setActiveTab(event.target.innerText.toLowerCase())
}
var idStrings = document.getElementsByClassName('myPub')
var myHumanReadable = httpGet('/getHumanReadable/' + myPub)
for (var i = 0; i < idStrings.length; i++){
if (idStrings[i].tagName.toLowerCase() == 'input'){
idStrings[i].value = myHumanReadable
}
else{
idStrings[i].innerText = myHumanReadable
}
}
for (var i = 0; i < document.getElementsByClassName('refresh').length; i++){
document.getElementsByClassName('refresh')[i].style.float = 'right'
}