1
1
import '../api/model/events.dart' ;
2
2
import '../api/model/initial_snapshot.dart' ;
3
3
import '../api/model/model.dart' ;
4
+ import 'algorithms.dart' ;
4
5
import 'localizations.dart' ;
5
6
import 'store.dart' ;
6
7
@@ -66,6 +67,9 @@ mixin UserStore on PerAccountStoreBase {
66
67
return getUser (message.senderId)? .fullName
67
68
?? message.senderFullName;
68
69
}
70
+
71
+ /// Whether the user with the given [id] is muted by [selfUser] .
72
+ bool isUserMuted (int id);
69
73
}
70
74
71
75
/// The implementation of [UserStore] that does the work.
@@ -81,16 +85,32 @@ class UserStoreImpl extends PerAccountStoreBase with UserStore {
81
85
initialSnapshot.realmUsers
82
86
.followedBy (initialSnapshot.realmNonActiveUsers)
83
87
.followedBy (initialSnapshot.crossRealmBots)
84
- .map ((user) => MapEntry (user.userId, user)));
88
+ .map ((user) => MapEntry (user.userId, user))),
89
+ _mutedUsers = initialSnapshot.mutedUsers,
90
+ _mutedUsersSorted = initialSnapshot.mutedUsers
91
+ ..sort ((a, b) => a.id.compareTo (b.id));
85
92
86
93
final Map <int , User > _users;
87
94
95
+ // Currently we don't need this, but we would need it if we wanted to display
96
+ // muted users in the order of server.
97
+ // ignore: unused_field
98
+ final List <MutedUserItem > _mutedUsers;
99
+
100
+ final List <MutedUserItem > _mutedUsersSorted;
101
+
88
102
@override
89
103
User ? getUser (int userId) => _users[userId];
90
104
91
105
@override
92
106
Iterable <User > get allUsers => _users.values;
93
107
108
+ @override
109
+ bool isUserMuted (int id) {
110
+ return binarySearchByKey (_mutedUsersSorted, id,
111
+ (item, id) => item.id.compareTo (id)) >= 0 ;
112
+ }
113
+
94
114
void handleRealmUserEvent (RealmUserEvent event) {
95
115
switch (event) {
96
116
case RealmUserAddEvent ():
0 commit comments