Skip to content

Commit 8f3cc2e

Browse files
committed
store: Exclude DM conversations with muted users
1 parent edba01f commit 8f3cc2e

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

lib/model/store.dart

+22-2
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,7 @@ class PerAccountStore extends ChangeNotifier with EmojiStore, UserStore, Channel
328328
assert(connection.zulipFeatureLevel == account.zulipFeatureLevel);
329329

330330
final realmUrl = account.realmUrl;
331+
final mutedUserIdsSorted = _sortMutedUsers(initialSnapshot.mutedUsers);
331332
final channels = ChannelStoreImpl(initialSnapshot: initialSnapshot);
332333
return PerAccountStore._(
333334
globalStore: globalStore,
@@ -346,6 +347,7 @@ class PerAccountStore extends ChangeNotifier with EmojiStore, UserStore, Channel
346347
accountId: accountId,
347348
userSettings: initialSnapshot.userSettings,
348349
mutedUsers: initialSnapshot.mutedUsers,
350+
mutedUserIdsSorted: mutedUserIdsSorted,
349351
typingNotifier: TypingNotifier(
350352
connection: connection,
351353
typingStoppedWaitPeriod: Duration(
@@ -368,7 +370,11 @@ class PerAccountStore extends ChangeNotifier with EmojiStore, UserStore, Channel
368370
channelStore: channels,
369371
),
370372
recentDmConversationsView: RecentDmConversationsView(
371-
initial: initialSnapshot.recentPrivateConversations, selfUserId: account.userId),
373+
initial: _filterRecentPrivateConversations(
374+
initialSnapshot.recentPrivateConversations,
375+
mutedUserIdsSorted),
376+
selfUserId: account.userId,
377+
),
372378
recentSenders: RecentSenders(),
373379
);
374380
}
@@ -389,6 +395,7 @@ class PerAccountStore extends ChangeNotifier with EmojiStore, UserStore, Channel
389395
required this.accountId,
390396
required this.userSettings,
391397
required this.mutedUsers,
398+
required List<int> mutedUserIdsSorted,
392399
required this.typingNotifier,
393400
required UserStoreImpl users,
394401
required this.typingStatus,
@@ -403,7 +410,7 @@ class PerAccountStore extends ChangeNotifier with EmojiStore, UserStore, Channel
403410
_globalStore = globalStore,
404411
_realmEmptyTopicDisplayName = realmEmptyTopicDisplayName,
405412
_emoji = emoji,
406-
_mutedUserIdsSorted = _sortMutedUsers(mutedUsers),
413+
_mutedUserIdsSorted = mutedUserIdsSorted,
407414
_users = users,
408415
_channels = channels,
409416
_messages = messages;
@@ -837,6 +844,19 @@ class PerAccountStore extends ChangeNotifier with EmojiStore, UserStore, Channel
837844
return mutedUsers.map((user) => user.id).toList()..sort();
838845
}
839846

847+
static List<RecentDmConversation> _filterRecentPrivateConversations(
848+
List<RecentDmConversation> recentPms,
849+
List<int> mutedUserIdsSorted,
850+
) {
851+
bool isUserMuted(int id) =>
852+
mutedUserIdsSorted.binarySearch(id, (a, b) => a.compareTo(b)) >= 0;
853+
854+
return recentPms
855+
.where((conversation) =>
856+
conversation.userIds.any((id) => !isUserMuted(id)))
857+
.toList();
858+
}
859+
840860
@override
841861
String toString() => '${objectRuntimeType(this, 'PerAccountStore')}#${shortHash(this)}';
842862
}

0 commit comments

Comments
 (0)