-
Notifications
You must be signed in to change notification settings - Fork 349
Mute muted users (Chris's revision, 2 of 2) #1561
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
d4d9711
recent-dms: Exclude DM conversations where all other recipients are m…
chrisbobbe c403608
msglist [nfc]: Place `_allMessagesVisible` right after `_messageVisible`
sm-sayedi ca03731
msglist [nfc]: s/VisibilityEffect/UserTopicVisibilityEffect/
chrisbobbe f7aff19
msglist: Exclude DMs if recipients muted (combined/mentions/starred/s…
chrisbobbe 9815022
autocomplete: Exclude muted users from user-mention autocomplete
chrisbobbe eebd1ed
msglist [nfc]: Use `const` to avoid making new lists for nobody-is-ty…
chrisbobbe fcc2c8b
msglist: Exclude muted users from typing-status text
chrisbobbe cc87e0c
new-dm: Exclude muted users
chrisbobbe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,6 +13,7 @@ import 'content.dart'; | |
| import 'message.dart'; | ||
| import 'narrow.dart'; | ||
| import 'store.dart'; | ||
| import 'user.dart'; | ||
|
|
||
| export '../api/route/messages.dart' show Anchor, AnchorCode, NumericAnchor; | ||
|
|
||
|
|
@@ -668,10 +669,12 @@ class MessageListView with ChangeNotifier, _MessageSequence { | |
| bool _messageVisible(MessageBase message) { | ||
| switch (narrow) { | ||
| case CombinedFeedNarrow(): | ||
| return switch (message.conversation) { | ||
| final conversation = message.conversation; | ||
| return switch (conversation) { | ||
| StreamConversation(:final streamId, :final topic) => | ||
| store.isTopicVisible(streamId, topic), | ||
| DmConversation() => true, | ||
| DmConversation() => !store.shouldMuteDmConversation( | ||
| DmNarrow.ofConversation(conversation, selfUserId: store.selfUserId)), | ||
| }; | ||
|
|
||
| case ChannelNarrow(:final streamId): | ||
|
|
@@ -682,48 +685,75 @@ class MessageListView with ChangeNotifier, _MessageSequence { | |
|
|
||
| case TopicNarrow(): | ||
| case DmNarrow(): | ||
| return true; | ||
|
|
||
| case MentionsNarrow(): | ||
| case StarredMessagesNarrow(): | ||
| case KeywordSearchNarrow(): | ||
| if (message.conversation case DmConversation(:final allRecipientIds)) { | ||
| return !store.shouldMuteDmConversation(DmNarrow( | ||
| allRecipientIds: allRecipientIds, selfUserId: store.selfUserId)); | ||
| } | ||
| return true; | ||
| } | ||
| } | ||
|
|
||
| /// Whether [_messageVisible] is true for all possible messages. | ||
| /// | ||
| /// This is useful for an optimization. | ||
| bool get _allMessagesVisible { | ||
| switch (narrow) { | ||
| case CombinedFeedNarrow(): | ||
| case ChannelNarrow(): | ||
| return false; | ||
|
|
||
| case TopicNarrow(): | ||
| case DmNarrow(): | ||
| return true; | ||
|
|
||
| case MentionsNarrow(): | ||
| case StarredMessagesNarrow(): | ||
| case KeywordSearchNarrow(): | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| /// Whether this event could affect the result that [_messageVisible] | ||
| /// would ever have returned for any possible message in this message list. | ||
| VisibilityEffect _canAffectVisibility(UserTopicEvent event) { | ||
| UserTopicVisibilityEffect _canAffectVisibility(UserTopicEvent event) { | ||
| switch (narrow) { | ||
| case CombinedFeedNarrow(): | ||
| return store.willChangeIfTopicVisible(event); | ||
|
|
||
| case ChannelNarrow(:final streamId): | ||
| if (event.streamId != streamId) return VisibilityEffect.none; | ||
| if (event.streamId != streamId) return UserTopicVisibilityEffect.none; | ||
| return store.willChangeIfTopicVisibleInStream(event); | ||
|
|
||
| case TopicNarrow(): | ||
| case DmNarrow(): | ||
| case MentionsNarrow(): | ||
| case StarredMessagesNarrow(): | ||
| case KeywordSearchNarrow(): | ||
| return VisibilityEffect.none; | ||
| return UserTopicVisibilityEffect.none; | ||
| } | ||
| } | ||
|
|
||
| /// Whether [_messageVisible] is true for all possible messages. | ||
| /// | ||
| /// This is useful for an optimization. | ||
| bool get _allMessagesVisible { | ||
| switch (narrow) { | ||
| /// Whether this event could affect the result that [_messageVisible] | ||
| /// would ever have returned for any possible message in this message list. | ||
| MutedUsersVisibilityEffect _mutedUsersEventCanAffectVisibility(MutedUsersEvent event) { | ||
| switch(narrow) { | ||
| case CombinedFeedNarrow(): | ||
|
Comment on lines
+743
to
745
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. similarly, put the cases in the same order as in |
||
| case ChannelNarrow(): | ||
| return false; | ||
| return store.mightChangeShouldMuteDmConversation(event); | ||
|
|
||
| case ChannelNarrow(): | ||
| case TopicNarrow(): | ||
| case DmNarrow(): | ||
| return MutedUsersVisibilityEffect.none; | ||
|
|
||
| case MentionsNarrow(): | ||
| case StarredMessagesNarrow(): | ||
| case KeywordSearchNarrow(): | ||
| return true; | ||
| return store.mightChangeShouldMuteDmConversation(event); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -1011,10 +1041,10 @@ class MessageListView with ChangeNotifier, _MessageSequence { | |
|
|
||
| void handleUserTopicEvent(UserTopicEvent event) { | ||
| switch (_canAffectVisibility(event)) { | ||
| case VisibilityEffect.none: | ||
| case UserTopicVisibilityEffect.none: | ||
| return; | ||
|
|
||
| case VisibilityEffect.muted: | ||
| case UserTopicVisibilityEffect.muted: | ||
| bool removed = _removeMessagesWhere((message) => | ||
| message is StreamMessage | ||
| && message.streamId == event.streamId | ||
|
|
@@ -1029,7 +1059,35 @@ class MessageListView with ChangeNotifier, _MessageSequence { | |
| notifyListeners(); | ||
| } | ||
|
|
||
| case VisibilityEffect.unmuted: | ||
| case UserTopicVisibilityEffect.unmuted: | ||
| // TODO get the newly-unmuted messages from the message store | ||
| // For now, we simplify the task by just refetching this message list | ||
| // from scratch. | ||
| if (fetched) { | ||
| _reset(); | ||
| notifyListeners(); | ||
| fetchInitial(); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| void handleMutedUsersEvent(MutedUsersEvent event) { | ||
| switch (_mutedUsersEventCanAffectVisibility(event)) { | ||
| case MutedUsersVisibilityEffect.none: | ||
| return; | ||
|
|
||
| case MutedUsersVisibilityEffect.muted: | ||
| final anyRemoved = _removeMessagesWhere((message) { | ||
| if (message is! DmMessage) return false; | ||
| final narrow = DmNarrow.ofMessage(message, selfUserId: store.selfUserId); | ||
| return store.shouldMuteDmConversation(narrow, event: event); | ||
| }); | ||
| if (anyRemoved) { | ||
| notifyListeners(); | ||
| } | ||
|
|
||
| case MutedUsersVisibilityEffect.mixed: | ||
| case MutedUsersVisibilityEffect.unmuted: | ||
| // TODO get the newly-unmuted messages from the message store | ||
| // For now, we simplify the task by just refetching this message list | ||
| // from scratch. | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,9 @@ | ||
| import '../api/model/events.dart'; | ||
| import '../api/model/initial_snapshot.dart'; | ||
| import '../api/model/model.dart'; | ||
| import 'algorithms.dart'; | ||
| import 'localizations.dart'; | ||
| import 'narrow.dart'; | ||
| import 'store.dart'; | ||
|
|
||
| /// The portion of [PerAccountStore] describing the users in the realm. | ||
|
|
@@ -85,6 +87,38 @@ mixin UserStore on PerAccountStoreBase { | |
| /// Looks for [userId] in a private [Set], | ||
| /// or in [event.mutedUsers] instead if event is non-null. | ||
| bool isUserMuted(int userId, {MutedUsersEvent? event}); | ||
|
|
||
| /// Whether the self-user has muted everyone in [narrow]. | ||
| /// | ||
| /// Returns false for the self-DM. | ||
| /// | ||
| /// Calls [isUserMuted] for each participant, passing along [event]. | ||
| bool shouldMuteDmConversation(DmNarrow narrow, {MutedUsersEvent? event}) { | ||
| if (narrow.otherRecipientIds.isEmpty) return false; | ||
| return narrow.otherRecipientIds.every( | ||
| (userId) => isUserMuted(userId, event: event)); | ||
| } | ||
|
|
||
| /// Whether the given event might change the result of [shouldMuteDmConversation] | ||
| /// for its list of muted users, compared to the current state. | ||
| MutedUsersVisibilityEffect mightChangeShouldMuteDmConversation(MutedUsersEvent event); | ||
| } | ||
|
|
||
| /// Whether and how a given [MutedUsersEvent] may affect the results | ||
| /// that [UserStore.shouldMuteDmConversation] would give for some messages. | ||
| enum MutedUsersVisibilityEffect { | ||
| /// The event will have no effect on the visibility results. | ||
| none, | ||
|
|
||
| /// The event may change some visibility results from true to false. | ||
| muted, | ||
|
|
||
| /// The event may change some visibility results from false to true. | ||
| unmuted, | ||
|
|
||
| /// The event may change some visibility results from false to true, | ||
| /// and some from true to false. | ||
| mixed; | ||
| } | ||
|
|
||
| /// The implementation of [UserStore] that does the work. | ||
|
|
@@ -118,6 +152,29 @@ class UserStoreImpl extends PerAccountStoreBase with UserStore { | |
| return (event?.mutedUsers.map((item) => item.id) ?? _mutedUsers).contains(userId); | ||
| } | ||
|
|
||
| @override | ||
| MutedUsersVisibilityEffect mightChangeShouldMuteDmConversation(MutedUsersEvent event) { | ||
| final sortedOld = _mutedUsers.toList()..sort(); | ||
| final sortedNew = event.mutedUsers.map((u) => u.id).toList()..sort(); | ||
| assert(isSortedWithoutDuplicates(sortedOld)); | ||
| assert(isSortedWithoutDuplicates(sortedNew)); | ||
| final union = setUnion(sortedOld, sortedNew); | ||
|
|
||
| final willMuteSome = sortedOld.length < union.length; | ||
| final willUnmuteSome = sortedNew.length < union.length; | ||
|
Comment on lines
+161
to
+164
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. Neat, yeah, this logic works. |
||
|
|
||
| switch ((willUnmuteSome, willMuteSome)) { | ||
| case (true, false): | ||
| return MutedUsersVisibilityEffect.unmuted; | ||
| case (false, true): | ||
| return MutedUsersVisibilityEffect.muted; | ||
| case (true, true): | ||
| return MutedUsersVisibilityEffect.mixed; | ||
| case (false, false): // TODO(log)? | ||
| return MutedUsersVisibilityEffect.none; | ||
| } | ||
| } | ||
|
|
||
| void handleRealmUserEvent(RealmUserEvent event) { | ||
| switch (event) { | ||
| case RealmUserAddEvent(): | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Yeah, agreed.
Some of the verbosity (like in these lines) will at least get resolved by the upcoming Dart feature of "dot shorthands", expected later this year:
https://github.com/dart-lang/language/blob/main/working/3616%20-%20enum%20value%20shorthand/proposal-simple-lrhn.md
I believe with that feature we'll be able to say just
.unmuted,.muted,.nonehere, without the name of the enum type.