Added message notifications
This commit is contained in:
parent
0d9abec269
commit
1b8bb58683
|
@ -52,9 +52,15 @@ if RNS.vendor.platformutils.get_platform() == "android":
|
|||
from android.runnable import run_on_ui_thread
|
||||
|
||||
class SidebandApp(MDApp):
|
||||
STARTING = 0x00
|
||||
ACTIVE = 0x01
|
||||
PAUSED = 0x02
|
||||
STOPPING = 0x03
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
super().__init__(**kwargs)
|
||||
self.title = "Sideband"
|
||||
self.app_state = SidebandApp.STARTING
|
||||
|
||||
self.sideband = SidebandCore(self)
|
||||
|
||||
|
@ -82,6 +88,7 @@ class SidebandApp(MDApp):
|
|||
if RNS.vendor.platformutils.get_platform() == "android":
|
||||
Clock.schedule_once(dismiss_splash, 0)
|
||||
|
||||
self.app_state = SidebandApp.ACTIVE
|
||||
|
||||
def start_android_service(self):
|
||||
service = autoclass('io.unsigned.sideband.ServiceSidebandservice')
|
||||
|
@ -94,6 +101,23 @@ class SidebandApp(MDApp):
|
|||
# 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):
|
||||
notifications_enabled = True
|
||||
|
||||
|
|
|
@ -161,6 +161,11 @@ class SidebandCore():
|
|||
if not os.path.isfile(self.db_path):
|
||||
self.__db_init()
|
||||
|
||||
def should_persist_data(self):
|
||||
if self.reticulum != None:
|
||||
self.reticulum._should_persist_data()
|
||||
|
||||
self.save_configuration()
|
||||
|
||||
def __load_config(self):
|
||||
RNS.log("Loading Sideband identity...")
|
||||
|
@ -896,10 +901,17 @@ class SidebandCore():
|
|||
return True
|
||||
|
||||
def lxm_ingest(self, message, originator = False):
|
||||
should_notify = False
|
||||
is_trusted = False
|
||||
|
||||
if originator:
|
||||
context_dest = message.destination_hash
|
||||
else:
|
||||
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)
|
||||
|
@ -916,6 +928,10 @@ class SidebandCore():
|
|||
if self.owner_app.root.ids.messages_scrollview.active_conversation != context_dest:
|
||||
self.unread_conversation(context_dest)
|
||||
self.owner_app.flag_unread_conversations = True
|
||||
else:
|
||||
RNS.log("CHECKING FG STATE")
|
||||
if self.owner_app.is_in_foreground():
|
||||
should_notify = False
|
||||
else:
|
||||
self.unread_conversation(context_dest)
|
||||
self.owner_app.flag_unread_conversations = True
|
||||
|
@ -925,6 +941,15 @@ class SidebandCore():
|
|||
except Exception as 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):
|
||||
self._db_clean_messages()
|
||||
|
|
|
@ -6,8 +6,8 @@ MDNavigationLayout:
|
|||
|
||||
ScreenManager:
|
||||
id: screen_manager
|
||||
# transition: SlideTransition()
|
||||
transition: NoTransition()
|
||||
transition: SlideTransition()
|
||||
# transition: NoTransition()
|
||||
|
||||
MDScreen:
|
||||
name: "starting_screen"
|
||||
|
|
Loading…
Reference in New Issue