@@ -13,9 +13,10 @@ mixin UserStore {
13
13
/// For the corresponding [User] object, see [selfUser] .
14
14
int get selfUserId;
15
15
16
- /// All known users in the realm, by [User.userId] .
16
+ /// The user with the given ID, if that user is known .
17
17
///
18
- /// There may be other users not found in this map, for multiple reasons:
18
+ /// There may be other users that are perfectly real but are
19
+ /// not known to the app, for multiple reasons:
19
20
///
20
21
/// * The self-user may not have permission to see all the users in the
21
22
/// realm, for example because the self-user is a guest.
@@ -27,33 +28,26 @@ mixin UserStore {
27
28
/// Those may therefore refer to users for which we have yet to see the
28
29
/// [RealmUserAddEvent], or have already handled a [RealmUserRemoveEvent].
29
30
///
30
- /// Code that looks up a user in this map should therefore always handle
31
+ /// Code that looks up a user here should therefore always handle
31
32
/// the possibility that the user is not found (except
32
33
/// where there is a specific reason to know the user should be found).
33
34
/// Consider using [userDisplayName] .
34
- Map <int , User > get users;
35
-
36
- /// The [User] object for the "self-user",
37
- /// i.e. the account the person using this app is logged into.
38
- ///
39
- /// When only the user ID is needed, see [selfUserId] .
40
- User get selfUser => getUser (selfUserId)! ;
41
-
42
- /// The user with the given ID, if that user is known.
43
- ///
44
- /// There may be perfectly real users that are not known,
45
- /// so callers must handle that possibility.
46
- /// For details, see [users] .
47
- User ? getUser (int userId) => users[userId];
35
+ User ? getUser (int userId);
48
36
49
37
/// All known users in the realm.
50
38
///
51
39
/// This may have a large number of elements, like tens of thousands.
52
40
/// Consider [getUser] or other alternatives to iterating through this.
53
41
///
54
42
/// There may be perfectly real users which are not known
55
- /// and so are not found here. For details, see [users] .
56
- Iterable <User > get allUsers => users.values;
43
+ /// and so are not found here. For details, see [getUser] .
44
+ Iterable <User > get allUsers;
45
+
46
+ /// The [User] object for the "self-user",
47
+ /// i.e. the account the person using this app is logged into.
48
+ ///
49
+ /// When only the user ID is needed, see [selfUserId] .
50
+ User get selfUser => getUser (selfUserId)! ;
57
51
58
52
/// The name to show the given user as in the UI, even for unknown users.
59
53
///
@@ -69,7 +63,7 @@ mixin UserStore {
69
63
70
64
/// The name to show for the given message's sender in the UI.
71
65
///
72
- /// If the user is known (see [users ] ), this is their current [User.fullName] .
66
+ /// If the user is known (see [getUser ] ), this is their current [User.fullName] .
73
67
/// If unknown, this uses the fallback value conveniently provided on the
74
68
/// [Message] object itself, namely [Message.senderFullName] .
75
69
///
@@ -90,7 +84,7 @@ class UserStoreImpl with UserStore {
90
84
UserStoreImpl ({
91
85
required this .selfUserId,
92
86
required InitialSnapshot initialSnapshot,
93
- }) : users = Map .fromEntries (
87
+ }) : _users = Map .fromEntries (
94
88
initialSnapshot.realmUsers
95
89
.followedBy (initialSnapshot.realmNonActiveUsers)
96
90
.followedBy (initialSnapshot.crossRealmBots)
@@ -99,19 +93,24 @@ class UserStoreImpl with UserStore {
99
93
@override
100
94
final int selfUserId;
101
95
96
+ final Map <int , User > _users;
97
+
98
+ @override
99
+ User ? getUser (int userId) => _users[userId];
100
+
102
101
@override
103
- final Map < int , User > users ;
102
+ Iterable < User > get allUsers => _users.values ;
104
103
105
104
void handleRealmUserEvent (RealmUserEvent event) {
106
105
switch (event) {
107
106
case RealmUserAddEvent ():
108
- users [event.person.userId] = event.person;
107
+ _users [event.person.userId] = event.person;
109
108
110
109
case RealmUserRemoveEvent ():
111
- users .remove (event.userId);
110
+ _users .remove (event.userId);
112
111
113
112
case RealmUserUpdateEvent ():
114
- final user = users [event.userId];
113
+ final user = _users [event.userId];
115
114
if (user == null ) {
116
115
return ; // TODO log
117
116
}
0 commit comments