diff --git a/desktop/src/features/messages/lib/messageQueryKeys.ts b/desktop/src/features/messages/lib/messageQueryKeys.ts index 94a04d6b9a..29864f5de7 100644 --- a/desktop/src/features/messages/lib/messageQueryKeys.ts +++ b/desktop/src/features/messages/lib/messageQueryKeys.ts @@ -50,7 +50,7 @@ export function sortMessages(messages: RelayEvent[]) { }); } -function isTimelineWindowContentEvent(event: RelayEvent) { +export function isTimelineWindowContentEvent(event: RelayEvent) { return ( event.kind === KIND_STREAM_MESSAGE || event.kind === KIND_STREAM_MESSAGE_V2 || diff --git a/desktop/src/features/messages/lib/pageOlderMessages.test.mjs b/desktop/src/features/messages/lib/pageOlderMessages.test.mjs index 512989568d..ee0e1775c2 100644 --- a/desktop/src/features/messages/lib/pageOlderMessages.test.mjs +++ b/desktop/src/features/messages/lib/pageOlderMessages.test.mjs @@ -1,7 +1,10 @@ import assert from "node:assert/strict"; import test from "node:test"; -import { pageOlderMessagesUntilRowFloor } from "./pageOlderMessages.ts"; +import { + maxEventIdAtSecond, + pageOlderMessagesUntilRowFloor, +} from "./pageOlderMessages.ts"; import { channelMessagesKey, mergeNonContiguousTimelineMessages, @@ -178,3 +181,39 @@ test("late island response never downgrades a contiguous copy (downgrade race)", // And the reverse direction: thread replies already contiguous stay put. assert.equal(merged.length, cache.length); }); + +test("dense-second seed ignores aux and island ids at the boundary second", () => { + const channelId = "dense-second-seed"; + const second = 7_000; + // Two content events already held at the stalled second... + const contentA = event({ id: id("caa", 0), createdAt: second, channelId }); + const contentB = event({ id: id("cbb", 0), createdAt: second, channelId }); + // ...an unmarked reaction whose id sorts after both (aux kinds are absent + // from the bridge keyset pages, so its id proves nothing about content)... + const auxLater = event({ + id: id("zaux", 0), + kind: 7, + createdAt: second, + channelId, + tags: [ + ["h", channelId], + ["e", contentA.id], + ], + }); + // ...and a marked island whose id sorts after everything. + const islandLater = { + ...event({ id: id("zisl", 0), createdAt: second, channelId }), + nonContiguous: true, + }; + + const seed = maxEventIdAtSecond( + [contentA, contentB, auxLater, islandLater], + second, + ); + + // Seeding from the aux/island id would tell the relay "everything up to + // this id is held" and skip unseen content rows in the same second. + assert.equal(seed, contentB.id); + // No contiguous content at the second -> no fabricated cursor. + assert.equal(maxEventIdAtSecond([auxLater, islandLater], second), null); +}); diff --git a/desktop/src/features/messages/lib/pageOlderMessages.ts b/desktop/src/features/messages/lib/pageOlderMessages.ts index d075592e58..66dd5122ee 100644 --- a/desktop/src/features/messages/lib/pageOlderMessages.ts +++ b/desktop/src/features/messages/lib/pageOlderMessages.ts @@ -4,6 +4,7 @@ import { countTopLevelTimelineRows } from "@/features/messages/lib/formatTimelin import { backfillAuxForMessages } from "@/features/messages/lib/auxBackfill"; import { channelMessagesKey, + isTimelineWindowContentEvent, mergeTimelineHistoryMessages, oldestContiguousHistoryTimestamp, } from "@/features/messages/lib/messageQueryKeys"; @@ -49,15 +50,24 @@ const inFlightPasses = new Map>(); * Non-contiguous events are excluded: an out-of-band island at the boundary * second is a *point*, not proof that everything up to its id is held — * seeding past it would skip the unfetched rows before it. The island itself - * just dedupes away when re-fetched. + * just dedupes away when re-fetched. Auxiliary events are excluded for the + * same reason: the bridge keyset pages timeline-content kinds only, so an aux + * id at the boundary second says nothing about which *content* rows are held + * — seeding from a later aux id would skip unseen content in that second. + * + * Exported for tests only — the pager is the sole runtime caller. */ -function maxEventIdAtSecond( +export function maxEventIdAtSecond( events: RelayEvent[], second: number, ): string | null { let maxId: string | null = null; for (const event of events) { - if (event.created_at !== second || event.nonContiguous) { + if ( + event.created_at !== second || + event.nonContiguous || + !isTimelineWindowContentEvent(event) + ) { continue; } if (maxId === null || event.id > maxId) {