From 7e7d519532add1f922a4d69f41e852abdbb0da4a Mon Sep 17 00:00:00 2001 From: liamcottle Date: Wed, 25 Sep 2024 22:19:12 +1200 Subject: [PATCH] show lxmf stamp cost in conversation viewer --- meshchat.py | 25 +++++++++++++ .../messages/ConversationViewer.vue | 35 ++++++++++++++++++- 2 files changed, 59 insertions(+), 1 deletion(-) diff --git a/meshchat.py b/meshchat.py index 4f9627f..2be642c 100644 --- a/meshchat.py +++ b/meshchat.py @@ -1082,6 +1082,23 @@ class ReticulumMeshChat: "message": "Custom display name has been removed", }) + # get lxmf stamp cost for the provided lxmf.delivery destination hash + @routes.get("/api/v1/destination/{destination_hash}/lxmf-stamp-cost") + async def index(request): + + # get path params + destination_hash = request.match_info.get("destination_hash", "") + + # get lxmf stamp cost from announce in database + lxmf_stamp_cost = None + announce = database.Announce.get_or_none(database.Announce.destination_hash == destination_hash) + if announce is not None: + lxmf_stamp_cost = self.parse_lxmf_stamp_cost(announce.app_data) + + return web.json_response({ + "lxmf_stamp_cost": lxmf_stamp_cost, + }) + # get interface stats @routes.get("/api/v1/interface-stats") async def index(request): @@ -2332,6 +2349,14 @@ class ReticulumMeshChat: except: return default_value + # reads the lxmf stamp cost from the provided base64 app data + def parse_lxmf_stamp_cost(self, app_data_base64: str): + try: + app_data_bytes = base64.b64decode(app_data_base64) + return LXMF.stamp_cost_from_app_data(app_data_bytes) + except: + return None + # reads the nomadnetwork node display name from the provided base64 app data def parse_nomadnetwork_node_display_name(self, app_data_base64: str, default_value: str | None = "Anonymous Node"): try: diff --git a/src/frontend/components/messages/ConversationViewer.vue b/src/frontend/components/messages/ConversationViewer.vue index 647127a..70d543b 100644 --- a/src/frontend/components/messages/ConversationViewer.vue +++ b/src/frontend/components/messages/ConversationViewer.vue @@ -17,7 +17,11 @@
{{ selectedPeer.custom_display_name ?? selectedPeer.display_name }}
-
<{{ selectedPeer.destination_hash }}> {{ selectedPeerPath.hops }} {{ selectedPeerPath.hops === 1 ? 'hop' : 'hops' }} away
+
+ <{{ selectedPeer.destination_hash }}> + {{ selectedPeerPath.hops }} {{ selectedPeerPath.hops === 1 ? 'hop' : 'hops' }} away + • Stamp Cost {{ selectedPeerLxmfStampCost }} +
@@ -380,6 +384,7 @@ export default { return { selectedPeerPath: null, + selectedPeerLxmfStampCost: null, lxmfMessagesRequestSequence: 0, chatItems: [], @@ -455,6 +460,7 @@ export default { } this.getPeerPath(); + this.getPeerLxmfStampCost(); // load 1 page of previous messages await this.loadPrevious(); @@ -523,6 +529,13 @@ export default { async onWebsocketMessage(message) { const json = JSON.parse(message.data); switch(json.type){ + case 'announce': { + // update stamp cost if an announce is received from the selected peer + if(json.announce.destination_hash === this.selectedPeer?.destination_hash){ + await this.getPeerLxmfStampCost(); + } + break; + } case 'lxmf.delivery': { this.onLxmfMessageReceived(json.lxmf_message); await this.getPeerPath(); @@ -627,6 +640,26 @@ export default { } } + }, + async getPeerLxmfStampCost() { + + // clear previous stamp cost + this.selectedPeerLxmfStampCost = null; + + if(this.selectedPeer){ + try { + + // get lxmf stamp cost + const response = await window.axios.get(`/api/v1/destination/${this.selectedPeer.destination_hash}/lxmf-stamp-cost`); + + // update ui + this.selectedPeerLxmfStampCost = response.data.lxmf_stamp_cost; + + } catch(e) { + console.log(e); + } + } + }, onDestinationPathClick(path) { DialogUtils.alert(`${path.hops} ${ path.hops === 1 ? 'hop' : 'hops' } away via ${path.next_hop_interface}`);