games: the chat line that shows up once, not twice
Your own message came back twice — once from the POST that sent it, once echoed over your own SSE stream — so the felt printed it on the rail twice. Drop any chat id already seen; reset the seen-set when the log is cleared (unseated, and on a full chat reload). Claude-Session: https://claude.ai/code/session_013M5nD7PgUboJXoDcYHzpuJ
This commit is contained in:
@@ -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");
|
||||
|
||||
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user