Skip to content

Commit e8ac5e7

Browse files
committed
store: Add streamsByName mapping
1 parent a91dde3 commit e8ac5e7

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

lib/model/store.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,8 @@ class PerAccountStore extends ChangeNotifier {
161161
.map((user) => MapEntry(user.userId, user))),
162162
streams = Map.fromEntries(initialSnapshot.streams.map(
163163
(stream) => MapEntry(stream.streamId, stream))),
164+
streamsByName = Map.fromEntries(initialSnapshot.streams.map(
165+
(stream) => MapEntry(stream.name, stream))),
164166
subscriptions = Map.fromEntries(initialSnapshot.subscriptions.map(
165167
(subscription) => MapEntry(subscription.streamId, subscription))),
166168
recentDmConversationsView = RecentDmConversationsView(
@@ -185,6 +187,7 @@ class PerAccountStore extends ChangeNotifier {
185187

186188
// Streams, topics, and stuff about them.
187189
final Map<int, ZulipStream> streams;
190+
final Map<String, ZulipStream> streamsByName;
188191
final Map<int, Subscription> subscriptions;
189192

190193
// TODO lots more data. When adding, be sure to update handleEvent too.
@@ -285,13 +288,15 @@ class PerAccountStore extends ChangeNotifier {
285288
} else if (event is StreamCreateEvent) {
286289
assert(debugLog("server event: stream/create"));
287290
streams.addEntries(event.streams.map((stream) => MapEntry(stream.streamId, stream)));
291+
streamsByName.addEntries(event.streams.map((stream) => MapEntry(stream.name, stream)));
288292
// (Don't touch `subscriptions`. If the user is subscribed to the stream,
289293
// details will come in a later `subscription` event.)
290294
notifyListeners();
291295
} else if (event is StreamDeleteEvent) {
292296
assert(debugLog("server event: stream/delete"));
293297
for (final stream in event.streams) {
294298
streams.remove(stream.streamId);
299+
streamsByName.remove(stream.name);
295300
subscriptions.remove(stream.streamId);
296301
}
297302
notifyListeners();

0 commit comments

Comments
 (0)