Skip to content

Commit 1fd0c3f

Browse files
committed
user [nfc]: Move selfUserId to UserStore
1 parent ea46825 commit 1fd0c3f

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

lib/model/store.dart

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,6 @@ class PerAccountStore extends ChangeNotifier with EmojiStore, UserStore, Channel
308308
emoji: EmojiStoreImpl(
309309
realmUrl: realmUrl, allRealmEmoji: initialSnapshot.realmEmoji),
310310
accountId: accountId,
311-
selfUserId: account.userId,
312311
userSettings: initialSnapshot.userSettings,
313312
typingNotifier: TypingNotifier(
314313
connection: connection,
@@ -317,7 +316,9 @@ class PerAccountStore extends ChangeNotifier with EmojiStore, UserStore, Channel
317316
typingStartedWaitPeriod: Duration(
318317
milliseconds: initialSnapshot.serverTypingStartedWaitPeriodMilliseconds),
319318
),
320-
users: UserStoreImpl(initialSnapshot: initialSnapshot),
319+
users: UserStoreImpl(
320+
selfUserId: account.userId,
321+
initialSnapshot: initialSnapshot),
321322
typingStatus: TypingStatus(
322323
selfUserId: account.userId,
323324
typingStartedExpiryPeriod: Duration(milliseconds: initialSnapshot.serverTypingStartedExpiryPeriodMilliseconds),
@@ -348,7 +349,6 @@ class PerAccountStore extends ChangeNotifier with EmojiStore, UserStore, Channel
348349
required this.emailAddressVisibility,
349350
required EmojiStoreImpl emoji,
350351
required this.accountId,
351-
required this.selfUserId,
352352
required this.userSettings,
353353
required this.typingNotifier,
354354
required UserStoreImpl users,
@@ -358,8 +358,7 @@ class PerAccountStore extends ChangeNotifier with EmojiStore, UserStore, Channel
358358
required this.unreads,
359359
required this.recentDmConversationsView,
360360
required this.recentSenders,
361-
}) : assert(selfUserId == globalStore.getAccount(accountId)!.userId),
362-
assert(realmUrl == globalStore.getAccount(accountId)!.realmUrl),
361+
}) : assert(realmUrl == globalStore.getAccount(accountId)!.realmUrl),
363362
assert(realmUrl == connection.realmUrl),
364363
assert(emoji.realmUrl == realmUrl),
365364
_globalStore = globalStore,
@@ -457,16 +456,16 @@ class PerAccountStore extends ChangeNotifier with EmojiStore, UserStore, Channel
457456
/// Will throw if called after [dispose] has been called.
458457
Account get account => _globalStore.getAccount(accountId)!;
459458

460-
/// Always equal to `account.userId`.
461-
final int selfUserId;
462-
463459
final UserSettings? userSettings; // TODO(server-5)
464460

465461
final TypingNotifier typingNotifier;
466462

467463
////////////////////////////////
468464
// Users and data about them.
469465

466+
@override
467+
int get selfUserId => _users.selfUserId;
468+
470469
@override
471470
Map<int, User> get users => _users.users;
472471

lib/model/user.dart

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ import 'localizations.dart';
55

66
/// The portion of [PerAccountStore] describing the users in the realm.
77
mixin UserStore {
8+
/// The user ID of the "self-user",
9+
/// i.e. the account the person using this app is logged into.
10+
///
11+
/// This always equals the [Account.userId] on [PerAccountStore.account].
12+
int get selfUserId;
13+
814
/// All known users in the realm, by [User.userId].
915
///
1016
/// There may be other users not found in this map, for multiple reasons:
@@ -41,13 +47,18 @@ mixin UserStore {
4147
/// itself. Other code accesses this functionality through [PerAccountStore],
4248
/// or through the mixin [UserStore] which describes its interface.
4349
class UserStoreImpl with UserStore {
44-
UserStoreImpl({required InitialSnapshot initialSnapshot})
45-
: users = Map.fromEntries(
50+
UserStoreImpl({
51+
required this.selfUserId,
52+
required InitialSnapshot initialSnapshot,
53+
}) : users = Map.fromEntries(
4654
initialSnapshot.realmUsers
4755
.followedBy(initialSnapshot.realmNonActiveUsers)
4856
.followedBy(initialSnapshot.crossRealmBots)
4957
.map((user) => MapEntry(user.userId, user)));
5058

59+
@override
60+
final int selfUserId;
61+
5162
@override
5263
final Map<int, User> users;
5364

0 commit comments

Comments
 (0)