@@ -11,6 +11,37 @@ import 'package:buzz/features/channels/timeline_message.dart';
1111import 'package:buzz/shared/relay/relay.dart';
1212
1313void main() {
14+ test('live window without deep links does not rescan flattened ids', () async {
15+ var historyIdReads = 0;
16+ final history = _IdReadTrackingEvent(
17+ _event(id: 'history', createdAt: 10),
18+ onIdRead: () => historyIdReads++,
19+ );
20+ final relaySession = _RecordingRelaySessionNotifier(
21+ queryResults: [
22+ [history, _bounds()],
23+ ],
24+ );
25+ final container = _buildContainer(relaySession);
26+ addTearDown(container.dispose);
27+ container.read(channelMessagesProvider(_channelId));
28+ await relaySession.subscribed;
29+ await _pumpEventQueue();
30+
31+ historyIdReads = 0;
32+ relaySession.emit(_event(id: 'live', createdAt: 20));
33+
34+ // One read checks page membership; one builds the flattened window. The
35+ // distinct timestamps need no id tie-break when sorting. A redundant
36+ // deep-link merge would read the historical id a third time to build its
37+ // dedup set. Allow fewer reads if either required pass is optimized later.
38+ expect(historyIdReads, lessThanOrEqualTo(2));
39+ expect(
40+ container.read(channelMessagesProvider(_channelId)).value!.length,
41+ 2,
42+ );
43+ });
44+
1445 for (final retainDeepLink in [false, true]) {
1546 test(
1647 'live window keeps chronological order with retained deep link: $retainDeepLink',
@@ -1035,6 +1066,27 @@ void main() {
10351066
10361067const _channelId = '11111111-1111-4111-8111-111111111111';
10371068
1069+ class _IdReadTrackingEvent extends NostrEvent {
1070+ final void Function() onIdRead;
1071+
1072+ _IdReadTrackingEvent(NostrEvent event, {required this.onIdRead})
1073+ : super(
1074+ id: event.id,
1075+ pubkey: event.pubkey,
1076+ createdAt: event.createdAt,
1077+ kind: event.kind,
1078+ tags: event.tags,
1079+ content: event.content,
1080+ sig: event.sig,
1081+ );
1082+
1083+ @override
1084+ String get id {
1085+ onIdRead();
1086+ return super.id;
1087+ }
1088+ }
1089+
10381090ProviderContainer _buildContainer(_RecordingRelaySessionNotifier relaySession) {
10391091 return ProviderContainer(
10401092 overrides: [relaySessionProvider.overrideWith(() => relaySession)],
0 commit comments