Skip to content

Commit 6bdbf1e

Browse files
gnpricechrisbobbe
authored andcommitted
user [nfc]: Expose UserStoreImpl.userMapFromInitialSnapshot
We'll need to pass RealmStoreImpl some details of the self-user, in order to correctly interpret (for #814) the permissions that live on RealmStore. But because UserStore already depends on RealmStore, we don't want to introduce a dependency in RealmStoreImpl on UserStore as a whole. So separate out the step that processes the user lists, and do that step in advance before constructing RealmStoreImpl.
1 parent 042e10b commit 6bdbf1e

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

lib/model/store.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,9 @@ class PerAccountStore extends PerAccountStoreBase with
482482
selfUserId: account.userId,
483483
);
484484
final realm = RealmStoreImpl(core: core, initialSnapshot: initialSnapshot);
485-
final users = UserStoreImpl(realm: realm, initialSnapshot: initialSnapshot);
485+
final userMap = UserStoreImpl.userMapFromInitialSnapshot(initialSnapshot);
486+
final users = UserStoreImpl(realm: realm, initialSnapshot: initialSnapshot,
487+
userMap: userMap);
486488
final channels = ChannelStoreImpl(users: users,
487489
initialSnapshot: initialSnapshot);
488490
return PerAccountStore._(

lib/model/user.dart

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -196,18 +196,27 @@ abstract class HasUserStore extends HasRealmStore with UserStore, ProxyUserStore
196196
/// itself. Other code accesses this functionality through [PerAccountStore],
197197
/// or through the mixin [UserStore] which describes its interface.
198198
class UserStoreImpl extends HasRealmStore with UserStore {
199+
/// Construct an implementation of [UserStore] that does the work itself.
200+
///
201+
/// The `userMap` parameter should be the result of
202+
/// [UserStoreImpl.userMapFromInitialSnapshot] applied to `initialSnapshot`.
199203
UserStoreImpl({
200204
required super.realm,
201205
required InitialSnapshot initialSnapshot,
202-
}) : _users = Map.fromEntries(
203-
initialSnapshot.realmUsers
204-
.followedBy(initialSnapshot.realmNonActiveUsers)
205-
.followedBy(initialSnapshot.crossRealmBots)
206-
.map((user) => MapEntry(user.userId, user))),
206+
required Map<int, User> userMap,
207+
}) : _users = userMap,
207208
_mutedUsers = Set.from(initialSnapshot.mutedUsers.map((item) => item.id)),
208209
_userStatuses = initialSnapshot.userStatuses.map((userId, change) =>
209210
MapEntry(userId, change.apply(UserStatus.zero)));
210211

212+
static Map<int, User> userMapFromInitialSnapshot(InitialSnapshot initialSnapshot) {
213+
return Map.fromEntries(
214+
initialSnapshot.realmUsers
215+
.followedBy(initialSnapshot.realmNonActiveUsers)
216+
.followedBy(initialSnapshot.crossRealmBots)
217+
.map((user) => MapEntry(user.userId, user)));
218+
}
219+
211220
final Map<int, User> _users;
212221

213222
@override

0 commit comments

Comments
 (0)