diff --git a/internal/web/static/js/holdem.js b/internal/web/static/js/holdem.js index 8ee12b2..9cdd199 100644 --- a/internal/web/static/js/holdem.js +++ b/internal/web/static/js/holdem.js @@ -62,6 +62,7 @@ var chatSection = root.querySelector("[data-chat]"); var chatLog = root.querySelector("[data-chat-log]"); + var chatSeen = {}; // chat line ids already on the rail, to drop echoed duplicates var chatForm = root.querySelector("[data-chat-form]"); var chatInput = root.querySelector("[data-chat-input]"); var lobbyWrap = root.querySelector("[data-lobby-wrap]"); @@ -734,6 +735,7 @@ function unseated() { disconnectLive(); if (chatLog) chatLog.innerHTML = ""; + chatSeen = {}; } function connectLive() { @@ -775,6 +777,7 @@ .then(function (data) { if (!data || !chatLog) return; chatLog.innerHTML = ""; + chatSeen = {}; (data.chat || []).forEach(addChat); }) .catch(function () {}); @@ -782,6 +785,12 @@ function addChat(line) { if (!chatLog || !line) return; + // Your own line comes back twice — once from the POST that sent it, once + // echoed over your own stream — so drop any id already on the rail. + if (line.id) { + if (chatSeen[line.id]) return; + chatSeen[line.id] = true; + } var row = document.createElement("div"); row.className = "pete-chat-line" + (line.mine ? " pete-chat-mine" : ""); var who = document.createElement("span"); diff --git a/internal/web/static/js/uno.js b/internal/web/static/js/uno.js index 58ecb52..72619ec 100644 --- a/internal/web/static/js/uno.js +++ b/internal/web/static/js/uno.js @@ -66,6 +66,7 @@ var tableMsg = root.querySelector("[data-table-msg]"); var chatLog = root.querySelector("[data-chat-log]"); + var chatSeen = {}; // chat line ids already on the rail, to drop echoed duplicates var chatForm = root.querySelector("[data-chat-form]"); var chatInput = root.querySelector("[data-chat-input]"); @@ -785,7 +786,7 @@ // ---- the live stream ------------------------------------------------------- function seated() { loadChat(); connectLive(); } - function unseated() { disconnectLive(); if (chatLog) chatLog.innerHTML = ""; } + function unseated() { disconnectLive(); if (chatLog) chatLog.innerHTML = ""; chatSeen = {}; } function connectLive() { if (stream || !window.EventSource) return; @@ -818,6 +819,7 @@ .then(function (data) { if (!data || !chatLog) return; chatLog.innerHTML = ""; + chatSeen = {}; (data.chat || []).forEach(addChat); }) .catch(function () {}); @@ -825,6 +827,12 @@ function addChat(line) { if (!chatLog || !line) return; + // Your own line comes back twice — once from the POST that sent it, once + // echoed over your own stream — so drop any id already on the rail. + if (line.id) { + if (chatSeen[line.id]) return; + chatSeen[line.id] = true; + } var row = document.createElement("div"); row.className = "pete-chat-line" + (line.mine ? " pete-chat-mine" : ""); var who = document.createElement("span");