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 <noreply@anthropic.com>
This commit is contained in:
@@ -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'));
|
||||
|
||||
Reference in New Issue
Block a user