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
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
'''
|
||||
import sys, os
|
||||
from flask import Response, request, redirect, Blueprint
|
||||
import sys, os, json
|
||||
from flask import Response, request, redirect, Blueprint, abort
|
||||
import core
|
||||
sys.path.insert(0, os.path.dirname(os.path.realpath(__file__)))
|
||||
import loadinbox
|
||||
import loadinbox, sentboxdb
|
||||
|
||||
flask_blueprint = Blueprint('mail', __name__)
|
||||
c = core.Core()
|
||||
@ -29,7 +29,8 @@ kv = c.keyStore
|
||||
|
||||
@flask_blueprint.route('/mail/deletemsg/<block>', methods=['POST'])
|
||||
def mail_delete(block):
|
||||
assert c._utils.validateHash(block)
|
||||
if not c._utils.validateHash(block):
|
||||
abort(504)
|
||||
existing = kv.get('deleted_mail')
|
||||
if existing is None:
|
||||
existing = []
|
||||
@ -40,4 +41,23 @@ def mail_delete(block):
|
||||
|
||||
@flask_blueprint.route('/mail/getinbox')
|
||||
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'])
|
||||
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):
|
||||
'''
|
||||
|
@ -25,10 +25,15 @@ class SentBox:
|
||||
self.dbLocation = mycore.dataDir + 'sentbox.db'
|
||||
if not os.path.exists(self.dbLocation):
|
||||
self.createDB()
|
||||
self.conn = sqlite3.connect(self.dbLocation)
|
||||
self.cursor = self.conn.cursor()
|
||||
self.core = mycore
|
||||
return
|
||||
|
||||
def connect(self):
|
||||
self.conn = sqlite3.connect(self.dbLocation)
|
||||
self.cursor = self.conn.cursor()
|
||||
|
||||
def close(self):
|
||||
self.conn.close()
|
||||
|
||||
def createDB(self):
|
||||
conn = sqlite3.connect(self.dbLocation)
|
||||
@ -42,22 +47,29 @@ class SentBox:
|
||||
);
|
||||
''')
|
||||
conn.commit()
|
||||
conn.close()
|
||||
return
|
||||
|
||||
def listSent(self):
|
||||
self.connect()
|
||||
retData = []
|
||||
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]})
|
||||
self.close()
|
||||
return retData
|
||||
|
||||
def addToSent(self, blockID, peer, message, subject=''):
|
||||
self.connect()
|
||||
args = (blockID, peer, message, subject, self.core._utils.getEpoch())
|
||||
self.cursor.execute('INSERT INTO sent VALUES(?, ?, ?, ?, ?)', args)
|
||||
self.conn.commit()
|
||||
self.close()
|
||||
return
|
||||
|
||||
def removeSent(self, blockID):
|
||||
self.connect()
|
||||
args = (blockID,)
|
||||
self.cursor.execute('DELETE FROM sent where hash=?', args)
|
||||
self.conn.commit()
|
||||
self.close()
|
||||
return
|
||||
|
@ -71,6 +71,7 @@ function setActiveTab(tabName){
|
||||
threadPart.innerHTML = ""
|
||||
switch(tabName){
|
||||
case 'inbox':
|
||||
refreshPms()
|
||||
getInbox()
|
||||
break
|
||||
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){
|
||||
fetch('/getblockheader/' + bHash, {
|
||||
headers: {
|
||||
@ -96,6 +108,7 @@ function loadInboxEntries(bHash){
|
||||
var subjectLine = document.createElement('span')
|
||||
var dateStr = document.createElement('span')
|
||||
var validSig = document.createElement('span')
|
||||
var deleteBtn = document.createElement('button')
|
||||
var humanDate = new Date(0)
|
||||
var metadata = resp['metadata']
|
||||
humanDate.setUTCSeconds(resp['meta']['time'])
|
||||
@ -119,6 +132,8 @@ function loadInboxEntries(bHash){
|
||||
entry.setAttribute('data-pubkey', resp['meta']['signer'])
|
||||
senderInput.readOnly = true
|
||||
dateStr.innerText = humanDate.toString()
|
||||
deleteBtn.innerText = 'X'
|
||||
deleteBtn.classList.add('dangerBtn', 'deleteBtn')
|
||||
if (metadata['subject'] === undefined || metadata['subject'] === null) {
|
||||
subjectLine.innerText = '()'
|
||||
}
|
||||
@ -127,6 +142,7 @@ function loadInboxEntries(bHash){
|
||||
}
|
||||
//entry.innerHTML = 'sender ' + resp['meta']['signer'] + ' - ' + resp['meta']['time']
|
||||
threadPart.appendChild(entry)
|
||||
entry.appendChild(deleteBtn)
|
||||
entry.appendChild(bHashDisplay)
|
||||
entry.appendChild(senderInput)
|
||||
entry.appendChild(validSig)
|
||||
@ -134,9 +150,17 @@ function loadInboxEntries(bHash){
|
||||
entry.appendChild(dateStr)
|
||||
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'))
|
||||
}
|
||||
|
||||
deleteBtn.onclick = function(){
|
||||
entry.parentNode.removeChild(entry);
|
||||
deleteMessage(entry.getAttribute('data-hash'))
|
||||
}
|
||||
|
||||
}.bind(bHash))
|
||||
}
|
||||
@ -160,7 +184,7 @@ function getInbox(){
|
||||
}
|
||||
|
||||
function getSentbox(){
|
||||
fetch('/apipoints/mail/sentbox', {
|
||||
fetch('/mail/getsentbox', {
|
||||
headers: {
|
||||
"token": webpass
|
||||
}})
|
||||
@ -180,16 +204,27 @@ function getSentbox(){
|
||||
toLabel.innerText = 'To: '
|
||||
var toEl = document.createElement('input')
|
||||
var preview = document.createElement('span')
|
||||
var deleteBtn = document.createElement('button')
|
||||
deleteBtn.classList.add('deleteBtn', 'dangerBtn')
|
||||
deleteBtn.innerText = 'X'
|
||||
toEl.readOnly = true
|
||||
toEl.value = resp[keys[i]][1]
|
||||
preview.innerText = '(' + resp[keys[i]][2] + ')'
|
||||
toEl.value = resp[i]['peer']
|
||||
preview.innerText = '(' + resp[i]['subject'] + ')'
|
||||
entry.setAttribute('data-hash', resp[i]['hash'])
|
||||
entry.appendChild(deleteBtn)
|
||||
entry.appendChild(toLabel)
|
||||
entry.appendChild(toEl)
|
||||
entry.appendChild(preview)
|
||||
entryUsed = resp[keys[i]]
|
||||
entryUsed = resp[i]['message']
|
||||
entry.onclick = function(){
|
||||
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)
|
||||
}
|
||||
@ -203,6 +238,7 @@ function showSentboxWindow(to, content){
|
||||
overlay('sentboxDisplay')
|
||||
}
|
||||
|
||||
function refreshPms(){
|
||||
fetch('/mail/getinbox', {
|
||||
headers: {
|
||||
"token": webpass
|
||||
@ -210,8 +246,8 @@ fetch('/mail/getinbox', {
|
||||
.then((resp) => resp.text()) // Transform the data into json
|
||||
.then(function(data) {
|
||||
pms = data.split(',')
|
||||
setActiveTab('inbox')
|
||||
})
|
||||
}
|
||||
|
||||
tabBtns.onclick = function(event){
|
||||
var children = tabBtns.children
|
||||
@ -273,4 +309,6 @@ fetch('/friends/list', {
|
||||
//friendSelectParent
|
||||
//alert(resp[keys[i]]['name'])
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
setActiveTab('inbox')
|
Loading…
Reference in New Issue
Block a user