From a74e0f9cf7e634fc30cada690c6b79d8bb5d6c93 Mon Sep 17 00:00:00 2001 From: Mark Qvist Date: Sun, 2 Oct 2022 12:15:37 +0200 Subject: [PATCH] Notification logic --- sbapp/main.py | 2 ++ sbapp/services/sidebandservice.py | 5 +++++ sbapp/sideband/core.py | 9 ++++++--- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/sbapp/main.py b/sbapp/main.py index 7581890..9e2c9f5 100644 --- a/sbapp/main.py +++ b/sbapp/main.py @@ -160,6 +160,7 @@ class SidebandApp(MDApp): def on_resume(self): self.sideband.setstate("app.running", True) self.sideband.setstate("app.foreground", True) + self.sideband.setstate("wants.clear_notifications", True) self.app_state = SidebandApp.ACTIVE def on_stop(self): @@ -494,6 +495,7 @@ class SidebandApp(MDApp): self.root.ids.screen_manager.current = "conversations_screen" self.root.ids.messages_scrollview.active_conversation = None self.sideband.setstate("app.displaying", self.root.ids.screen_manager.current) + self.sideband.setstate("wants.clear_notifications", True) def connectivity_status(self, sender): hs = dp(22) diff --git a/sbapp/services/sidebandservice.py b/sbapp/services/sidebandservice.py index 030b5da..6638365 100644 --- a/sbapp/services/sidebandservice.py +++ b/sbapp/services/sidebandservice.py @@ -157,6 +157,11 @@ class SidebandService(): self.should_run = False sleep_time = 0 + if self.sideband.getstate("wants.clear_notifications"): + self.sideband.setstate("wants.clear_notifications", False) + if self.notification_service != None: + self.notification_service.cancelAll() + time.sleep(sleep_time) self.release_locks() diff --git a/sbapp/sideband/core.py b/sbapp/sideband/core.py index a2c68b8..16338ba 100644 --- a/sbapp/sideband/core.py +++ b/sbapp/sideband/core.py @@ -1096,9 +1096,6 @@ class SidebandCore(): context_dest = message.source_hash is_trusted = self.is_trusted(context_dest) - if is_trusted: - should_notify = True - if self._db_message(message.hash): RNS.log("Message exists, setting state to: "+str(message.state), RNS.LOG_DEBUG) self._db_message_set_state(message.hash, message.state) @@ -1106,6 +1103,9 @@ class SidebandCore(): RNS.log("Message does not exist, saving", RNS.LOG_DEBUG) self._db_save_lxm(message, context_dest) + if is_trusted: + should_notify = True + if self._db_conversation(context_dest) == None: self._db_create_conversation(context_dest) self.setstate("app.flags.new_conversations", True) @@ -1121,6 +1121,9 @@ class SidebandCore(): self.unread_conversation(context_dest) self.setstate("app.flags.unread_conversations", True) + if self.gui_display() == "conversations_screen" and self.gui_foreground(): + should_notify = False + if self.is_client: should_notify = False