From c5ad94b2d344f3d847d87762bdf1d2a0dcd011ab Mon Sep 17 00:00:00 2001 From: Mark Qvist Date: Sat, 8 Oct 2022 19:55:46 +0200 Subject: [PATCH] Improved announce stream --- sbapp/sideband/core.py | 20 +++++++++++++++++--- sbapp/ui/announces.py | 30 +++++++++++++++++++----------- 2 files changed, 36 insertions(+), 14 deletions(-) diff --git a/sbapp/sideband/core.py b/sbapp/sideband/core.py index e56a271..e978fec 100644 --- a/sbapp/sideband/core.py +++ b/sbapp/sideband/core.py @@ -373,6 +373,9 @@ class SidebandCore(): def clear_conversation(self, context_dest): self._db_clear_conversation(context_dest) + def delete_announce(self, context_dest): + self._db_delete_announce(context_dest) + def delete_conversation(self, context_dest): self._db_clear_conversation(context_dest) self._db_delete_conversation(context_dest) @@ -666,7 +669,7 @@ class SidebandCore(): return conv def _db_clear_conversation(self, context_dest): - RNS.log("Clearing conversation with "+RNS.prettyhexrep(context_dest)) + RNS.log("Clearing conversation with "+RNS.prettyhexrep(context_dest), RNS.LOG_DEBUG) db = sqlite3.connect(self.db_path) dbc = db.cursor() @@ -677,7 +680,7 @@ class SidebandCore(): db.close() def _db_delete_conversation(self, context_dest): - RNS.log("Deleting conversation with "+RNS.prettyhexrep(context_dest)) + RNS.log("Deleting conversation with "+RNS.prettyhexrep(context_dest), RNS.LOG_DEBUG) db = sqlite3.connect(self.db_path) dbc = db.cursor() @@ -687,8 +690,19 @@ class SidebandCore(): db.close() + def _db_delete_announce(self, context_dest): + RNS.log("Deleting announce with "+RNS.prettyhexrep(context_dest), RNS.LOG_DEBUG) + db = sqlite3.connect(self.db_path) + dbc = db.cursor() + + query = "delete from announce where (source=:ctx_dst);" + dbc.execute(query, {"ctx_dst": context_dest}) + db.commit() + + db.close() + def _db_create_conversation(self, context_dest, name = None, trust = False): - RNS.log("Creating conversation for "+RNS.prettyhexrep(context_dest)) + RNS.log("Creating conversation for "+RNS.prettyhexrep(context_dest), RNS.LOG_DEBUG) db = sqlite3.connect(self.db_path) dbc = db.cursor() diff --git a/sbapp/ui/announces.py b/sbapp/ui/announces.py index 99709af..6efce45 100644 --- a/sbapp/ui/announces.py +++ b/sbapp/ui/announces.py @@ -8,6 +8,7 @@ from kivymd.uix.list import MDList, IconLeftWidget, IconRightWidget, OneLineAvat from kivymd.uix.menu import MDDropdownMenu from kivy.uix.gridlayout import GridLayout from kivy.uix.boxlayout import BoxLayout +from kivy.clock import Clock from kivymd.uix.button import MDFlatButton from kivymd.uix.dialog import MDDialog @@ -42,9 +43,11 @@ class Announces(): self.added_item_dests = [] def update(self): + us = time.time() self.fetch_announces() self.update_widget() self.app.sideband.setstate("app.flags.new_announces", False) + RNS.log("Updated announce stream widgets in "+RNS.prettytime(time.time()-us), RNS.LOG_DEBUG) def update_widget(self): if self.list == None: @@ -138,8 +141,10 @@ class Announces(): ) def dl_yes(s): dialog.dismiss() - self.app.sideband.delete_announce(dest) - self.reload() + def cb(dt): + self.app.sideband.delete_announce(dest) + self.update() + Clock.schedule_once(cb, 0.2) def dl_no(s): dialog.dismiss() @@ -171,12 +176,12 @@ class Announces(): "height": dp(40), "on_release": gen_conv(context_dest, item) }, - # { - # "text": "Delete Announce", - # "viewclass": "OneLineListItem", - # "height": dp(40), - # "on_release": gen_del(context_dest, item) - # } + { + "text": "Delete Announce", + "viewclass": "OneLineListItem", + "height": dp(40), + "on_release": gen_del(context_dest, item) + } ] elif dest_type == "lxmf.propagation": @@ -187,6 +192,12 @@ class Announces(): "height": dp(40), "on_release": gen_set_node(context_dest, item) }, + { + "text": "Delete Announce", + "viewclass": "OneLineListItem", + "height": dp(40), + "on_release": gen_del(context_dest, item) + } ] else: @@ -201,8 +212,6 @@ class Announces(): width_mult=4, elevation=1, radius=dp(3), - opening_transition="linear", - opening_time=0.0, ) def callback_factory(ref): @@ -211,7 +220,6 @@ class Announces(): return x item.iconr.bind(on_release=callback_factory(item)) - item.add_widget(item.iconr) self.added_item_dests.append(context_dest)