From 2416f0ea1a52da1d58a2562ecbe8172aa3779e3c Mon Sep 17 00:00:00 2001 From: Hemna Date: Tue, 22 Aug 2023 16:03:27 -0400 Subject: [PATCH] Added dupe checkig code to webchat mobile --- .../web/chat/static/js/send-message-mobile.js | 32 ++++++++++++++++--- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/aprsd/web/chat/static/js/send-message-mobile.js b/aprsd/web/chat/static/js/send-message-mobile.js index 7dc92e6..ad699ad 100644 --- a/aprsd/web/chat/static/js/send-message-mobile.js +++ b/aprsd/web/chat/static/js/send-message-mobile.js @@ -1,6 +1,7 @@ var cleared = false; var callsign_list = {}; var message_list = {}; +var from_msg_list = {}; function size_dict(d){c=0; for (i in d) ++c; return c} @@ -117,8 +118,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+'
'; @@ -135,6 +137,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"); @@ -146,12 +155,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(); @@ -163,7 +187,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); }