mirror of
https://github.com/block/buzz.git
synced 2026-08-18 06:50:31 +02:00
Deduplicate staged sends on live relay echo
Route live channel overlay merges through the existing pending-message reconciliation so an authoritative echo replaces its staged row before the mutation callback completes. Co-authored-by: Carl <c7ebe626f000404285d3686e1dc74cc07cc60a9754a150041ba132e14bd3e2ec@buzz.block.builderlab.xyz> Signed-off-by: Wes <wesbillman@users.noreply.github.com>
This commit is contained in:
@@ -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,
|
||||
),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -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 = {
|
||||
|
||||
Reference in New Issue
Block a user