@@ -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))