Skip to content

Commit fab85ca

Browse files
committed
channel [nfc]: Provide UserStore to ChannelStore
This way, this substore becomes a valid home for methods that need to refer to data about both channels and users.
1 parent 623bcb4 commit fab85ca

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

lib/model/channel.dart

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,16 @@ import 'package:flutter/foundation.dart';
55
import '../api/model/events.dart';
66
import '../api/model/initial_snapshot.dart';
77
import '../api/model/model.dart';
8+
import 'store.dart';
9+
import 'user.dart';
810

911
/// The portion of [PerAccountStore] for channels, topics, and stuff about them.
1012
///
1113
/// This type is useful for expressing the needs of other parts of the
1214
/// implementation of [PerAccountStore], to avoid circularity.
1315
///
1416
/// The data structures described here are implemented at [ChannelStoreImpl].
15-
mixin ChannelStore {
17+
mixin ChannelStore on UserStore {
1618
/// All known channels/streams, indexed by [ZulipStream.streamId].
1719
///
1820
/// The same [ZulipStream] objects also appear in [streamsByName].
@@ -165,8 +167,11 @@ enum UserTopicVisibilityEffect {
165167
/// Generally the only code that should need this class is [PerAccountStore]
166168
/// itself. Other code accesses this functionality through [PerAccountStore],
167169
/// or through the mixin [ChannelStore] which describes its interface.
168-
class ChannelStoreImpl with ChannelStore {
169-
factory ChannelStoreImpl({required InitialSnapshot initialSnapshot}) {
170+
class ChannelStoreImpl extends HasUserStore with ChannelStore {
171+
factory ChannelStoreImpl({
172+
required UserStore users,
173+
required InitialSnapshot initialSnapshot,
174+
}) {
170175
final subscriptions = Map.fromEntries(initialSnapshot.subscriptions.map(
171176
(subscription) => MapEntry(subscription.streamId, subscription)));
172177

@@ -186,6 +191,7 @@ class ChannelStoreImpl with ChannelStore {
186191
}
187192

188193
return ChannelStoreImpl._(
194+
users: users,
189195
streams: streams,
190196
streamsByName: streams.map((_, stream) => MapEntry(stream.name, stream)),
191197
subscriptions: subscriptions,
@@ -194,6 +200,7 @@ class ChannelStoreImpl with ChannelStore {
194200
}
195201

196202
ChannelStoreImpl._({
203+
required super.users,
197204
required this.streams,
198205
required this.streamsByName,
199206
required this.subscriptions,

lib/model/store.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -482,8 +482,10 @@ class PerAccountStore extends PerAccountStoreBase with
482482
accountId: accountId,
483483
selfUserId: account.userId,
484484
);
485-
final channels = ChannelStoreImpl(initialSnapshot: initialSnapshot);
486485
final realm = RealmStoreImpl(core: core, initialSnapshot: initialSnapshot);
486+
final users = UserStoreImpl(realm: realm, initialSnapshot: initialSnapshot);
487+
final channels = ChannelStoreImpl(users: users,
488+
initialSnapshot: initialSnapshot);
487489
return PerAccountStore._(
488490
core: core,
489491
groups: UserGroupStoreImpl(core: core,
@@ -495,7 +497,7 @@ class PerAccountStore extends PerAccountStoreBase with
495497
savedSnippets: SavedSnippetStoreImpl(core: core,
496498
savedSnippets: initialSnapshot.savedSnippets ?? []),
497499
typingNotifier: TypingNotifier(realm: realm),
498-
users: UserStoreImpl(realm: realm, initialSnapshot: initialSnapshot),
500+
users: users,
499501
typingStatus: TypingStatus(realm: realm),
500502
presence: Presence(realm: realm,
501503
initial: initialSnapshot.presences),

0 commit comments

Comments
 (0)