Merge pull request #59 from navjotcis/newwork

worked on trash message permanent delete functionlity
This commit is contained in:
navjotcis 2019-11-26 20:50:06 +05:30 committed by GitHub
commit b8d1d809be
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 116 additions and 59 deletions

View File

@ -74,6 +74,7 @@
text: "Starred" text: "Starred"
icon:'star' icon:'star'
on_release: app.root.ids.scr_mngr.current = 'starred' on_release: app.root.ids.scr_mngr.current = 'starred'
badge_text: "0"
NavigationDrawerIconButton: NavigationDrawerIconButton:
icon: 'archive' icon: 'archive'
text: "Archieve" text: "Archieve"
@ -231,6 +232,7 @@ NavigationLayout:
do_scroll_x: False do_scroll_x: False
MDList: MDList:
id: ml id: ml
Loader:
ComposerButton: ComposerButton:
<Draft>: <Draft>:
@ -984,6 +986,7 @@ NavigationLayout:
orientation: 'vertical' orientation: 'vertical'
size_hint_y: None size_hint_y: None
height: dp(100) + self.minimum_height height: dp(100) + self.minimum_height
Loader:
<CopyTextBtn@Button>: <CopyTextBtn@Button>:
id: cpyButton id: cpyButton

View File

@ -106,6 +106,7 @@ class Inbox(Screen):
"""Load Inbox list for Inbox messages.""" """Load Inbox list for Inbox messages."""
# pylint: disable=too-many-locals # pylint: disable=too-many-locals
if state.searcing_text: if state.searcing_text:
self.children[2].children[0].children[0].scroll_y = 1.0
where = ['subject', 'message'] where = ['subject', 'message']
what = state.searcing_text what = state.searcing_text
xAddress = 'toaddress' xAddress = 'toaddress'
@ -295,6 +296,7 @@ class MyAddress(Screen):
# pylint: disable=unnecessary-lambda, deprecated-lambda # pylint: disable=unnecessary-lambda, deprecated-lambda
self.addresses_list = state.kivyapp.variable_1 self.addresses_list = state.kivyapp.variable_1
if state.searcing_text: if state.searcing_text:
self.ids.refresh_layout.scroll_y = 1.0
filtered_list = filter( filtered_list = filter(
lambda addr: self.filter_address( lambda addr: self.filter_address(
addr), BMConfigParser().addresses()) addr), BMConfigParser().addresses())
@ -413,6 +415,7 @@ class AddressBook(Screen):
def loadAddresslist(self, account, where="", what=""): def loadAddresslist(self, account, where="", what=""):
"""Clock Schdule for method AddressBook.""" """Clock Schdule for method AddressBook."""
if state.searcing_text: if state.searcing_text:
self.ids.scroll_y.scroll_y = 1.0
where = ['label', 'address'] where = ['label', 'address']
what = state.searcing_text what = state.searcing_text
xAddress = '' xAddress = ''
@ -477,7 +480,7 @@ class AddressBook(Screen):
def update_addressBook_on_scroll(self, exist_addresses): def update_addressBook_on_scroll(self, exist_addresses):
"""This method is used to load more data on scroll down""" """This method is used to load more data on scroll down"""
self.set_mdList(exist_addresses, exist_addresses + 20) self.set_mdList(exist_addresses,exist_addresses + 5)
@staticmethod @staticmethod
def refreshs(*args): def refreshs(*args):
@ -622,8 +625,6 @@ class DropDownWidget(BoxLayout):
BMConfigParser().getint( BMConfigParser().getint(
'bitmessagesettings', 'ttl')) 'bitmessagesettings', 'ttl'))
state.check_sent_acc = fromAddress state.check_sent_acc = fromAddress
# state.msg_counter_objs = self.parent.parent.parent.parent\
# .parent.parent.children[0].children[2].children[0].ids
state.msg_counter_objs = self.parent.parent.parent.parent\ state.msg_counter_objs = self.parent.parent.parent.parent\
.parent.parent.children[2].children[0].ids .parent.parent.children[2].children[0].ids
# self.parent.parent.screens[0].ids.ml.clear_widgets() # self.parent.parent.screens[0].ids.ml.clear_widgets()
@ -631,9 +632,7 @@ class DropDownWidget(BoxLayout):
self.parent.parent.screens[3].update_sent_messagelist() self.parent.parent.screens[3].update_sent_messagelist()
self.parent.parent.screens[16].clear_widgets() self.parent.parent.screens[16].clear_widgets()
self.parent.parent.screens[16].add_widget(Allmails()) self.parent.parent.screens[16].add_widget(Allmails())
# toast('sending...')
Clock.schedule_once(self.callback_for_msgsend, 3) Clock.schedule_once(self.callback_for_msgsend, 3)
# toLabel = ''
queues.workerQueue.put(('sendmessage', toAddress)) queues.workerQueue.put(('sendmessage', toAddress))
print "sqlExecute successfully #######################" print "sqlExecute successfully #######################"
state.in_composer = True state.in_composer = True
@ -869,6 +868,7 @@ class Sent(Screen):
def loadSent(self, account, where="", what=""): def loadSent(self, account, where="", what=""):
"""Load Sent list for Sent messages.""" """Load Sent list for Sent messages."""
if state.searcing_text: if state.searcing_text:
self.ids.scroll_y.scroll_y = 1.0
where = ['subject', 'message'] where = ['subject', 'message']
what = state.searcing_text what = state.searcing_text
xAddress = 'fromaddress' xAddress = 'fromaddress'
@ -1057,6 +1057,8 @@ class Trash(Screen):
"""Trash Screen uses screen to show widgets of screens.""" """Trash Screen uses screen to show widgets of screens."""
trash_messages = ListProperty() trash_messages = ListProperty()
has_refreshed = True has_refreshed = True
delete_index = StringProperty()
table_name = StringProperty()
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
"""Trash method, delete sent message and add in Trash.""" """Trash method, delete sent message and add in Trash."""
@ -1069,11 +1071,10 @@ class Trash(Screen):
if BMConfigParser().addresses(): if BMConfigParser().addresses():
state.association = BMConfigParser().addresses()[0] state.association = BMConfigParser().addresses()[0]
self.trash_messages = sqlQuery( self.trash_messages = sqlQuery(
"SELECT toaddress, fromaddress, subject, message, folder, ackdata" "SELECT toaddress, fromaddress, subject, message, folder ||',' || 'sent' as folder, ackdata As id, DATE(lastactiontime)"
" As id, DATE(lastactiontime) As actionTime FROM sent WHERE" " As actionTime FROM sent WHERE folder = 'trash' and fromaddress = '{0}' UNION"
" folder = 'trash' UNION SELECT toaddress, fromaddress, subject," " SELECT toaddress, fromaddress, subject, message, folder ||',' || 'inbox' as folder, msgid As id, DATE(received) As"
" message, folder, msgid As id, DATE(received) As actionTime FROM" " actionTime FROM inbox WHERE folder = 'trash' and toaddress = '{0}' ORDER BY actionTime DESC".format(state.association))
" inbox WHERE folder = 'trash' ORDER BY actionTime DESC")
if self.trash_messages: if self.trash_messages:
src_mng_obj = state.kivyapp.root.children[2].children[0].ids src_mng_obj = state.kivyapp.root.children[2].children[0].ids
src_mng_obj.trash_cnt.badge_text = str(len(self.trash_messages)) src_mng_obj.trash_cnt.badge_text = str(len(self.trash_messages))
@ -1115,7 +1116,7 @@ class Trash(Screen):
del_btn.background_normal = '' del_btn.background_normal = ''
del_btn.background_color = (1, 0, 0, 1) del_btn.background_color = (1, 0, 0, 1)
del_btn.bind(on_press=partial( del_btn.bind(on_press=partial(
self.delete_permanently, item[5])) self.delete_permanently, item[5], item[4]))
carousel.add_widget(del_btn) carousel.add_widget(del_btn)
carousel.add_widget(meny) carousel.add_widget(meny)
carousel.index = 1 carousel.index = 1
@ -1137,9 +1138,49 @@ class Trash(Screen):
"""This method is used to load more data on scroll down""" """This method is used to load more data on scroll down"""
self.set_mdList(total_trash_msg, total_trash_msg + 5) self.set_mdList(total_trash_msg, total_trash_msg + 5)
def delete_permanently(self, data_index, instance, *args): def delete_permanently(self, data_index, folder, instance, *args):
"""Deleting trash mail permanently.""" """Deleting trash mail permanently."""
pass self.table_name = folder.split(',')[1]
self.delete_index = data_index
self.delete_confirmation()
def callback_for_screen_load(self, dt=0):
"""This methos is for loading screen"""
self.ids.ml.clear_widgets()
self.init_ui(0)
self.children[1].active = False
toast('Message is permanently deleted')
def delete_confirmation(self):
"""This method is used to show delete confirmation popup"""
delete_msg_dialog = MDDialog(
text='Are you sure you want to delete this message permanently from trash?',
title='', size_hint=(.8, .25), text_button_ok='Yes',
text_button_cancel='No', events_callback=self.callback_for_delete_msg)
delete_msg_dialog.open()
def callback_for_delete_msg(self, text_item):
"""Method is used for getting the callback of alert box"""
if text_item == 'Yes':
self.delete_message_from_trash()
else:
toast(text_item)
def delete_message_from_trash(self):
"""This method is used to delete """
self.children[1].active = True
if self.table_name == 'inbox':
sqlExecute("DELETE FROM inbox WHERE msgid = ?;", str(
self.delete_index))
elif self.table_name == 'sent':
sqlExecute("DELETE FROM sent WHERE ackdata = ?;", str(
self.delete_index))
msg_count_objs = state.kivyapp.root.children[2].children[0].ids
if int(state.trash_count) > 0:
msg_count_objs.trash_cnt.badge_text = str(
int(state.trash_count) - 1)
state.trash_count = str(int(state.trash_count) - 1)
Clock.schedule_once(self.callback_for_screen_load, 1)
class Page(Screen): class Page(Screen):
@ -1520,39 +1561,39 @@ class NavigateApp(App):
self.refreshScreen() self.refreshScreen()
state.in_search_mode = False state.in_search_mode = False
def refreshScreen(self): # pylint: disable=unused-variable def refreshScreen(self): # pylint: disable=unused-variable
"""Method show search button only on inbox or sent screen.""" """Method show search button only on inbox or sent screen."""
state.searcing_text = '' state.searcing_text = ''
if state.search_screen == 'inbox': if state.search_screen == 'inbox':
try: try:
self.root.ids.sc1.children[ self.root.ids.sc1.children[
3].children[1].ids.search_field.text = '' 3].children[1].ids.search_field.text = ''
except Exception: except Exception:
self.root.ids.sc1.children[ self.root.ids.sc1.children[
2].children[1].ids.search_field.text = ''
self.root.ids.sc1.children[1].active = True
Clock.schedule_once(self.search_callback, 0.5)
elif state.search_screen == 'addressbook':
self.root.ids.sc11.children[
2].children[1].ids.search_field.text = '' 2].children[1].ids.search_field.text = ''
self.root.ids.sc11.children[ self.root.ids.sc1.children[1].active = True
1].active = True Clock.schedule_once(self.search_callback, 0.5)
Clock.schedule_once(self.search_callback, 0.5) elif state.search_screen == 'addressbook':
elif state.search_screen == 'myaddress': self.root.ids.sc11.children[
try: 2].children[1].ids.search_field.text = ''
self.root.ids.sc10.children[ self.root.ids.sc11.children[
3].children[1].ids.search_field.text = '' 1].active = True
except Exception: Clock.schedule_once(self.search_callback, 0.5)
self.root.ids.sc10.children[ elif state.search_screen == 'myaddress':
2].children[1].ids.search_field.text = '' try:
self.root.ids.sc10.children[1].active = True self.root.ids.sc10.children[
Clock.schedule_once(self.search_callback, 0.5) 3].children[1].ids.search_field.text = ''
else: except Exception:
self.root.ids.sc4.children[ self.root.ids.sc10.children[
2].children[1].ids.search_field.text = '' 2].children[1].ids.search_field.text = ''
self.root.ids.sc4.children[1].active = True self.root.ids.sc10.children[1].active = True
Clock.schedule_once(self.search_callback, 0.5) Clock.schedule_once(self.search_callback, 0.5)
return else:
self.root.ids.sc4.children[
2].children[1].ids.search_field.text = ''
self.root.ids.sc4.children[1].active = True
Clock.schedule_once(self.search_callback, 0.5)
return
def set_identicon(self, text): def set_identicon(self, text):
"""This method is use for showing identicon in address spinner""" """This method is use for showing identicon in address spinner"""
@ -1768,6 +1809,7 @@ class MailDetail(Screen):
msg_count_objs = state.kivyapp.root.children[2].children[0].ids msg_count_objs = state.kivyapp.root.children[2].children[0].ids
state.searcing_text = '' state.searcing_text = ''
if state.detailPageType == 'sent': if state.detailPageType == 'sent':
state.kivyapp.root.ids.sc4.children[2].children[1].ids.search_field.text = ''
sqlExecute( sqlExecute(
"UPDATE sent SET folder = 'trash' WHERE" "UPDATE sent SET folder = 'trash' WHERE"
" ackdata = ?;", str(state.mail_id)) " ackdata = ?;", str(state.mail_id))
@ -1776,6 +1818,8 @@ class MailDetail(Screen):
self.parent.screens[3].ids.ml.clear_widgets() self.parent.screens[3].ids.ml.clear_widgets()
self.parent.screens[3].loadSent(state.association) self.parent.screens[3].loadSent(state.association)
elif state.detailPageType == 'inbox': elif state.detailPageType == 'inbox':
state.kivyapp.root.ids.sc1.children[2].children[1].ids.search_field.text = ''
self.parent.screens[0].children[2].children[1].ids.search_field.text = ''
sqlExecute( sqlExecute(
"UPDATE inbox SET folder = 'trash' WHERE" "UPDATE inbox SET folder = 'trash' WHERE"
" msgid = ?;", str(state.mail_id)) " msgid = ?;", str(state.mail_id))
@ -1784,6 +1828,7 @@ class MailDetail(Screen):
state.inbox_count = str(int(state.inbox_count) - 1) state.inbox_count = str(int(state.inbox_count) - 1)
self.parent.screens[0].ids.ml.clear_widgets() self.parent.screens[0].ids.ml.clear_widgets()
self.parent.screens[0].loadMessagelist(state.association) self.parent.screens[0].loadMessagelist(state.association)
elif state.detailPageType == 'draft': elif state.detailPageType == 'draft':
sqlExecute("DELETE FROM sent WHERE ackdata = ?;", str( sqlExecute("DELETE FROM sent WHERE ackdata = ?;", str(
state.mail_id)) state.mail_id))
@ -1793,8 +1838,8 @@ class MailDetail(Screen):
self.parent.screens[15].clear_widgets() self.parent.screens[15].clear_widgets()
self.parent.screens[15].add_widget(Draft()) self.parent.screens[15].add_widget(Draft())
self.parent.current = 'allmails' \ # self.parent.current = 'allmails' \
if state.is_allmail else state.detailPageType # if state.is_allmail else state.detailPageType
if state.detailPageType != 'draft': if state.detailPageType != 'draft':
msg_count_objs.trash_cnt.badge_text = str( msg_count_objs.trash_cnt.badge_text = str(
int(state.trash_count) + 1) int(state.trash_count) + 1)
@ -1806,7 +1851,15 @@ class MailDetail(Screen):
self.parent.screens[4].add_widget(Trash()) self.parent.screens[4].add_widget(Trash())
self.parent.screens[16].clear_widgets() self.parent.screens[16].clear_widgets()
self.parent.screens[16].add_widget(Allmails()) self.parent.screens[16].add_widget(Allmails())
state.kivyapp.back_press() self.children[0].children[0].active = True
Clock.schedule_once(self.callback_for_delete, 3)
def callback_for_delete(self, dt=0):
self.children[0].children[0].active = False
state.kivyapp.set_common_header()
self.parent.current = 'allmails' \
if state.is_allmail else state.detailPageType
state.detailPageType = ''
toast('Deleted') toast('Deleted')
def inbox_reply(self): def inbox_reply(self):
@ -1824,10 +1877,6 @@ class MailDetail(Screen):
self.parent.current = 'create' self.parent.current = 'create'
state.kivyapp.set_navbar_for_composer() state.kivyapp.set_navbar_for_composer()
def copy_sent_mail(self):
"""Method used for copying sent mail to the composer."""
pass
def write_msg(self, navApp): def write_msg(self, navApp):
"""Method used to write on draft mail.""" """Method used to write on draft mail."""
state.send_draft_mail = state.mail_id state.send_draft_mail = state.mail_id
@ -2111,17 +2160,13 @@ class Draft(Screen):
sendMessageToPeople = True sendMessageToPeople = True
if sendMessageToPeople: if sendMessageToPeople:
from addresses import decodeAddress from addresses import decodeAddress
# status, addressVersionNumber, streamNumber, ripe = decodeAddress(
# toAddress)
streamNumber, ripe = decodeAddress(toAddress)[2:] streamNumber, ripe = decodeAddress(toAddress)[2:]
from addresses import addBMIfNotPresent from addresses import addBMIfNotPresent
toAddress = addBMIfNotPresent(toAddress) toAddress = addBMIfNotPresent(toAddress)
# statusIconColor = 'red'
stealthLevel = BMConfigParser().safeGetInt( stealthLevel = BMConfigParser().safeGetInt(
'bitmessagesettings', 'ackstealthlevel') 'bitmessagesettings', 'ackstealthlevel')
from helper_ackPayload import genAckPayload from helper_ackPayload import genAckPayload
ackdata = genAckPayload(streamNumber, stealthLevel) ackdata = genAckPayload(streamNumber, stealthLevel)
# t = ()
sqlExecute( sqlExecute(
'''INSERT INTO sent VALUES '''INSERT INTO sent VALUES
(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)''', (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)''',
@ -2187,9 +2232,9 @@ class Allmails(Screen):
self.all_mails = sqlQuery( self.all_mails = sqlQuery(
"SELECT toaddress, fromaddress, subject, message, folder, ackdata" "SELECT toaddress, fromaddress, subject, message, folder, ackdata"
" As id, DATE(lastactiontime) As actionTime FROM sent WHERE" " As id, DATE(lastactiontime) As actionTime FROM sent WHERE"
" folder = 'sent' UNION SELECT toaddress, fromaddress, subject," " folder = 'sent' and fromaddress = '{0}' UNION SELECT toaddress, fromaddress, subject,"
" message, folder, msgid As id, DATE(received) As actionTime" " message, folder, msgid As id, DATE(received) As actionTime"
" FROM inbox WHERE folder = 'inbox' ORDER BY actionTime DESC") " FROM inbox WHERE folder = 'inbox' and toaddress = '{0}' ORDER BY actionTime DESC".format(account))
if self.all_mails: if self.all_mails:
state.kivyapp.root.children[2].children[ state.kivyapp.root.children[2].children[
0].ids.allmail_cnt.badge_text = str( 0].ids.allmail_cnt.badge_text = str(

View File

@ -30,11 +30,11 @@ from helper_threading import StoppableThread
from inventory import Inventory from inventory import Inventory
from network.connectionpool import BMConnectionPool from network.connectionpool import BMConnectionPool
from debug import logger from debug import logger
from datetime import datetime, timedelta
import knownnodes import knownnodes
import queues import queues
import state import state
class singleCleaner(StoppableThread): class singleCleaner(StoppableThread):
"""Base method that Cleanup knownnodes and handle possible severe exception""" """Base method that Cleanup knownnodes and handle possible severe exception"""
name = "singleCleaner" name = "singleCleaner"
@ -111,7 +111,7 @@ class singleCleaner(StoppableThread):
resendPubkeyRequest(toAddress) resendPubkeyRequest(toAddress)
elif status == 'msgsent': elif status == 'msgsent':
resendMsg(ackData) resendMsg(ackData)
deleteTrashMsgPermonantly()
try: try:
# Cleanup knownnodes and handle possible severe exception # Cleanup knownnodes and handle possible severe exception
# while writing it to disk # while writing it to disk
@ -202,3 +202,12 @@ def resendMsg(ackdata):
'updateStatusBar', 'updateStatusBar',
'Doing work necessary to again attempt to deliver a message...' 'Doing work necessary to again attempt to deliver a message...'
)) ))
def deleteTrashMsgPermonantly():
"""This method is used to delete old messages"""
ndays_before_time = datetime.now() - timedelta(days=30)
old_messages = time.mktime(ndays_before_time.timetuple())
sqlExecute("delete from sent where folder = 'trash' and lastactiontime <= ?;", int(old_messages))
sqlExecute("delete from inbox where folder = 'trash' and received <= ?;", int(old_messages))
return