Skip to content

Commit fa6f481

Browse files
wesbillmanPinky
andauthored
fix(desktop): retain live rows after window exhaustion (#1810)
Signed-off-by: Wes <[email protected]> Co-authored-by: Pinky <44b8e82baa6e0e254e0208d68f335c283c94e7b78dd1fa10d5a49d3f13dd0435@sprout-oss.stage.blox.sqprod.co>
1 parent af190c9 commit fa6f481

2 files changed

Lines changed: 33 additions & 3 deletions

File tree

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

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,14 +154,38 @@ test("live backdated rows stay outside pages and render in order", () => {
154154
);
155155
});
156156

157-
test("live rows below the oldest retained boundary wait for paging", () => {
157+
test("live rows below an open oldest boundary wait for paging", () => {
158158
const store = replaceNewestChannelWindow(
159159
emptyChannelWindowStore(),
160160
page(null, [event("n", 110), event("a", 100)]),
161161
);
162162
assert.equal(mergeLiveChannelWindowEvent(store, event("old", 90)), store);
163163
});
164164

165+
test("same-second live rows enter an exhausted short window regardless of id order", () => {
166+
const store = replaceNewestChannelWindow(
167+
emptyChannelWindowStore(),
168+
page(null, [event("a", 100), event("m", 100)], { hasMore: false }),
169+
);
170+
const live = event("z", 100);
171+
const withLive = mergeLiveChannelWindowEvent(store, live);
172+
173+
assert.notEqual(withLive, store);
174+
assert.deepEqual(
175+
flattenChannelWindowEvents(withLive).map((item) => item.content),
176+
["z", "m", "a"],
177+
);
178+
});
179+
180+
test("older live rows stay below an exhausted window", () => {
181+
const store = replaceNewestChannelWindow(
182+
emptyChannelWindowStore(),
183+
page(null, [event("a", 100)], { hasMore: false }),
184+
);
185+
186+
assert.equal(mergeLiveChannelWindowEvent(store, event("old", 99)), store);
187+
});
188+
165189
test("live aux stays separate from authoritative page closure", () => {
166190
const store = replaceNewestChannelWindow(
167191
emptyChannelWindowStore(),

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ export function mergeLiveThreadSummary(
178178

179179
/**
180180
* Merge a live top-level event without mutating authoritative page boundaries.
181-
* Events below the oldest loaded boundary wait for ordinary relay pagination.
181+
* Events below an open oldest boundary wait for ordinary relay pagination.
182182
*/
183183
export function mergeLiveChannelWindowEvent(
184184
current: ChannelWindowStore,
@@ -205,7 +205,13 @@ export function mergeLiveChannelWindowEvent(
205205
}
206206
const oldestPage = current.pages[current.pages.length - 1];
207207
const oldest = oldestPage?.rows[oldestPage.rows.length - 1]?.event;
208-
if (oldest && compareRelayOrder(event, oldest) >= 0) return current;
208+
if (
209+
oldest &&
210+
(event.created_at < oldest.created_at ||
211+
(oldestPage.hasMore && compareRelayOrder(event, oldest) >= 0))
212+
) {
213+
return current;
214+
}
209215
return {
210216
...current,
211217
liveOverlay: current.liveOverlay

0 commit comments

Comments
 (0)