Notification logic

This commit is contained in:
Mark Qvist 2022-10-02 12:15:37 +02:00
parent 93d214ead6
commit a74e0f9cf7
3 changed files with 13 additions and 3 deletions

View File

@ -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)

View File

@ -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()

View File

@ -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