diff --git a/public/app.js b/public/app.js index 0927f58..15a112b 100644 --- a/public/app.js +++ b/public/app.js @@ -40,6 +40,7 @@ function ensureConversation(type, name) { } function addMessage(type, name, msg) { + if (!name || name === 'unknown') return; const conv = ensureConversation(type, name); conv.messages.push(msg); if (!state.active) state.active = conv.key; @@ -101,11 +102,21 @@ stream.on('im', (event) => { stream.on('sentIM', (event) => { const d = event.data || event.raw?.eventData || {}; if (!d.iSent) return; - const to = aimId(d.dest || {}); + let to = aimId(d.dest || d.target || {}); const text = plainText(d.message || d.text || d.msg || ''); - // Optimistic UI already added local sends; avoid obvious dup by msgId. - const conv = state.conversations[convKey('im', to)]; - if (conv && d.msgId && conv.messages.some((m) => m.msgId === d.msgId)) return; + if (!to || to === 'unknown') { + // Fallback: find conv where optimistic message was just added. + for (const c of Object.values(state.conversations)) { + if (c.type !== 'im') continue; + if (d.msgId && c.messages.some((m) => m.msgId && m.msgId === d.msgId)) { to = c.name; break; } + if (c.messages.slice(-6).some((m) => m.mine && m.text === text)) { to = c.name; break; } + } + } + if (!to || to === 'unknown') return; // can't place it safely + const key = convKey('im', to); + const conv = state.conversations[key]; + if (conv && d.msgId && conv.messages.some((m) => m.msgId && m.msgId === d.msgId)) return; + if (conv && conv.messages.slice(-6).some((m) => m.mine && m.text === text)) return; addMessage('im', to, { from: state.screenName || 'me', text, time: event.time, mine: true, msgId: d.msgId }); }); diff --git a/public/index.html b/public/index.html index 4ed3cf9..ea4abfd 100644 --- a/public/index.html +++ b/public/index.html @@ -4,7 +4,7 @@