From d4ae72608b9d7c2da1b89c20bf58fcae796f552d Mon Sep 17 00:00:00 2001 From: Hemna Date: Tue, 26 Nov 2024 19:48:50 -0500 Subject: [PATCH] Fixed webchat packets without msgNo This patch makes a fix in the webchat UI for packets that don't have a msgNo in the RX'd packets. Previously the packets would just show up as a dupe of the previous RX'd packet from the same callsign. Webchat UI will now properly show the message by creating a fake msgNo value based on the contents of the RX'd packet from_call+addressee+message_text --- aprsd/cmds/webchat.py | 2 +- aprsd/web/chat/static/js/send-message.js | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/aprsd/cmds/webchat.py b/aprsd/cmds/webchat.py index 62be1406..26df7c95 100644 --- a/aprsd/cmds/webchat.py +++ b/aprsd/cmds/webchat.py @@ -500,8 +500,8 @@ def on_send(self, data): pkt.prepare() self.msg = pkt msgs = SentMessages() - msgs.add(pkt) tx.send(pkt) + msgs.add(pkt) msgs.set_status(pkt.msgNo, "Sending") obj = msgs.get(pkt.msgNo) socketio.emit( diff --git a/aprsd/web/chat/static/js/send-message.js b/aprsd/web/chat/static/js/send-message.js index 19a5cc18..481c6b2f 100644 --- a/aprsd/web/chat/static/js/send-message.js +++ b/aprsd/web/chat/static/js/send-message.js @@ -510,11 +510,30 @@ function sent_msg(msg) { reload_popovers(); } +function str_to_int(my_string) { + total = 0 + for (let i = 0; i < my_string.length; i++) { + total += my_string.charCodeAt(i); + } + return total +} + function from_msg(msg) { if (!from_msg_list.hasOwnProperty(msg["from_call"])) { from_msg_list[msg["from_call"]] = new Array(); } + // Try to account for messages that have no msgNo + console.log(msg) + if (msg["msgNo"] == null) { + console.log("Need to add msgNO!!") + // create an artificial msgNo + total = str_to_int(msg["from_call"]) + total += str_to_int(msg["addresse"]) + total += str_to_int(msg["message_text"]) + msg["msgNo"] = total + } + if (msg["msgNo"] in from_msg_list[msg["from_call"]]) { // We already have this message //console.log("We already have this message msgNo=" + msg["msgNo"]);