From 4a6dfa4a4712d43b3206f351f569dea1292ea463 Mon Sep 17 00:00:00 2001 From: Mark Qvist Date: Mon, 16 Oct 2023 22:21:38 +0200 Subject: [PATCH] Added retry option on failed messages --- sbapp/ui/messages.py | 66 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 52 insertions(+), 14 deletions(-) diff --git a/sbapp/ui/messages.py b/sbapp/ui/messages.py index e96f08e..0a93f08 100644 --- a/sbapp/ui/messages.py +++ b/sbapp/ui/messages.py @@ -149,6 +149,7 @@ class Messages(): titlestr = "[b]Title[/b] "+msg["title"].decode("utf-8")+"\n" w.heading = titlestr+"[b]Sent[/b] "+txstr+"\n[b]State[/b] Failed" m["state"] = msg["state"] + w.dmenu.items.append(w.dmenu.retry_item) def update_widget(self): @@ -240,6 +241,18 @@ class Messages(): dialog.open() return x + def gen_retry(mhash, mcontent, item): + def x(): + self.app.root.ids.message_text.text = mcontent.decode("utf-8") + self.app.sideband.delete_message(mhash) + self.app.message_send_action() + item.dmenu.dismiss() + def cb(dt): + self.reload() + Clock.schedule_once(cb, 0.2) + + return x + def gen_copy(msg, item): def x(): Clipboard.copy(msg) @@ -346,6 +359,12 @@ class Messages(): return x + retry_item = { + "viewclass": "OneLineListItem", + "text": "Retry", + "height": dp(40), + "on_release": gen_retry(m["hash"], m["content"], item) + } if m["method"] == LXMF.LXMessage.PAPER: if RNS.vendor.platformutils.is_android(): qr_save_text = "Share QR Code" @@ -411,20 +430,38 @@ class Messages(): ] else: - dm_items = [ - { - "viewclass": "OneLineListItem", - "text": "Copy", - "height": dp(40), - "on_release": gen_copy(m["content"].decode("utf-8"), item) - }, - { - "text": "Delete", - "viewclass": "OneLineListItem", - "height": dp(40), - "on_release": gen_del(m["hash"], item) - } - ] + if m["state"] == LXMF.LXMessage.FAILED: + dm_items = [ + retry_item, + { + "viewclass": "OneLineListItem", + "text": "Copy", + "height": dp(40), + "on_release": gen_copy(m["content"].decode("utf-8"), item) + }, + { + "text": "Delete", + "viewclass": "OneLineListItem", + "height": dp(40), + "on_release": gen_del(m["hash"], item) + } + ] + else: + dm_items = [ + { + "viewclass": "OneLineListItem", + "text": "Copy", + "height": dp(40), + "on_release": gen_copy(m["content"].decode("utf-8"), item) + }, + { + "text": "Delete", + "viewclass": "OneLineListItem", + "height": dp(40), + "on_release": gen_del(m["hash"], item) + } + + ] item.dmenu = MDDropdownMenu( caller=item.ids.msg_submenu, @@ -434,6 +471,7 @@ class Messages(): elevation=0, radius=dp(3), ) + item.dmenu.retry_item = retry_item def callback_factory(ref): def x(sender):