Nexo chat — dedup message between POST response and WebSocket push

The send flow now hits two paths concurrently:

1. `POST /api/matches/:id/messages` returns the persisted message.
2. The server broadcasts `dating.message.created` to every match
   member, including the sender.

Whichever arrives first adds the message to the timeline; whoever
arrives second was supposed to detect the duplicate and skip. The
WebSocket handler already gated on `messages.some(id === incoming.id)`,
but the POST branch unconditionally appended — so when WS won the
race the POST branch produced a duplicate keyed entry and Svelte
threw `each_key_duplicate` at indexes 10/11.

Fix: the POST branch now performs the same dedup check before
appending. Whichever path lands first wins; the other no-ops. The
optimistic bubble is still removed by `clientNonce` in both paths.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
master
dev 5 months ago
parent 00b0544a46
commit 869a9b320b

@ -146,8 +146,14 @@
try {
const sent = await nexo.api.sendMessage(matchId, { body, clientNonce: nonce });
messages = [...messages, sent];
pending = pending.filter((entry) => entry.clientNonce !== nonce);
// The realtime distributor pushes this same message back —
// whichever arrives first wins; the other branch must skip
// to avoid duplicating the keyed timeline (see the WS
// subscription above).
if (!messages.some((entry) => entry.id === sent.id)) {
messages = [...messages, sent];
}
await tick();
scrollToEnd();
} catch (caught) {

Loading…
Cancel
Save

Powered by TurnKey Linux.