Skip to content

Commit ffa2d32

Browse files
committed
unread [nfc]: Give Unreads a reference to StreamStore
1 parent f8f88fe commit ffa2d32

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

lib/model/store.dart

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ class PerAccountStore extends ChangeNotifier with StreamStore {
153153
required ApiConnection connection,
154154
required InitialSnapshot initialSnapshot,
155155
}) {
156+
final streams = StreamStoreImpl(initialSnapshot: initialSnapshot);
156157
return PerAccountStore._(
157158
account: account,
158159
connection: connection,
@@ -162,13 +163,17 @@ class PerAccountStore extends ChangeNotifier with StreamStore {
162163
realmEmoji: initialSnapshot.realmEmoji,
163164
customProfileFields: _sortCustomProfileFields(initialSnapshot.customProfileFields),
164165
userSettings: initialSnapshot.userSettings,
165-
unreads: Unreads(initial: initialSnapshot.unreadMsgs, selfUserId: account.userId),
166+
unreads: Unreads(
167+
initial: initialSnapshot.unreadMsgs,
168+
selfUserId: account.userId,
169+
streamStore: streams,
170+
),
166171
users: Map.fromEntries(
167172
initialSnapshot.realmUsers
168173
.followedBy(initialSnapshot.realmNonActiveUsers)
169174
.followedBy(initialSnapshot.crossRealmBots)
170175
.map((user) => MapEntry(user.userId, user))),
171-
streams: StreamStoreImpl(initialSnapshot: initialSnapshot),
176+
streams: streams,
172177
recentDmConversationsView: RecentDmConversationsView(
173178
initial: initialSnapshot.recentPrivateConversations, selfUserId: account.userId),
174179
);

lib/model/unreads.dart

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import '../api/model/events.dart';
99
import '../log.dart';
1010
import 'algorithms.dart';
1111
import 'narrow.dart';
12+
import 'stream.dart';
1213

1314
/// The view-model for unread messages.
1415
///
@@ -39,7 +40,11 @@ import 'narrow.dart';
3940
// TODO When loading a message list with stream messages, check all the stream
4041
// messages and refresh [mentions] (see [mentions] dartdoc).
4142
class Unreads extends ChangeNotifier {
42-
factory Unreads({required UnreadMessagesSnapshot initial, required selfUserId}) {
43+
factory Unreads({
44+
required UnreadMessagesSnapshot initial,
45+
required selfUserId,
46+
required StreamStore streamStore,
47+
}) {
4348
final streams = <int, Map<String, QueueList<int>>>{};
4449
final dms = <DmNarrow, QueueList<int>>{};
4550
final mentions = Set.of(initial.mentions);
@@ -62,6 +67,7 @@ class Unreads extends ChangeNotifier {
6267
}
6368

6469
return Unreads._(
70+
streamStore: streamStore,
6571
streams: streams,
6672
dms: dms,
6773
mentions: mentions,
@@ -71,13 +77,16 @@ class Unreads extends ChangeNotifier {
7177
}
7278

7379
Unreads._({
80+
required this.streamStore,
7481
required this.streams,
7582
required this.dms,
7683
required this.mentions,
7784
required this.oldUnreadsMissing,
7885
required this.selfUserId,
7986
});
8087

88+
final StreamStore streamStore;
89+
8190
// TODO excluded for now; would need to handle nuances around muting etc.
8291
// int count;
8392

test/model/unreads_test.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import 'package:zulip/api/model/events.dart';
55
import 'package:zulip/api/model/initial_snapshot.dart';
66
import 'package:zulip/api/model/model.dart';
77
import 'package:zulip/model/narrow.dart';
8+
import 'package:zulip/model/store.dart';
89
import 'package:zulip/model/unreads.dart';
910

1011
import '../example_data.dart' as eg;
@@ -14,6 +15,7 @@ void main() {
1415
// These variables are the common state operated on by each test.
1516
// Each test case calls [prepare] to initialize them.
1617
late Unreads model;
18+
late PerAccountStore streamStore; // TODO reduce this to StreamStore
1719
late int notifiedCount;
1820

1921
void checkNotified({required int count}) {
@@ -34,8 +36,10 @@ void main() {
3436
oldUnreadsMissing: false,
3537
),
3638
}) {
39+
streamStore = eg.store();
3740
notifiedCount = 0;
38-
model = Unreads(initial: initial, selfUserId: eg.selfUser.userId)
41+
model = Unreads(initial: initial,
42+
selfUserId: eg.selfUser.userId, streamStore: streamStore)
3943
..addListener(() {
4044
notifiedCount++;
4145
});

0 commit comments

Comments
 (0)