Skip to content

Commit 9a533a9

Browse files
npub12gtutshhh76rx0jx697f32f9tffd4hhp3hx58fp4x6u4uemkm7sqf8f757Tyler Longwell
andcommitted
fix(desktop): close live channel window gaps
Keep depth-one broadcast replies in both their thread cache and the main timeline live overlay, matching the relay-owned channel-row classification. When pagination acquires a live-overlay row, transfer ownership to the authoritative page. Establish the live subscription before a final page-zero refresh so events during the original fetch cannot fall between history and live delivery. Co-authored-by: Tyler Longwell <[email protected]> Signed-off-by: Tyler Longwell <[email protected]>
1 parent f2a551f commit 9a533a9

3 files changed

Lines changed: 46 additions & 4 deletions

File tree

‎desktop/src/features/messages/hooks.ts‎

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
buildReplyTags,
1414
getChannelIdFromTags,
1515
getThreadReference,
16+
isBroadcastReply,
1617
normalizeMentionPubkeys,
1718
resolveReplyRootId,
1819
} from "@/features/messages/lib/threading";
@@ -296,15 +297,18 @@ export function useChannelSubscription(channel: Channel | null) {
296297
const appendMessage = useEffectEvent((event: RelayEvent) => {
297298
if (!channelId) return;
298299
const isTimelineRow = CHANNEL_TIMELINE_KINDS.has(event.kind);
299-
if (isTimelineRow && getThreadReference(event.tags).parentId !== null) {
300-
const rootId = getThreadReference(event.tags).rootId;
300+
const threadReference = isTimelineRow
301+
? getThreadReference(event.tags)
302+
: null;
303+
if (threadReference?.parentId != null) {
304+
const rootId = threadReference?.rootId;
301305
if (rootId) {
302306
queryClient.setQueryData<RelayEvent[]>(
303307
threadRepliesKey(channelId, rootId),
304308
(current = []) => mergeMessages(current, event),
305309
);
306310
}
307-
return;
311+
if (!isBroadcastReply(event.tags)) return;
308312
}
309313
if (!isTimelineRow && !CHANNEL_AUX_KINDS.has(event.kind)) return;
310314
if (!isTimelineRow) {
@@ -381,6 +385,15 @@ export function useChannelSubscription(channel: Channel | null) {
381385
}
382386

383387
cleanup = dispose;
388+
void refreshNewestWindow().catch((error) => {
389+
if (!isDisposed) {
390+
console.error(
391+
"Failed to refresh channel window after subscribing",
392+
channelId,
393+
error,
394+
);
395+
}
396+
});
384397
})
385398
.catch((error) => {
386399
console.error("Failed to subscribe to channel", channelId, error);

‎desktop/src/features/messages/lib/channelWindowStore.test.mjs‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,30 @@ test("authoritative refresh reconciles duplicate live rows", () => {
193193
);
194194
});
195195

196+
test("older-page append reconciles a live row pushed below page zero", () => {
197+
const initial = replaceNewestChannelWindow(
198+
emptyChannelWindowStore(),
199+
page(null, [event("a", 100)]),
200+
);
201+
const live = event("n", 110);
202+
const withLive = mergeLiveChannelWindowEvent(initial, live);
203+
const refreshed = replaceNewestChannelWindow(
204+
withLive,
205+
page(null, [event("newer", 120)]),
206+
);
207+
const reconciled = appendOlderChannelWindow(
208+
refreshed,
209+
page(refreshed.pages[0].nextCursor, [live], { hasMore: false }),
210+
);
211+
212+
assert.deepEqual(reconciled.liveOverlay, []);
213+
assert.equal(
214+
flattenChannelWindowEvents(reconciled).filter((item) => item.id === live.id)
215+
.length,
216+
1,
217+
);
218+
});
219+
196220
test("flattening dedupes aux closure events returned on adjacent pages", () => {
197221
const deletion = event("d", 120, 5);
198222
const first = page(null, [event("a", 100)], { aux: [deletion] });

‎desktop/src/features/messages/lib/channelWindowStore.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,12 @@ export function appendOlderChannelWindow(
132132
throw new Error(`Channel row ${row.event.id} overlaps a retained page.`);
133133
}
134134
}
135-
return { ...current, pages: [...current.pages, page] };
135+
const pageIds = new Set(page.rows.map((row) => row.event.id));
136+
return {
137+
...current,
138+
pages: [...current.pages, page],
139+
liveOverlay: current.liveOverlay.filter((event) => !pageIds.has(event.id)),
140+
};
136141
}
137142

138143
/**

0 commit comments

Comments
 (0)