work on mail ui deletion of items
This commit is contained in:
parent
c45c016123
commit
4798308ccd
@ -17,11 +17,11 @@
|
|||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
'''
|
'''
|
||||||
import sys, os
|
import sys, os, json
|
||||||
from flask import Response, request, redirect, Blueprint
|
from flask import Response, request, redirect, Blueprint, abort
|
||||||
import core
|
import core
|
||||||
sys.path.insert(0, os.path.dirname(os.path.realpath(__file__)))
|
sys.path.insert(0, os.path.dirname(os.path.realpath(__file__)))
|
||||||
import loadinbox
|
import loadinbox, sentboxdb
|
||||||
|
|
||||||
flask_blueprint = Blueprint('mail', __name__)
|
flask_blueprint = Blueprint('mail', __name__)
|
||||||
c = core.Core()
|
c = core.Core()
|
||||||
@ -29,7 +29,8 @@ kv = c.keyStore
|
|||||||
|
|
||||||
@flask_blueprint.route('/mail/deletemsg/<block>', methods=['POST'])
|
@flask_blueprint.route('/mail/deletemsg/<block>', methods=['POST'])
|
||||||
def mail_delete(block):
|
def mail_delete(block):
|
||||||
assert c._utils.validateHash(block)
|
if not c._utils.validateHash(block):
|
||||||
|
abort(504)
|
||||||
existing = kv.get('deleted_mail')
|
existing = kv.get('deleted_mail')
|
||||||
if existing is None:
|
if existing is None:
|
||||||
existing = []
|
existing = []
|
||||||
@ -40,4 +41,23 @@ def mail_delete(block):
|
|||||||
|
|
||||||
@flask_blueprint.route('/mail/getinbox')
|
@flask_blueprint.route('/mail/getinbox')
|
||||||
def list_inbox():
|
def list_inbox():
|
||||||
return ','.join(loadinbox.load_inbox(c))
|
return ','.join(loadinbox.load_inbox(c))
|
||||||
|
|
||||||
|
@flask_blueprint.route('/mail/getsentbox')
|
||||||
|
def list_sentbox():
|
||||||
|
sentbox_list = sentboxdb.SentBox(c).listSent()
|
||||||
|
sentbox_list_copy = list(sentbox_list)
|
||||||
|
deleted = kv.get('deleted_mail')
|
||||||
|
if deleted is None:
|
||||||
|
deleted = []
|
||||||
|
for x in range(len(sentbox_list_copy)):
|
||||||
|
if sentbox_list_copy[x]['hash'] in deleted:
|
||||||
|
sentbox_list.pop(x)
|
||||||
|
|
||||||
|
'''
|
||||||
|
hash_list = []
|
||||||
|
for x in sentbox_list:
|
||||||
|
hash_list.append({x['hash'])
|
||||||
|
return ','.join(hash_list)
|
||||||
|
'''
|
||||||
|
return json.dumps(sentbox_list)
|
@ -307,23 +307,6 @@ def on_insertblock(api, data={}):
|
|||||||
meta = json.loads(data['meta'])
|
meta = json.loads(data['meta'])
|
||||||
sentboxTools.addToSent(data['hash'], data['peer'], data['content'], meta['subject'])
|
sentboxTools.addToSent(data['hash'], data['peer'], data['content'], meta['subject'])
|
||||||
|
|
||||||
def on_pluginrequest(api, data=None):
|
|
||||||
resp = ''
|
|
||||||
subject = ''
|
|
||||||
recip = ''
|
|
||||||
message = ''
|
|
||||||
postData = {}
|
|
||||||
blockID = ''
|
|
||||||
sentboxTools = sentboxdb.SentBox(api.get_core())
|
|
||||||
keyStore = api.get_core().keyStore
|
|
||||||
if data['name'] == 'mail':
|
|
||||||
path = data['path']
|
|
||||||
print(cmd)
|
|
||||||
cmd = path.split('/')[1]
|
|
||||||
if cmd == 'sentbox':
|
|
||||||
resp = OnionrMail(api).get_sent_list(display=False)
|
|
||||||
if resp != '':
|
|
||||||
api.get_onionr().clientAPIInst.pluginResponses[data['pluginResponse']] = resp
|
|
||||||
|
|
||||||
def on_init(api, data = None):
|
def on_init(api, data = None):
|
||||||
'''
|
'''
|
||||||
|
@ -25,10 +25,15 @@ class SentBox:
|
|||||||
self.dbLocation = mycore.dataDir + 'sentbox.db'
|
self.dbLocation = mycore.dataDir + 'sentbox.db'
|
||||||
if not os.path.exists(self.dbLocation):
|
if not os.path.exists(self.dbLocation):
|
||||||
self.createDB()
|
self.createDB()
|
||||||
self.conn = sqlite3.connect(self.dbLocation)
|
|
||||||
self.cursor = self.conn.cursor()
|
|
||||||
self.core = mycore
|
self.core = mycore
|
||||||
return
|
return
|
||||||
|
|
||||||
|
def connect(self):
|
||||||
|
self.conn = sqlite3.connect(self.dbLocation)
|
||||||
|
self.cursor = self.conn.cursor()
|
||||||
|
|
||||||
|
def close(self):
|
||||||
|
self.conn.close()
|
||||||
|
|
||||||
def createDB(self):
|
def createDB(self):
|
||||||
conn = sqlite3.connect(self.dbLocation)
|
conn = sqlite3.connect(self.dbLocation)
|
||||||
@ -42,22 +47,29 @@ class SentBox:
|
|||||||
);
|
);
|
||||||
''')
|
''')
|
||||||
conn.commit()
|
conn.commit()
|
||||||
|
conn.close()
|
||||||
return
|
return
|
||||||
|
|
||||||
def listSent(self):
|
def listSent(self):
|
||||||
|
self.connect()
|
||||||
retData = []
|
retData = []
|
||||||
for entry in self.cursor.execute('SELECT * FROM sent;'):
|
for entry in self.cursor.execute('SELECT * FROM sent;'):
|
||||||
retData.append({'hash': entry[0], 'peer': entry[1], 'message': entry[2], 'subject': entry[3], 'date': entry[4]})
|
retData.append({'hash': entry[0], 'peer': entry[1], 'message': entry[2], 'subject': entry[3], 'date': entry[4]})
|
||||||
|
self.close()
|
||||||
return retData
|
return retData
|
||||||
|
|
||||||
def addToSent(self, blockID, peer, message, subject=''):
|
def addToSent(self, blockID, peer, message, subject=''):
|
||||||
|
self.connect()
|
||||||
args = (blockID, peer, message, subject, self.core._utils.getEpoch())
|
args = (blockID, peer, message, subject, self.core._utils.getEpoch())
|
||||||
self.cursor.execute('INSERT INTO sent VALUES(?, ?, ?, ?, ?)', args)
|
self.cursor.execute('INSERT INTO sent VALUES(?, ?, ?, ?, ?)', args)
|
||||||
self.conn.commit()
|
self.conn.commit()
|
||||||
|
self.close()
|
||||||
return
|
return
|
||||||
|
|
||||||
def removeSent(self, blockID):
|
def removeSent(self, blockID):
|
||||||
|
self.connect()
|
||||||
args = (blockID,)
|
args = (blockID,)
|
||||||
self.cursor.execute('DELETE FROM sent where hash=?', args)
|
self.cursor.execute('DELETE FROM sent where hash=?', args)
|
||||||
self.conn.commit()
|
self.conn.commit()
|
||||||
|
self.close()
|
||||||
return
|
return
|
||||||
|
@ -71,6 +71,7 @@ function setActiveTab(tabName){
|
|||||||
threadPart.innerHTML = ""
|
threadPart.innerHTML = ""
|
||||||
switch(tabName){
|
switch(tabName){
|
||||||
case 'inbox':
|
case 'inbox':
|
||||||
|
refreshPms()
|
||||||
getInbox()
|
getInbox()
|
||||||
break
|
break
|
||||||
case 'sentbox':
|
case 'sentbox':
|
||||||
@ -82,6 +83,17 @@ function setActiveTab(tabName){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function deleteMessage(bHash){
|
||||||
|
fetch('/mail/deletemsg/' + bHash, {
|
||||||
|
"method": "post",
|
||||||
|
headers: {
|
||||||
|
"token": webpass
|
||||||
|
}})
|
||||||
|
.then((resp) => resp.text()) // Transform the data into json
|
||||||
|
.then(function(resp) {
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
function loadInboxEntries(bHash){
|
function loadInboxEntries(bHash){
|
||||||
fetch('/getblockheader/' + bHash, {
|
fetch('/getblockheader/' + bHash, {
|
||||||
headers: {
|
headers: {
|
||||||
@ -96,6 +108,7 @@ function loadInboxEntries(bHash){
|
|||||||
var subjectLine = document.createElement('span')
|
var subjectLine = document.createElement('span')
|
||||||
var dateStr = document.createElement('span')
|
var dateStr = document.createElement('span')
|
||||||
var validSig = document.createElement('span')
|
var validSig = document.createElement('span')
|
||||||
|
var deleteBtn = document.createElement('button')
|
||||||
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'])
|
||||||
@ -119,6 +132,8 @@ function loadInboxEntries(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.toString()
|
||||||
|
deleteBtn.innerText = 'X'
|
||||||
|
deleteBtn.classList.add('dangerBtn', 'deleteBtn')
|
||||||
if (metadata['subject'] === undefined || metadata['subject'] === null) {
|
if (metadata['subject'] === undefined || metadata['subject'] === null) {
|
||||||
subjectLine.innerText = '()'
|
subjectLine.innerText = '()'
|
||||||
}
|
}
|
||||||
@ -127,6 +142,7 @@ function loadInboxEntries(bHash){
|
|||||||
}
|
}
|
||||||
//entry.innerHTML = 'sender ' + resp['meta']['signer'] + ' - ' + resp['meta']['time']
|
//entry.innerHTML = 'sender ' + resp['meta']['signer'] + ' - ' + resp['meta']['time']
|
||||||
threadPart.appendChild(entry)
|
threadPart.appendChild(entry)
|
||||||
|
entry.appendChild(deleteBtn)
|
||||||
entry.appendChild(bHashDisplay)
|
entry.appendChild(bHashDisplay)
|
||||||
entry.appendChild(senderInput)
|
entry.appendChild(senderInput)
|
||||||
entry.appendChild(validSig)
|
entry.appendChild(validSig)
|
||||||
@ -134,9 +150,17 @@ function loadInboxEntries(bHash){
|
|||||||
entry.appendChild(dateStr)
|
entry.appendChild(dateStr)
|
||||||
entry.classList.add('threadEntry')
|
entry.classList.add('threadEntry')
|
||||||
|
|
||||||
entry.onclick = function(){
|
entry.onclick = function(event){
|
||||||
|
if (event.target.classList.contains('deleteBtn')){
|
||||||
|
return
|
||||||
|
}
|
||||||
openThread(entry.getAttribute('data-hash'), senderInput.value, dateStr.innerText, resp['meta']['validSig'], entry.getAttribute('data-pubkey'))
|
openThread(entry.getAttribute('data-hash'), senderInput.value, dateStr.innerText, resp['meta']['validSig'], entry.getAttribute('data-pubkey'))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
deleteBtn.onclick = function(){
|
||||||
|
entry.parentNode.removeChild(entry);
|
||||||
|
deleteMessage(entry.getAttribute('data-hash'))
|
||||||
|
}
|
||||||
|
|
||||||
}.bind(bHash))
|
}.bind(bHash))
|
||||||
}
|
}
|
||||||
@ -160,7 +184,7 @@ function getInbox(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getSentbox(){
|
function getSentbox(){
|
||||||
fetch('/apipoints/mail/sentbox', {
|
fetch('/mail/getsentbox', {
|
||||||
headers: {
|
headers: {
|
||||||
"token": webpass
|
"token": webpass
|
||||||
}})
|
}})
|
||||||
@ -180,16 +204,27 @@ function getSentbox(){
|
|||||||
toLabel.innerText = 'To: '
|
toLabel.innerText = 'To: '
|
||||||
var toEl = document.createElement('input')
|
var toEl = document.createElement('input')
|
||||||
var preview = document.createElement('span')
|
var preview = document.createElement('span')
|
||||||
|
var deleteBtn = document.createElement('button')
|
||||||
|
deleteBtn.classList.add('deleteBtn', 'dangerBtn')
|
||||||
|
deleteBtn.innerText = 'X'
|
||||||
toEl.readOnly = true
|
toEl.readOnly = true
|
||||||
toEl.value = resp[keys[i]][1]
|
toEl.value = resp[i]['peer']
|
||||||
preview.innerText = '(' + resp[keys[i]][2] + ')'
|
preview.innerText = '(' + resp[i]['subject'] + ')'
|
||||||
|
entry.setAttribute('data-hash', resp[i]['hash'])
|
||||||
|
entry.appendChild(deleteBtn)
|
||||||
entry.appendChild(toLabel)
|
entry.appendChild(toLabel)
|
||||||
entry.appendChild(toEl)
|
entry.appendChild(toEl)
|
||||||
entry.appendChild(preview)
|
entry.appendChild(preview)
|
||||||
entryUsed = resp[keys[i]]
|
entryUsed = resp[i]['message']
|
||||||
entry.onclick = function(){
|
entry.onclick = function(){
|
||||||
console.log(resp)
|
console.log(resp)
|
||||||
showSentboxWindow(toEl.value, entryUsed[0])
|
if (! entry.target.classList.contains('deleteBtn')){
|
||||||
|
showSentboxWindow(toEl.value, entryUsed)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
deleteBtn.onclick = function(){
|
||||||
|
entry.parentNode.removeChild(entry);
|
||||||
|
deleteMessage(entry.getAttribute('data-hash'))
|
||||||
}
|
}
|
||||||
threadPart.appendChild(entry)
|
threadPart.appendChild(entry)
|
||||||
}
|
}
|
||||||
@ -203,6 +238,7 @@ function showSentboxWindow(to, content){
|
|||||||
overlay('sentboxDisplay')
|
overlay('sentboxDisplay')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function refreshPms(){
|
||||||
fetch('/mail/getinbox', {
|
fetch('/mail/getinbox', {
|
||||||
headers: {
|
headers: {
|
||||||
"token": webpass
|
"token": webpass
|
||||||
@ -210,8 +246,8 @@ fetch('/mail/getinbox', {
|
|||||||
.then((resp) => resp.text()) // Transform the data into json
|
.then((resp) => resp.text()) // Transform the data into json
|
||||||
.then(function(data) {
|
.then(function(data) {
|
||||||
pms = data.split(',')
|
pms = data.split(',')
|
||||||
setActiveTab('inbox')
|
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
|
||||||
tabBtns.onclick = function(event){
|
tabBtns.onclick = function(event){
|
||||||
var children = tabBtns.children
|
var children = tabBtns.children
|
||||||
@ -273,4 +309,6 @@ fetch('/friends/list', {
|
|||||||
//friendSelectParent
|
//friendSelectParent
|
||||||
//alert(resp[keys[i]]['name'])
|
//alert(resp[keys[i]]['name'])
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
setActiveTab('inbox')
|
Loading…
Reference in New Issue
Block a user