From 1f4516d69b4a81de3ac021e0c8c9590245e99909 Mon Sep 17 00:00:00 2001 From: sravan Date: Tue, 23 Jun 2026 18:06:00 +0530 Subject: [PATCH] fix(chat): dedup own echoed message so sent messages don't show twice Server echoes your own message back over WS (multi-tab/device sync) and sendMessage already appended it optimistically; onChatMessage now skips the append if the id is already in the thread. Co-Authored-By: Claude Opus 4.8 --- server/public/home.html | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/server/public/home.html b/server/public/home.html index a52f542..fdad267 100644 --- a/server/public/home.html +++ b/server/public/home.html @@ -1519,7 +1519,9 @@ function onChatMessage(m){ if(m.from!==ME.id && !isOpen && !isSys) it.unread=(it.unread||0)+1; } if(isOpen){ - THREAD.push(m); appendBubble(m); + // Dedup by id: the server echoes our own sent message back (multi-tab/device sync), and + // sendMessage already appended it optimistically — so skip if it's already in the thread. + if(!THREAD.some(x=>x.id===m.id)){ THREAD.push(m); appendBubble(m); } if(m.from!==ME.id && !isSys){ if(it) it.unread=0; const body=JSON.stringify(kind==='group'?{group:rid}:{with:rid}); try{ fetch('/api/messages/read',{method:'POST',headers:{'Content-Type':'application/json'},body}); }catch(_){} } } else if(m.from!==ME.id && !isSys && notifOn(kind)){ toast((m.fromName||'New message')+': '+(m.body?(m.body.length>60?m.body.slice(0,60)+'…':m.body):'📎 Attachment'));