mirror of
https://github.com/liberatedsystems/openCom-Companion.git
synced 2025-02-23 01:39:52 +01:00
Added ability to cancel outbound messages
This commit is contained in:
parent
60591d3f0d
commit
4dfd423915
@ -1868,6 +1868,10 @@ class SidebandCore():
|
|||||||
image=args["image"],
|
image=args["image"],
|
||||||
audio=args["audio"])
|
audio=args["audio"])
|
||||||
connection.send(send_result)
|
connection.send(send_result)
|
||||||
|
elif "cancel_message" in call:
|
||||||
|
args = call["cancel_message"]
|
||||||
|
cancel_result = self.cancel_message(args["message_id"])
|
||||||
|
connection.send(cancel_result)
|
||||||
elif "send_command" in call:
|
elif "send_command" in call:
|
||||||
args = call["send_command"]
|
args = call["send_command"]
|
||||||
send_result = self.send_command(
|
send_result = self.send_command(
|
||||||
@ -4273,6 +4277,21 @@ class SidebandCore():
|
|||||||
RNS.log("An error occurred while getting message transfer stamp cost: "+str(e), RNS.LOG_ERROR)
|
RNS.log("An error occurred while getting message transfer stamp cost: "+str(e), RNS.LOG_ERROR)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def _service_cancel_message(self, message_id):
|
||||||
|
if not RNS.vendor.platformutils.is_android():
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
if self.is_client:
|
||||||
|
try:
|
||||||
|
return self.service_rpc_request({"cancel_message": {"message_id": message_id }})
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
RNS.log("Error while cancelling message over RPC: "+str(e), RNS.LOG_DEBUG)
|
||||||
|
RNS.trace_exception(e)
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
def _service_send_message(self, content, destination_hash, propagation, skip_fields=False, no_display=False, attachment = None, image = None, audio = None):
|
def _service_send_message(self, content, destination_hash, propagation, skip_fields=False, no_display=False, attachment = None, image = None, audio = None):
|
||||||
if not RNS.vendor.platformutils.is_android():
|
if not RNS.vendor.platformutils.is_android():
|
||||||
return False
|
return False
|
||||||
@ -4316,6 +4335,26 @@ class SidebandCore():
|
|||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def cancel_message(self, message_id):
|
||||||
|
if self.allow_service_dispatch and self.is_client:
|
||||||
|
try:
|
||||||
|
return self._service_cancel_message(message_id)
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
RNS.log("Error while cancelling message: "+str(e), RNS.LOG_ERROR)
|
||||||
|
RNS.trace_exception(e)
|
||||||
|
return False
|
||||||
|
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
self.message_router.cancel_outbound(message_id)
|
||||||
|
return True
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
RNS.log("Error while cancelling message: "+str(e), RNS.LOG_ERROR)
|
||||||
|
RNS.trace_exception(e)
|
||||||
|
return False
|
||||||
|
|
||||||
def send_message(self, content, destination_hash, propagation, skip_fields=False, no_display=False, attachment = None, image = None, audio = None):
|
def send_message(self, content, destination_hash, propagation, skip_fields=False, no_display=False, attachment = None, image = None, audio = None):
|
||||||
if self.allow_service_dispatch and self.is_client:
|
if self.allow_service_dispatch and self.is_client:
|
||||||
try:
|
try:
|
||||||
|
@ -20,11 +20,13 @@ color_delivered = "Blue"
|
|||||||
color_paper = "Indigo"
|
color_paper = "Indigo"
|
||||||
color_propagated = "Indigo"
|
color_propagated = "Indigo"
|
||||||
color_failed = "Red"
|
color_failed = "Red"
|
||||||
|
color_cancelled = "Red"
|
||||||
color_unknown = "Gray"
|
color_unknown = "Gray"
|
||||||
intensity_msgs_dark = "800"
|
intensity_msgs_dark = "800"
|
||||||
intensity_msgs_light = "500"
|
intensity_msgs_light = "500"
|
||||||
intensity_play_dark = "600"
|
intensity_play_dark = "600"
|
||||||
intensity_play_light = "300"
|
intensity_play_light = "300"
|
||||||
|
intensity_cancelled = "900"
|
||||||
|
|
||||||
|
|
||||||
intensity_msgs_dark_alt = "800"
|
intensity_msgs_dark_alt = "800"
|
||||||
@ -38,6 +40,7 @@ color_paper_alt = "DeepPurple"
|
|||||||
color_playing_alt = "Amber"
|
color_playing_alt = "Amber"
|
||||||
color_failed_alt = "Red"
|
color_failed_alt = "Red"
|
||||||
color_unknown_alt = "Gray"
|
color_unknown_alt = "Gray"
|
||||||
|
color_cancelled_alt = "Red"
|
||||||
|
|
||||||
class ContentNavigationDrawer(Screen):
|
class ContentNavigationDrawer(Screen):
|
||||||
pass
|
pass
|
||||||
|
@ -34,14 +34,14 @@ if RNS.vendor.platformutils.get_platform() == "android":
|
|||||||
import plyer
|
import plyer
|
||||||
from sideband.sense import Telemeter, Commands
|
from sideband.sense import Telemeter, Commands
|
||||||
from ui.helpers import ts_format, file_ts_format, mdc
|
from ui.helpers import ts_format, file_ts_format, mdc
|
||||||
from ui.helpers import color_playing, color_received, color_delivered, color_propagated, color_paper, color_failed, color_unknown, intensity_msgs_dark, intensity_msgs_light, intensity_play_dark, intensity_play_light
|
from ui.helpers import color_playing, color_received, color_delivered, color_propagated, color_paper, color_failed, color_unknown, intensity_msgs_dark, intensity_msgs_light, intensity_play_dark, intensity_play_light, color_cancelled, intensity_cancelled
|
||||||
from ui.helpers import color_received_alt, color_received_alt_light, color_delivered_alt, color_propagated_alt, color_paper_alt, color_failed_alt, color_unknown_alt, color_playing_alt, intensity_msgs_dark_alt, intensity_msgs_light_alt, intensity_delivered_alt_dark
|
from ui.helpers import color_received_alt, color_received_alt_light, color_delivered_alt, color_propagated_alt, color_paper_alt, color_failed_alt, color_unknown_alt, color_playing_alt, intensity_msgs_dark_alt, intensity_msgs_light_alt, intensity_delivered_alt_dark, color_cancelled_alt
|
||||||
else:
|
else:
|
||||||
import sbapp.plyer as plyer
|
import sbapp.plyer as plyer
|
||||||
from sbapp.sideband.sense import Telemeter, Commands
|
from sbapp.sideband.sense import Telemeter, Commands
|
||||||
from .helpers import ts_format, file_ts_format, mdc
|
from .helpers import ts_format, file_ts_format, mdc
|
||||||
from .helpers import color_playing, color_received, color_delivered, color_propagated, color_paper, color_failed, color_unknown, intensity_msgs_dark, intensity_msgs_light, intensity_play_dark, intensity_play_light
|
from .helpers import color_playing, color_received, color_delivered, color_propagated, color_paper, color_failed, color_unknown, intensity_msgs_dark, intensity_msgs_light, intensity_play_dark, intensity_play_light, color_cancelled, intensity_cancelled
|
||||||
from .helpers import color_received_alt, color_received_alt_light, color_delivered_alt, color_propagated_alt, color_paper_alt, color_failed_alt, color_unknown_alt, color_playing_alt, intensity_msgs_dark_alt, intensity_msgs_light_alt, intensity_delivered_alt_dark
|
from .helpers import color_received_alt, color_received_alt_light, color_delivered_alt, color_propagated_alt, color_paper_alt, color_failed_alt, color_unknown_alt, color_playing_alt, intensity_msgs_dark_alt, intensity_msgs_light_alt, intensity_delivered_alt_dark, color_cancelled_alt
|
||||||
|
|
||||||
if RNS.vendor.platformutils.is_darwin():
|
if RNS.vendor.platformutils.is_darwin():
|
||||||
from PIL import Image as PilImage
|
from PIL import Image as PilImage
|
||||||
@ -213,6 +213,7 @@ class Messages():
|
|||||||
c_paper = color_paper_alt
|
c_paper = color_paper_alt
|
||||||
c_unknown = color_unknown_alt
|
c_unknown = color_unknown_alt
|
||||||
c_failed = color_failed_alt
|
c_failed = color_failed_alt
|
||||||
|
c_cancelled = color_cancelled_alt
|
||||||
else:
|
else:
|
||||||
c_delivered = color_delivered
|
c_delivered = color_delivered
|
||||||
c_received = color_received
|
c_received = color_received
|
||||||
@ -221,6 +222,7 @@ class Messages():
|
|||||||
c_paper = color_paper
|
c_paper = color_paper
|
||||||
c_unknown = color_unknown
|
c_unknown = color_unknown
|
||||||
c_failed = color_failed
|
c_failed = color_failed
|
||||||
|
c_cancelled = color_cancelled
|
||||||
|
|
||||||
for new_message in self.app.sideband.list_messages(self.context_dest, after=self.latest_message_timestamp,limit=limit):
|
for new_message in self.app.sideband.list_messages(self.context_dest, after=self.latest_message_timestamp,limit=limit):
|
||||||
self.new_messages.append(new_message)
|
self.new_messages.append(new_message)
|
||||||
@ -369,7 +371,7 @@ class Messages():
|
|||||||
m["state"] = msg["state"]
|
m["state"] = msg["state"]
|
||||||
|
|
||||||
if msg["state"] == LXMF.LXMessage.FAILED:
|
if msg["state"] == LXMF.LXMessage.FAILED:
|
||||||
w.md_bg_color = msg_color = mdc(c_failed, intensity_msgs)
|
w.md_bg_color = msg_color = mdc(c_failed, intensity_cancelled)
|
||||||
txstr = time.strftime(ts_format, time.localtime(msg["sent"]))
|
txstr = time.strftime(ts_format, time.localtime(msg["sent"]))
|
||||||
titlestr = ""
|
titlestr = ""
|
||||||
if msg["title"]:
|
if msg["title"]:
|
||||||
@ -381,6 +383,19 @@ class Messages():
|
|||||||
w.heading += f"\n[b]Audio Message[/b] ({alstr})"
|
w.heading += f"\n[b]Audio Message[/b] ({alstr})"
|
||||||
w.dmenu.items.append(w.dmenu.retry_item)
|
w.dmenu.items.append(w.dmenu.retry_item)
|
||||||
|
|
||||||
|
if msg["state"] == LXMF.LXMessage.CANCELLED:
|
||||||
|
w.md_bg_color = msg_color = mdc(c_cancelled, intensity_cancelled)
|
||||||
|
txstr = time.strftime(ts_format, time.localtime(msg["sent"]))
|
||||||
|
titlestr = ""
|
||||||
|
if msg["title"]:
|
||||||
|
titlestr = "[b]Title[/b] "+msg["title"].decode("utf-8")+"\n"
|
||||||
|
w.heading = titlestr+"[b]Sent[/b] "+txstr+"\n[b]State[/b] Cancelled"
|
||||||
|
m["state"] = msg["state"]
|
||||||
|
if w.has_audio:
|
||||||
|
alstr = RNS.prettysize(w.audio_size)
|
||||||
|
w.heading += f"\n[b]Audio Message[/b] ({alstr})"
|
||||||
|
w.dmenu.items.append(w.dmenu.retry_item)
|
||||||
|
|
||||||
|
|
||||||
def hide_widget(self, wid, dohide=True):
|
def hide_widget(self, wid, dohide=True):
|
||||||
if hasattr(wid, 'saved_attrs'):
|
if hasattr(wid, 'saved_attrs'):
|
||||||
@ -427,6 +442,7 @@ class Messages():
|
|||||||
c_paper = color_paper_alt
|
c_paper = color_paper_alt
|
||||||
c_unknown = color_unknown_alt
|
c_unknown = color_unknown_alt
|
||||||
c_failed = color_failed_alt
|
c_failed = color_failed_alt
|
||||||
|
c_cancelled = color_cancelled_alt
|
||||||
else:
|
else:
|
||||||
c_delivered = color_delivered
|
c_delivered = color_delivered
|
||||||
c_received = color_received
|
c_received = color_received
|
||||||
@ -435,6 +451,7 @@ class Messages():
|
|||||||
c_paper = color_paper
|
c_paper = color_paper
|
||||||
c_unknown = color_unknown
|
c_unknown = color_unknown
|
||||||
c_failed = color_failed
|
c_failed = color_failed
|
||||||
|
c_cancelled = color_cancelled
|
||||||
|
|
||||||
self.ids.message_text.font_name = self.app.input_font
|
self.ids.message_text.font_name = self.app.input_font
|
||||||
|
|
||||||
@ -602,9 +619,13 @@ class Messages():
|
|||||||
heading_str = titlestr+"[b]Created[/b] "+txstr+"\n[b]State[/b] Paper Message"
|
heading_str = titlestr+"[b]Created[/b] "+txstr+"\n[b]State[/b] Paper Message"
|
||||||
|
|
||||||
elif m["state"] == LXMF.LXMessage.FAILED:
|
elif m["state"] == LXMF.LXMessage.FAILED:
|
||||||
msg_color = mdc(c_failed, intensity_msgs)
|
msg_color = mdc(c_failed, intensity_cancelled)
|
||||||
heading_str = titlestr+"[b]Sent[/b] "+txstr+"\n[b]State[/b] Failed"
|
heading_str = titlestr+"[b]Sent[/b] "+txstr+"\n[b]State[/b] Failed"
|
||||||
|
|
||||||
|
elif m["state"] == LXMF.LXMessage.CANCELLED:
|
||||||
|
msg_color = mdc(c_cancelled, intensity_cancelled)
|
||||||
|
heading_str = titlestr+"[b]Sent[/b] "+txstr+"\n[b]State[/b] Cancelled"
|
||||||
|
|
||||||
elif m["state"] == LXMF.LXMessage.OUTBOUND or m["state"] == LXMF.LXMessage.SENDING:
|
elif m["state"] == LXMF.LXMessage.OUTBOUND or m["state"] == LXMF.LXMessage.SENDING:
|
||||||
msg_color = mdc(c_unknown, intensity_msgs)
|
msg_color = mdc(c_unknown, intensity_msgs)
|
||||||
heading_str = titlestr+"[b]Sent[/b] "+txstr+"\n[b]State[/b] Sending "
|
heading_str = titlestr+"[b]Sent[/b] "+txstr+"\n[b]State[/b] Sending "
|
||||||
@ -798,6 +819,13 @@ class Messages():
|
|||||||
|
|
||||||
return x
|
return x
|
||||||
|
|
||||||
|
def gen_cancel(mhash, item):
|
||||||
|
def x():
|
||||||
|
self.app.sideband.cancel_message(mhash)
|
||||||
|
item.dmenu.dismiss()
|
||||||
|
|
||||||
|
return x
|
||||||
|
|
||||||
def gen_save_image(item):
|
def gen_save_image(item):
|
||||||
if RNS.vendor.platformutils.is_android():
|
if RNS.vendor.platformutils.is_android():
|
||||||
def x():
|
def x():
|
||||||
@ -1197,6 +1225,14 @@ class Messages():
|
|||||||
"on_release": gen_save_attachment(item)
|
"on_release": gen_save_attachment(item)
|
||||||
}
|
}
|
||||||
dm_items.append(extra_item)
|
dm_items.append(extra_item)
|
||||||
|
if m["state"] <= LXMF.LXMessage.SENT:
|
||||||
|
extra_item = {
|
||||||
|
"viewclass": "OneLineListItem",
|
||||||
|
"text": "Cancel message",
|
||||||
|
"height": dp(40),
|
||||||
|
"on_release": gen_cancel(m["hash"], item)
|
||||||
|
}
|
||||||
|
dm_items.append(extra_item)
|
||||||
|
|
||||||
item.dmenu = MDDropdownMenu(
|
item.dmenu = MDDropdownMenu(
|
||||||
caller=item.ids.msg_submenu,
|
caller=item.ids.msg_submenu,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user