From a8dd9ce0129d24a16c033546ffbff7d9b59f0885 Mon Sep 17 00:00:00 2001 From: Hemna Date: Tue, 22 Aug 2023 13:37:43 -0400 Subject: [PATCH] Webchat suppress to display of dupe messages This patch updates the web ui for webchat to suppress the displaying of duplicate recieved messages. Dupes can happen over the KISS interface due to packets being encapsulated by nearby repeaters into 3rd party packets. When a dupe message is recieved, the dupe message is flashed 3 times. --- aprsd/cmds/webchat.py | 2 +- aprsd/web/chat/static/js/send-message.js | 32 +++++++++++++++++++++--- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/aprsd/cmds/webchat.py b/aprsd/cmds/webchat.py index a7552f4..67ae9cb 100644 --- a/aprsd/cmds/webchat.py +++ b/aprsd/cmds/webchat.py @@ -163,7 +163,7 @@ class WebChatProcessPacketThread(rx.APRSDProcessPacketThread): message = packet.get("message_text", None) msg = { - "id": 0, + "id": packet.msgNo, "ts": packet.get("timestamp", time.time()), "ack": False, "from": fromcall, diff --git a/aprsd/web/chat/static/js/send-message.js b/aprsd/web/chat/static/js/send-message.js index 28b9d28..e540ee8 100644 --- a/aprsd/web/chat/static/js/send-message.js +++ b/aprsd/web/chat/static/js/send-message.js @@ -1,6 +1,7 @@ var cleared = false; var callsign_list = {}; var message_list = {}; +var from_msg_list = {}; const socket = io("/sendmsg"); function size_dict(d){c=0; for (i in d) ++c; return c} @@ -111,8 +112,9 @@ function append_message_html(callsign, msg_html, new_callsign) { $(divname).animate({scrollTop: $(divname)[0].scrollHeight}, "slow"); } -function create_message_html(time, from, to, message, ack) { - msg_html = '
'; +function create_message_html(time, from, to, message, ack, msg) { + div_id = from + "_" + msg.id; + msg_html = '
'; msg_html += '
'+time+'
'; msg_html += '
'; msg_html += '
'+from+'
'; @@ -129,6 +131,13 @@ function create_message_html(time, from, to, message, ack) { return msg_html } +function flash_message(msg) { + // Callback function to bring a hidden box back + id = msg.from + "_" + msg.id; + var msgid = $('#'+id); + msgid.effect("pulsate", { times:3 }, 2000); +} + function sent_msg(msg) { var msgsdiv = $("#sendMsgsDiv"); @@ -140,12 +149,27 @@ function sent_msg(msg) { var d = new Date(ts).toLocaleDateString("en-US") var t = new Date(ts).toLocaleTimeString("en-US") - msg_html = create_message_html(t, msg['from'], msg['to'], msg['message'], ack_id); + msg_html = create_message_html(t, msg['from'], msg['to'], msg['message'], ack_id, msg); append_message(msg['to'], msg, msg_html); } function from_msg(msg) { var msgsdiv = $("#sendMsgsDiv"); + console.log(msg); + if (!from_msg_list.hasOwnProperty(msg.from)) { + from_msg_list[msg.from] = new Array(); + } + + if (msg.id in from_msg_list[msg.from]) { + // We already have this message + console.log("We already have this message " + msg); + // Do some flashy thing? + flash_message(msg); + return false + } else { + console.log("Adding message " + msg.id + " to " + msg.from); + from_msg_list[msg.from][msg.id] = msg + } // We have an existing entry ts_str = msg["ts"].toString(); @@ -157,7 +181,7 @@ function from_msg(msg) { var t = new Date(ts).toLocaleTimeString("en-US") from = msg['from'] - msg_html = create_message_html(t, from, false, msg['message'], false); + msg_html = create_message_html(t, from, false, msg['message'], false, msg); append_message(from, msg, msg_html); }