Skip to content

Commit 22fa969

Browse files
committed
store: Exclude DM conversations with muted users
1 parent 533eb12 commit 22fa969

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

lib/model/store.dart

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,7 @@ class PerAccountStore extends PerAccountStoreBase with ChangeNotifier, EmojiStor
465465
accountId: accountId,
466466
selfUserId: account.userId,
467467
);
468+
final mutedUserIdsSorted = _sortMutedUsers(initialSnapshot.mutedUsers);
468469
final channels = ChannelStoreImpl(initialSnapshot: initialSnapshot);
469470
return PerAccountStore._(
470471
core: core,
@@ -482,6 +483,7 @@ class PerAccountStore extends PerAccountStoreBase with ChangeNotifier, EmojiStor
482483
core: core, allRealmEmoji: initialSnapshot.realmEmoji),
483484
userSettings: initialSnapshot.userSettings,
484485
mutedUsers: initialSnapshot.mutedUsers,
486+
mutedUserIdsSorted: mutedUserIdsSorted,
485487
typingNotifier: TypingNotifier(
486488
core: core,
487489
typingStoppedWaitPeriod: Duration(
@@ -501,7 +503,10 @@ class PerAccountStore extends PerAccountStoreBase with ChangeNotifier, EmojiStor
501503
channelStore: channels,
502504
),
503505
recentDmConversationsView: RecentDmConversationsView(core: core,
504-
initial: initialSnapshot.recentPrivateConversations),
506+
initial: _filterRecentPrivateConversations(
507+
initialSnapshot.recentPrivateConversations,
508+
mutedUserIdsSorted),
509+
),
505510
recentSenders: RecentSenders(),
506511
);
507512
}
@@ -521,6 +526,7 @@ class PerAccountStore extends PerAccountStoreBase with ChangeNotifier, EmojiStor
521526
required EmojiStoreImpl emoji,
522527
required this.userSettings,
523528
required this.mutedUsers,
529+
required List<int> mutedUserIdsSorted,
524530
required this.typingNotifier,
525531
required UserStoreImpl users,
526532
required this.typingStatus,
@@ -531,7 +537,7 @@ class PerAccountStore extends PerAccountStoreBase with ChangeNotifier, EmojiStor
531537
required this.recentSenders,
532538
}) : _realmEmptyTopicDisplayName = realmEmptyTopicDisplayName,
533539
_emoji = emoji,
534-
_mutedUserIdsSorted = _sortMutedUsers(mutedUsers),
540+
_mutedUserIdsSorted = mutedUserIdsSorted,
535541
_users = users,
536542
_channels = channels,
537543
_messages = messages;
@@ -946,6 +952,19 @@ class PerAccountStore extends PerAccountStoreBase with ChangeNotifier, EmojiStor
946952
return mutedUsers.map((user) => user.id).toList()..sort();
947953
}
948954

955+
static List<RecentDmConversation> _filterRecentPrivateConversations(
956+
List<RecentDmConversation> recentPms,
957+
List<int> mutedUserIdsSorted,
958+
) {
959+
bool isUserMuted(int id) =>
960+
mutedUserIdsSorted.binarySearch(id, (a, b) => a.compareTo(b)) >= 0;
961+
962+
return recentPms
963+
.where((conversation) =>
964+
conversation.userIds.any((id) => !isUserMuted(id)))
965+
.toList();
966+
}
967+
949968
@override
950969
String toString() => '${objectRuntimeType(this, 'PerAccountStore')}#${shortHash(this)}';
951970
}

0 commit comments

Comments
 (0)