Skip to content

Commit 8dc1e7a

Browse files
committed
user [nfc]: Move selfUserId to UserStore
1 parent 06be949 commit 8dc1e7a

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
@@ -279,7 +279,6 @@ class PerAccountStore extends ChangeNotifier with EmojiStore, UserStore, Channel
279279
emoji: EmojiStoreImpl(
280280
realmUrl: realmUrl, allRealmEmoji: initialSnapshot.realmEmoji),
281281
accountId: accountId,
282-
selfUserId: account.userId,
283282
userSettings: initialSnapshot.userSettings,
284283
typingNotifier: TypingNotifier(
285284
connection: connection,
@@ -288,7 +287,9 @@ class PerAccountStore extends ChangeNotifier with EmojiStore, UserStore, Channel
288287
typingStartedWaitPeriod: Duration(
289288
milliseconds: initialSnapshot.serverTypingStartedWaitPeriodMilliseconds),
290289
),
291-
users: UserStoreImpl(initialSnapshot: initialSnapshot),
290+
users: UserStoreImpl(
291+
selfUserId: account.userId,
292+
initialSnapshot: initialSnapshot),
292293
typingStatus: TypingStatus(
293294
selfUserId: account.userId,
294295
typingStartedExpiryPeriod: Duration(milliseconds: initialSnapshot.serverTypingStartedExpiryPeriodMilliseconds),
@@ -319,7 +320,6 @@ class PerAccountStore extends ChangeNotifier with EmojiStore, UserStore, Channel
319320
required this.emailAddressVisibility,
320321
required EmojiStoreImpl emoji,
321322
required this.accountId,
322-
required this.selfUserId,
323323
required this.userSettings,
324324
required this.typingNotifier,
325325
required UserStoreImpl users,
@@ -329,8 +329,7 @@ class PerAccountStore extends ChangeNotifier with EmojiStore, UserStore, Channel
329329
required this.unreads,
330330
required this.recentDmConversationsView,
331331
required this.recentSenders,
332-
}) : assert(selfUserId == globalStore.getAccount(accountId)!.userId),
333-
assert(realmUrl == globalStore.getAccount(accountId)!.realmUrl),
332+
}) : assert(realmUrl == globalStore.getAccount(accountId)!.realmUrl),
334333
assert(realmUrl == connection.realmUrl),
335334
assert(emoji.realmUrl == realmUrl),
336335
_globalStore = globalStore,
@@ -428,16 +427,16 @@ class PerAccountStore extends ChangeNotifier with EmojiStore, UserStore, Channel
428427
/// Will throw if called after [dispose] has been called.
429428
Account get account => _globalStore.getAccount(accountId)!;
430429

431-
/// Always equal to `account.userId`.
432-
final int selfUserId;
433-
434430
final UserSettings? userSettings; // TODO(server-5)
435431

436432
final TypingNotifier typingNotifier;
437433

438434
////////////////////////////////
439435
// Users and data about them.
440436

437+
@override
438+
int get selfUserId => _users.selfUserId;
439+
441440
@override
442441
Map<int, User> get users => _users.users;
443442

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)