From 018075eb126a6c0ae45708b411983f5ed64ea0cc Mon Sep 17 00:00:00 2001 From: liamcottle Date: Mon, 4 Nov 2024 18:37:41 +1300 Subject: [PATCH] allow selecting delivery method before sending messages --- meshchat.py | 38 +++++++--- .../messages/ConversationViewer.vue | 16 +++- .../components/messages/SendMessageButton.vue | 76 +++++++++++++++++++ 3 files changed, 117 insertions(+), 13 deletions(-) create mode 100644 src/frontend/components/messages/SendMessageButton.vue diff --git a/meshchat.py b/meshchat.py index 0d6154a..e203699 100644 --- a/meshchat.py +++ b/meshchat.py @@ -1254,6 +1254,11 @@ class ReticulumMeshChat: # get request body as json data = await request.json() + # get delivery method + delivery_method = None + if "delivery_method" in data: + delivery_method = data["delivery_method"] + # get data from json destination_hash = data["lxmf_message"]["destination_hash"] content = data["lxmf_message"]["content"] @@ -1295,7 +1300,8 @@ class ReticulumMeshChat: content=content, image_field=image_field, audio_field=audio_field, - file_attachments_field=file_attachments_field + file_attachments_field=file_attachments_field, + delivery_method=delivery_method ) return web.json_response({ @@ -2143,7 +2149,8 @@ class ReticulumMeshChat: async def send_message(self, destination_hash: str, content: str, image_field: LxmfImageField = None, audio_field: LxmfAudioField = None, - file_attachments_field: LxmfFileAttachmentsField = None) -> LXMF.LXMessage: + file_attachments_field: LxmfFileAttachmentsField = None, + delivery_method: str = None) -> LXMF.LXMessage: # convert destination hash to bytes destination_hash = bytes.fromhex(destination_hash) @@ -2171,14 +2178,27 @@ class ReticulumMeshChat: # create destination for recipients lxmf delivery address lxmf_destination = RNS.Destination(destination_identity, RNS.Destination.OUT, RNS.Destination.SINGLE, "lxmf", "delivery") - # send messages over a direct link by default - desired_delivery_method = LXMF.LXMessage.DIRECT - if not self.message_router.delivery_link_available(destination_hash) and RNS.Identity.current_ratchet_id(destination_hash) != None: - # since there's no link established to the destination, it's faster to send opportunistically - # this is because it takes several packets to establish a link, and then we still have to send the message over it - # oppotunistic mode will send the message in a single packet (if the message is small enough, otherwise it falls back to a direct link) - # we will only do this if an encryption ratchet is available, so single packet delivery is more secure + # determine how the user wants to send the message + desired_delivery_method = None + if delivery_method == "direct": + desired_delivery_method = LXMF.LXMessage.DIRECT + elif delivery_method == "opportunistic": desired_delivery_method = LXMF.LXMessage.OPPORTUNISTIC + elif delivery_method == "propagated": + desired_delivery_method = LXMF.LXMessage.PROPAGATED + + # determine how to send the message if the user didn't provide a method + if desired_delivery_method is None: + + # send messages over a direct link by default + desired_delivery_method = LXMF.LXMessage.DIRECT + if not self.message_router.delivery_link_available(destination_hash) and RNS.Identity.current_ratchet_id(destination_hash) != None: + + # since there's no link established to the destination, it's faster to send opportunistically + # this is because it takes several packets to establish a link, and then we still have to send the message over it + # oppotunistic mode will send the message in a single packet (if the message is small enough, otherwise it falls back to a direct link) + # we will only do this if an encryption ratchet is available, so single packet delivery is more secure + desired_delivery_method = LXMF.LXMessage.OPPORTUNISTIC # create lxmf message lxmf_message = LXMF.LXMessage(lxmf_destination, self.local_lxmf_destination, content, desired_method=desired_delivery_method) diff --git a/src/frontend/components/messages/ConversationViewer.vue b/src/frontend/components/messages/ConversationViewer.vue index 20b9afa..e04757a 100644 --- a/src/frontend/components/messages/ConversationViewer.vue +++ b/src/frontend/components/messages/ConversationViewer.vue @@ -332,10 +332,14 @@ - +
+ +
@@ -371,10 +375,12 @@ import NotificationUtils from "../../js/NotificationUtils"; import WebSocketConnection from "../../js/WebSocketConnection"; import AddAudioButton from "./AddAudioButton.vue"; import moment from "moment"; +import SendMessageButton from "./SendMessageButton.vue"; export default { name: 'ConversationViewer', components: { + SendMessageButton, AddAudioButton, }, props: { @@ -394,6 +400,7 @@ export default { isLoadingPrevious: false, hasMorePrevious: true, + newMessageDeliveryMethod: null, newMessageText: "", newMessageImage: null, newMessageImageUrl: null, @@ -1022,6 +1029,7 @@ export default { // send message to reticulum const response = await window.axios.post(`/api/v1/lxmf-messages/send`, { + "delivery_method": this.newMessageDeliveryMethod, "lxmf_message": { "destination_hash": this.selectedPeer.destination_hash, "content": this.newMessageText, diff --git a/src/frontend/components/messages/SendMessageButton.vue b/src/frontend/components/messages/SendMessageButton.vue new file mode 100644 index 0000000..0d57bfb --- /dev/null +++ b/src/frontend/components/messages/SendMessageButton.vue @@ -0,0 +1,76 @@ + + +