@@ -22,13 +22,14 @@ Channel chat(String id, {bool member = true, bool archived = false}) => Channel(
2222 description: '' ,
2323 createdBy: 'owner' ,
2424 createdAt: DateTime (2026 ),
25+ lastMessageAt: DateTime .fromMillisecondsSinceEpoch (20000 ),
2526 memberCount: 2 ,
2627 isMember: member,
2728 archivedAt: archived ? DateTime (2026 ) : null ,
2829);
2930
3031class _Channels extends ChannelsNotifier {
31- final all = [
32+ var all = [
3233 chat ('solo' ),
3334 chat ('ordinary' ),
3435 chat ('archived' , archived: true ),
@@ -58,16 +59,32 @@ class _Channels extends ChannelsNotifier {
5859 };
5960 void reply () {
6061 timestamp++ ;
62+ all = [
63+ for (final c in all)
64+ c.copyWith (
65+ lastMessageAt: DateTime .fromMillisecondsSinceEpoch (timestamp * 1000 ),
66+ ),
67+ ];
6168 state = AsyncData ([...all]);
6269 }
6370}
6471
6572class _Reads extends ReadStateNotifier {
73+ final bool empty;
74+ _Reads ({this .empty = false });
75+ @override
76+ void seedContextRead (String key, int timestamp) => read (key, timestamp);
6677 @override
67- ReadStateState build () => const ReadStateState (
78+ ReadStateState build () => ReadStateState (
6879 isReady: true ,
6980 pubkey: 'owner' ,
70- contexts: {'solo' : 10 },
81+ contexts: empty ? {} : {'solo' : 10 },
82+ version: 0 ,
83+ );
84+ void resetIdentity () => state = const ReadStateState (
85+ isReady: true ,
86+ pubkey: 'other-owner' ,
87+ contexts: {},
7188 version: 0 ,
7289 );
7390 void read (String key, int timestamp) =>
@@ -90,6 +107,76 @@ const organization = MeGroups(
90107);
91108
92109void main () {
110+ for (final duringSeed in [false , true ]) {
111+ test (
112+ 'fresh Solo history is gated; new reply during seeding=$duringSeed badges' ,
113+ () async {
114+ SharedPreferences .setMockInitialValues ({});
115+ final prefs = await SharedPreferences .getInstance ();
116+ final channels = _Channels ();
117+ final reads = _Reads (empty: true );
118+ final container = ProviderContainer (
119+ overrides: [
120+ savedPrefsProvider.overrideWithValue (prefs),
121+ channelsProvider.overrideWith (() => channels),
122+ readStateProvider.overrideWith (() => reads),
123+ meGroupsProvider.overrideWith (
124+ (ref) =>
125+ Stream .value (const MeGroups (channels: ['solo' , 'ordinary' ])),
126+ ),
127+ ],
128+ );
129+ addTearDown (container.dispose);
130+ container.listen (channelsProvider, (_, _) {});
131+ container.listen (meGroupsProvider, (_, _) {});
132+ await container.read (channelsProvider.future);
133+ await container.read (meGroupsProvider.future);
134+ final observed = < Set <String >> [];
135+ container.listen (
136+ meUnreadChannelIdsProvider,
137+ (_, next) => observed.add (next),
138+ fireImmediately: true ,
139+ );
140+ expect (container.read (meUnreadChannelIdsProvider), isEmpty);
141+ if (duringSeed) {
142+ channels.reply ();
143+ expect (container.read (meUnreadChannelIdsProvider), isEmpty);
144+ }
145+ await container.pump ();
146+ expect (
147+ container.read (readStateProvider).effectiveTimestamp ('solo' ),
148+ 20 ,
149+ );
150+ if (! duringSeed) {
151+ expect (observed.every ((ids) => ids.isEmpty), isTrue);
152+ channels.reply ();
153+ }
154+ await container.pump ();
155+ expect (container.read (meUnreadChannelIdsProvider), {
156+ 'solo' ,
157+ 'ordinary' ,
158+ });
159+ expect (
160+ container.read (readStateProvider).effectiveTimestamp ('solo' ),
161+ 20 ,
162+ );
163+ reads.resetIdentity ();
164+ expect (container.read (meUnreadChannelIdsProvider), isEmpty);
165+ await container.pump ();
166+ expect (
167+ container.read (readStateProvider).effectiveTimestamp ('solo' ),
168+ 21 ,
169+ );
170+ expect (container.read (meUnreadChannelIdsProvider), isEmpty);
171+ channels.reply ();
172+ await container.pump ();
173+ expect (container.read (meUnreadChannelIdsProvider), {
174+ 'solo' ,
175+ 'ordinary' ,
176+ });
177+ },
178+ );
179+ }
93180 testWidgets (
94181 'Solo retains live unread row, collapsed section, and tab indication' ,
95182 (tester) async {
0 commit comments