-
Notifications
You must be signed in to change notification settings - Fork 309
Muted users prep #1530
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Muted users prep #1530
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,6 +66,12 @@ mixin UserStore on PerAccountStoreBase { | |
return getUser(message.senderId)?.fullName | ||
?? message.senderFullName; | ||
} | ||
|
||
/// Whether the user with [userId] is muted by the self-user. | ||
/// | ||
/// Looks for [userId] in a private [Set], | ||
/// or in [event.mutedUsers] instead if event is non-null. | ||
bool isUserMuted(int userId, {MutedUsersEvent? event}); | ||
} | ||
|
||
/// The implementation of [UserStore] that does the work. | ||
|
@@ -81,7 +87,8 @@ class UserStoreImpl extends PerAccountStoreBase with UserStore { | |
initialSnapshot.realmUsers | ||
.followedBy(initialSnapshot.realmNonActiveUsers) | ||
.followedBy(initialSnapshot.crossRealmBots) | ||
.map((user) => MapEntry(user.userId, user))); | ||
.map((user) => MapEntry(user.userId, user))), | ||
_mutedUsers = Set.from(initialSnapshot.mutedUsers.map((item) => item.id)); | ||
|
||
final Map<int, User> _users; | ||
|
||
|
@@ -91,6 +98,13 @@ class UserStoreImpl extends PerAccountStoreBase with UserStore { | |
@override | ||
Iterable<User> get allUsers => _users.values; | ||
|
||
final Set<int> _mutedUsers; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yeah, looks good. If we later feel that seeing the whole Set would be really helpful for testing, we can add a getter like Iterable<int> debugMutedUsers => _mutedUsers; and tests can compare using |
||
|
||
@override | ||
bool isUserMuted(int userId, {MutedUsersEvent? event}) { | ||
return (event?.mutedUsers.map((item) => item.id) ?? _mutedUsers).contains(userId); | ||
} | ||
|
||
void handleRealmUserEvent(RealmUserEvent event) { | ||
switch (event) { | ||
case RealmUserAddEvent(): | ||
|
@@ -129,4 +143,9 @@ class UserStoreImpl extends PerAccountStoreBase with UserStore { | |
} | ||
} | ||
} | ||
|
||
void handleMutedUsersEvent(MutedUsersEvent event) { | ||
_mutedUsers.clear(); | ||
_mutedUsers.addAll(event.mutedUsers.map((item) => item.id)); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool, this is good.
In #1530 (comment) I actually only meant to suggest removing the timestamps from the model, not the API binding. Removing them from the API binding is fine too, but definitely should have this comment as Chris's commit message says: