Skip to content

Commit 9928882

Browse files
committed
fix(mobile): reconcile live summaries after zero-reply pages
Signed-off-by: Tom Brow <[email protected]>
1 parent 7ac39d1 commit 9928882

2 files changed

Lines changed: 87 additions & 2 deletions

File tree

‎mobile/lib/features/channels/channel_messages_provider/thread_summaries.dart‎

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,28 @@ extension _ThreadSummaryState on ChannelMessagesNotifier {
8181
bool _hasVisibleThreadRows(String root) =>
8282
_isVisibleRoot(root) || _visibleNestedRows(root).isNotEmpty;
8383

84+
ChannelWindowThreadSummary? _emptyPageSummary(String root) {
85+
// A page's implicit zero is no longer the only evidence once replies arrive.
86+
if (cachedThreadReplyIds(root).isNotEmpty) return null;
87+
for (final page in _windowStore.pages) {
88+
for (final row in page.rows) {
89+
if (row.event.id != root) continue;
90+
if (row.thread != null) return null;
91+
return const ChannelWindowThreadSummary(
92+
replyCount: 0,
93+
descendantCount: 0,
94+
lastReplyAt: null,
95+
participantPubkeys: [],
96+
);
97+
}
98+
}
99+
return null;
100+
}
101+
84102
void _applyLiveThreadSummary(NostrEvent event, int? summaryVersion) {
85103
final root = event.getTagValue('e');
86104
if (root == null) return;
87-
final exact = _queryThreadSummaries[root];
105+
final exact = _queryThreadSummaries[root] ?? _emptyPageSummary(root);
88106
if (summaryVersion == null && exact != null) {
89107
// WebSocket arrival order cannot establish freshness relative to HTTP
90108
// scans. Preserve the completed scan and reconcile conflicting counts.

‎mobile/test/features/channels/channel_messages_provider_test.dart‎

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,11 @@ void main() {
506506
() async {
507507
final relaySession = _RecordingRelaySessionNotifier(
508508
queryResults: [
509-
[_event(id: 'root', createdAt: 10), _bounds()],
509+
[
510+
_event(id: 'root', createdAt: 10),
511+
_summary(rootId: 'root', replyCount: 1),
512+
_bounds(),
513+
],
510514
],
511515
);
512516
final container = _buildContainer(relaySession);
@@ -4314,6 +4318,69 @@ void main() {
43144318
);
43154319
}
43164320

4321+
for (final newReplyExists in [false, true]) {
4322+
test(
4323+
'live summary after empty older page is reconciled (new reply: $newReplyExists)',
4324+
() async {
4325+
final recount = Completer<List<NostrEvent>>();
4326+
final session = _RecordingRelaySessionNotifier(
4327+
queryResults: [
4328+
[
4329+
_event(id: 'newest', createdAt: 100),
4330+
_bounds(hasMore: true, cursorCreatedAt: 100, cursorId: 'newest'),
4331+
],
4332+
[
4333+
_event(id: 'root', createdAt: 10),
4334+
_bounds(dTag: '${_channelId.toLowerCase()}:100:newest'),
4335+
],
4336+
recount.future,
4337+
],
4338+
);
4339+
final container = _buildContainer(session);
4340+
addTearDown(container.dispose);
4341+
container.listen(channelMessagesProvider(_channelId), (_, _) {});
4342+
await _pumpEventQueue();
4343+
final notifier = container.read(
4344+
channelMessagesProvider(_channelId).notifier,
4345+
);
4346+
expect(await notifier.fetchOlder(), isTrue);
4347+
session.emit(_summary(rootId: 'root', replyCount: 1));
4348+
expect(notifier.threadSummaries['root']!.descendantCount, 0);
4349+
await Future<void>.delayed(const Duration(milliseconds: 300));
4350+
expect(
4351+
session.queryFilters.where(
4352+
(f) => f.extensions.containsKey('depth_limit'),
4353+
),
4354+
hasLength(1),
4355+
);
4356+
recount.complete([
4357+
if (newReplyExists)
4358+
_event(
4359+
id: 'new-reply',
4360+
createdAt: 30,
4361+
extraTags: const [
4362+
['e', 'root', '', 'reply'],
4363+
],
4364+
),
4365+
]);
4366+
await _pumpEventQueue();
4367+
final entries = buildMainTimelineEntries(
4368+
formatTimeline(
4369+
container.read(channelMessagesProvider(_channelId)).value!,
4370+
),
4371+
relaySummaries: notifier.threadSummaries,
4372+
);
4373+
expect(
4374+
entries
4375+
.singleWhere((e) => e.message.id == 'root')
4376+
.summary
4377+
?.replyCount,
4378+
newReplyExists ? 1 : null,
4379+
);
4380+
},
4381+
);
4382+
}
4383+
43174384
for (final newReplyExists in [false, true]) {
43184385
test(
43194386
'live summary after empty scan is reconciled (new reply: $newReplyExists)',

0 commit comments

Comments
 (0)