From bf49443005e24802ca5c1f7eecb77d2e56a2930e Mon Sep 17 00:00:00 2001 From: liamcottle Date: Sun, 5 May 2024 02:40:03 +1200 Subject: [PATCH] add button to delete entire conversation --- public/index.html | 41 +++++++++++++++++++++++++++++++++++++++-- web.py | 26 ++++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 2 deletions(-) diff --git a/public/index.html b/public/index.html index bb19807..da6e999 100644 --- a/public/index.html +++ b/public/index.html @@ -163,8 +163,21 @@
@<{{ selectedPeer.destination_hash }}>
- +
+
+
+
+ + + +
+
+
+
+ + +
@@ -962,7 +975,31 @@ binary += String.fromCharCode(bytes[i]); } return window.btoa(binary); - } + }, + async deleteConversation() { + + // do nothing if no peer selected + if(!this.selectedPeer){ + return; + } + + // ask user to confirm deleting conversation history + if(!confirm("Are you sure you want to delete all messages from this conversation? This can not be undone!")){ + return; + } + + // delete all lxmf messages from "us to destination" and from "destination to us" + try { + await window.axios.delete(`/api/v1/lxmf-messages/conversation/${this.selectedPeer.destination_hash}`); + } catch(e) { + alert("failed to delete conversation"); + console.log(e); + } + + // reload conversation + await this.loadLxmfMessages(this.selectedPeer.destination_hash); + + }, }, computed: { isMobile() { diff --git a/web.py b/web.py index 0144c86..73b886d 100644 --- a/web.py +++ b/web.py @@ -208,6 +208,32 @@ class ReticulumWebChat: "message": "ok", }) + # delete lxmf messages for conversation + @routes.delete("/api/v1/lxmf-messages/conversation/{destination_hash}") + async def index(request): + + # get path params + destination_hash = request.match_info.get("destination_hash", None) + + # get source hash from local lxmf destination + source_hash = self.local_lxmf_destination.hash.hex() + + # source_hash is required + if destination_hash is None: + return web.json_response({ + "message": "destination_hash is required", + }, status=422) + + # delete lxmf messages from db where "source to destination" or "destination to source" + (database.LxmfMessage.delete() + .where((database.LxmfMessage.source_hash == source_hash) & (database.LxmfMessage.destination_hash == destination_hash)) + .orwhere((database.LxmfMessage.destination_hash == source_hash) & (database.LxmfMessage.source_hash == destination_hash)) + .execute()) + + return web.json_response({ + "message": "ok", + }) + asyncio.get_event_loop().add_signal_handler(signal.SIGINT, lambda: exit(-1)) asyncio.get_event_loop().add_signal_handler(signal.SIGTERM, lambda: exit(-1))