diff --git a/desktop/src/features/messages/lib/channelWindowStore.ts b/desktop/src/features/messages/lib/channelWindowStore.ts index 1bd921aab..4929422ce 100644 --- a/desktop/src/features/messages/lib/channelWindowStore.ts +++ b/desktop/src/features/messages/lib/channelWindowStore.ts @@ -1,4 +1,5 @@ import type { RelayEvent } from "@/shared/api/types"; +import { reconcileIncomingMessage } from "./messageMerge"; export type ChannelWindowCursor = { createdAt: number; eventId: string }; export type ChannelWindowThreadSummary = { @@ -214,10 +215,9 @@ export function mergeLiveChannelWindowEvent( } return { ...current, - liveOverlay: current.liveOverlay - .filter((candidate) => candidate.id !== event.id) - .concat(event) - .sort(compareRelayOrder), + liveOverlay: reconcileIncomingMessage(current.liveOverlay, event).sort( + compareRelayOrder, + ), }; } diff --git a/desktop/src/features/messages/lib/projectChannelWindow.test.mjs b/desktop/src/features/messages/lib/projectChannelWindow.test.mjs index f207777bd..4209e6ec2 100644 --- a/desktop/src/features/messages/lib/projectChannelWindow.test.mjs +++ b/desktop/src/features/messages/lib/projectChannelWindow.test.mjs @@ -213,6 +213,31 @@ test("test_reconciliation_preserves_dense_second_window_order", () => { ); }); +test("test_live_echo_replaces_matching_staged_send", () => { + const harness = createHarness(); + const pending = { + ...event("pending", 110), + content: "hello", + pending: true, + }; + const accepted = { + ...event("accepted", 110), + content: "hello", + id: "c".repeat(64), + }; + appendLiveEvent(harness, pending); + appendLiveEvent(harness, accepted); + + assert.deepEqual( + harness.client.getQueryData(harness.messagesKey).map((item) => item.id), + [event("initial", 100).id, accepted.id], + ); + assert.equal( + harness.client.getQueryData(harness.messagesKey)[1]?.localKey, + pending.id, + ); +}); + test("test_reconciliation_retains_identical_pending_sends", () => { const harness = createHarness(); const first = {