Fix IM sentIM unknown-dest splitting into unknown tab
This commit is contained in:
parent
87fd5569db
commit
187a5771c4
2 changed files with 17 additions and 6 deletions
|
|
@ -40,6 +40,7 @@ function ensureConversation(type, name) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function addMessage(type, name, msg) {
|
function addMessage(type, name, msg) {
|
||||||
|
if (!name || name === 'unknown') return;
|
||||||
const conv = ensureConversation(type, name);
|
const conv = ensureConversation(type, name);
|
||||||
conv.messages.push(msg);
|
conv.messages.push(msg);
|
||||||
if (!state.active) state.active = conv.key;
|
if (!state.active) state.active = conv.key;
|
||||||
|
|
@ -101,11 +102,21 @@ stream.on('im', (event) => {
|
||||||
stream.on('sentIM', (event) => {
|
stream.on('sentIM', (event) => {
|
||||||
const d = event.data || event.raw?.eventData || {};
|
const d = event.data || event.raw?.eventData || {};
|
||||||
if (!d.iSent) return;
|
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 || '');
|
const text = plainText(d.message || d.text || d.msg || '');
|
||||||
// Optimistic UI already added local sends; avoid obvious dup by msgId.
|
if (!to || to === 'unknown') {
|
||||||
const conv = state.conversations[convKey('im', to)];
|
// Fallback: find conv where optimistic message was just added.
|
||||||
if (conv && d.msgId && conv.messages.some((m) => m.msgId === d.msgId)) return;
|
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 });
|
addMessage('im', to, { from: state.screenName || 'me', text, time: event.time, mine: true, msgId: d.msgId });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
<title>Web OSCAR Chat</title>
|
<title>Web OSCAR Chat</title>
|
||||||
<link rel="stylesheet" href="/style.css?v=16">
|
<link rel="stylesheet" href="/style.css?v=17">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="app">
|
<div id="app">
|
||||||
|
|
@ -87,6 +87,6 @@
|
||||||
</main>
|
</main>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script type="module" src="/app.js?v=16"></script>
|
<script type="module" src="/app.js?v=17"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue