Added message notifications

This commit is contained in:
Mark Qvist 2022-09-17 17:12:25 +02:00
parent 0d9abec269
commit 1b8bb58683
3 changed files with 51 additions and 2 deletions

View File

@ -52,9 +52,15 @@ if RNS.vendor.platformutils.get_platform() == "android":
from android.runnable import run_on_ui_thread from android.runnable import run_on_ui_thread
class SidebandApp(MDApp): class SidebandApp(MDApp):
STARTING = 0x00
ACTIVE = 0x01
PAUSED = 0x02
STOPPING = 0x03
def __init__(self, **kwargs): def __init__(self, **kwargs):
super().__init__(**kwargs) super().__init__(**kwargs)
self.title = "Sideband" self.title = "Sideband"
self.app_state = SidebandApp.STARTING
self.sideband = SidebandCore(self) self.sideband = SidebandCore(self)
@ -82,6 +88,7 @@ class SidebandApp(MDApp):
if RNS.vendor.platformutils.get_platform() == "android": if RNS.vendor.platformutils.get_platform() == "android":
Clock.schedule_once(dismiss_splash, 0) Clock.schedule_once(dismiss_splash, 0)
self.app_state = SidebandApp.ACTIVE
def start_android_service(self): def start_android_service(self):
service = autoclass('io.unsigned.sideband.ServiceSidebandservice') service = autoclass('io.unsigned.sideband.ServiceSidebandservice')
@ -94,6 +101,23 @@ class SidebandApp(MDApp):
# General helpers # # General helpers #
################################################# #################################################
def on_pause(self):
self.app_state = SidebandApp.PAUSED
self.sideband.should_persist_data()
return True
def on_resume(self):
self.app_state = SidebandApp.ACTIVE
def on_stop(self):
self.app_state = SidebandApp.STOPPING
def is_in_foreground(self):
if self.app_state == SidebandApp.ACTIVE:
return True
else:
return False
def notify(self, title, content): def notify(self, title, content):
notifications_enabled = True notifications_enabled = True

View File

@ -161,6 +161,11 @@ class SidebandCore():
if not os.path.isfile(self.db_path): if not os.path.isfile(self.db_path):
self.__db_init() self.__db_init()
def should_persist_data(self):
if self.reticulum != None:
self.reticulum._should_persist_data()
self.save_configuration()
def __load_config(self): def __load_config(self):
RNS.log("Loading Sideband identity...") RNS.log("Loading Sideband identity...")
@ -896,10 +901,17 @@ class SidebandCore():
return True return True
def lxm_ingest(self, message, originator = False): def lxm_ingest(self, message, originator = False):
should_notify = False
is_trusted = False
if originator: if originator:
context_dest = message.destination_hash context_dest = message.destination_hash
else: else:
context_dest = message.source_hash context_dest = message.source_hash
is_trusted = self.is_trusted(context_dest)
if is_trusted:
should_notify = True
if self._db_message(message.hash): if self._db_message(message.hash):
RNS.log("Message exists, setting state to: "+str(message.state), RNS.LOG_DEBUG) RNS.log("Message exists, setting state to: "+str(message.state), RNS.LOG_DEBUG)
@ -916,6 +928,10 @@ class SidebandCore():
if self.owner_app.root.ids.messages_scrollview.active_conversation != context_dest: if self.owner_app.root.ids.messages_scrollview.active_conversation != context_dest:
self.unread_conversation(context_dest) self.unread_conversation(context_dest)
self.owner_app.flag_unread_conversations = True self.owner_app.flag_unread_conversations = True
else:
RNS.log("CHECKING FG STATE")
if self.owner_app.is_in_foreground():
should_notify = False
else: else:
self.unread_conversation(context_dest) self.unread_conversation(context_dest)
self.owner_app.flag_unread_conversations = True self.owner_app.flag_unread_conversations = True
@ -925,6 +941,15 @@ class SidebandCore():
except Exception as e: except Exception as e:
RNS.log("Error in conversation update callback: "+str(e)) RNS.log("Error in conversation update callback: "+str(e))
if should_notify:
nlen = 128
text = message.content.decode("utf-8")
notification_content = text[:nlen]
if len(text) > nlen:
text += "..."
self.owner_app.notify(title="Message from "+self.peer_display_name(context_dest), content=notification_content)
def start(self): def start(self):
self._db_clean_messages() self._db_clean_messages()

View File

@ -6,8 +6,8 @@ MDNavigationLayout:
ScreenManager: ScreenManager:
id: screen_manager id: screen_manager
# transition: SlideTransition() transition: SlideTransition()
transition: NoTransition() # transition: NoTransition()
MDScreen: MDScreen:
name: "starting_screen" name: "starting_screen"