diff --git a/public/app.js b/public/app.js index c6ccd2f..00a95ad 100644 --- a/public/app.js +++ b/public/app.js @@ -39,9 +39,14 @@ function ensureConversation(type, name) { return state.conversations[key]; } +// NOTE: Dedupe is required here. Sent messages can be added optimistically and also +// arrive via SSE replay/broadcast (e.g. TOC sentIM buffer). Never remove this guard +// or duplicates will reappear in the UI. function addMessage(type, name, msg) { if (!name || name === 'unknown') return; const conv = ensureConversation(type, name); + if (msg?.msgId && conv.messages.some((m) => m.msgId && m.msgId === msg.msgId)) return; + if (msg?.text && conv.messages.slice(-6).some((m) => m.text === msg.text && normalizeName(m.from) === normalizeName(msg.from) && !!m.mine === !!msg.mine)) return; conv.messages.push(msg); if (!state.active) state.active = conv.key; ui.renderConversations(state); @@ -300,6 +305,7 @@ document.getElementById('messageForm').addEventListener('submit', async (e) => { const res = await api.sendChat(conv.roomId || conv.name, text); msgId = res?.data?.msgId; } + // addMessage dedupes by msgId/text - see note in addMessage(). addMessage(conv.type, conv.roomId || conv.name, { from: state.screenName, text, diff --git a/public/index.html b/public/index.html index 28ac0b3..41a290e 100644 --- a/public/index.html +++ b/public/index.html @@ -4,7 +4,7 @@ Web OSCAR Chat - +
@@ -86,6 +86,6 @@
- +