Skip to content

Commit

Permalink
store: Add streamsByName mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
sirpengi committed Sep 22, 2023
1 parent a91dde3 commit e8ac5e7
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/model/store.dart
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ class PerAccountStore extends ChangeNotifier {
.map((user) => MapEntry(user.userId, user))),
streams = Map.fromEntries(initialSnapshot.streams.map(
(stream) => MapEntry(stream.streamId, stream))),
streamsByName = Map.fromEntries(initialSnapshot.streams.map(
(stream) => MapEntry(stream.name, stream))),
subscriptions = Map.fromEntries(initialSnapshot.subscriptions.map(
(subscription) => MapEntry(subscription.streamId, subscription))),
recentDmConversationsView = RecentDmConversationsView(
Expand All @@ -185,6 +187,7 @@ class PerAccountStore extends ChangeNotifier {

// Streams, topics, and stuff about them.
final Map<int, ZulipStream> streams;
final Map<String, ZulipStream> streamsByName;
final Map<int, Subscription> subscriptions;

// TODO lots more data. When adding, be sure to update handleEvent too.
Expand Down Expand Up @@ -285,13 +288,15 @@ class PerAccountStore extends ChangeNotifier {
} else if (event is StreamCreateEvent) {
assert(debugLog("server event: stream/create"));
streams.addEntries(event.streams.map((stream) => MapEntry(stream.streamId, stream)));
streamsByName.addEntries(event.streams.map((stream) => MapEntry(stream.name, stream)));
// (Don't touch `subscriptions`. If the user is subscribed to the stream,
// details will come in a later `subscription` event.)
notifyListeners();
} else if (event is StreamDeleteEvent) {
assert(debugLog("server event: stream/delete"));
for (final stream in event.streams) {
streams.remove(stream.streamId);
streamsByName.remove(stream.name);
subscriptions.remove(stream.streamId);
}
notifyListeners();
Expand Down

0 comments on commit e8ac5e7

Please sign in to comment.