Skip to content

Commit 8314fc7

Browse files
committed
recent-dms: Exclude DM conversations with muted users
The conversations are excluded where all the recipients are muted.
1 parent 23c3025 commit 8314fc7

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

lib/model/recent_dm_conversations.dart

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import '../api/model/model.dart';
88
import '../api/model/events.dart';
99
import 'narrow.dart';
1010
import 'store.dart';
11+
import 'user.dart';
1112

1213
/// A view-model for the recent-DM-conversations UI.
1314
///
@@ -17,6 +18,7 @@ class RecentDmConversationsView extends PerAccountStoreBase with ChangeNotifier
1718
factory RecentDmConversationsView({
1819
required CorePerAccountStore core,
1920
required List<RecentDmConversation> initial,
21+
required UserStore userStore,
2022
}) {
2123
final entries = initial.map((conversation) => MapEntry(
2224
DmNarrow.ofRecentDmConversation(conversation, selfUserId: core.selfUserId),
@@ -35,6 +37,7 @@ class RecentDmConversationsView extends PerAccountStoreBase with ChangeNotifier
3537

3638
return RecentDmConversationsView._(
3739
core: core,
40+
userStore: userStore,
3841
map: Map.fromEntries(entries),
3942
sorted: QueueList.from(entries.map((e) => e.key)),
4043
latestMessagesByRecipient: latestMessagesByRecipient,
@@ -43,11 +46,14 @@ class RecentDmConversationsView extends PerAccountStoreBase with ChangeNotifier
4346

4447
RecentDmConversationsView._({
4548
required super.core,
49+
required this.userStore,
4650
required this.map,
4751
required this.sorted,
4852
required this.latestMessagesByRecipient,
4953
});
5054

55+
final UserStore userStore;
56+
5157
/// The latest message ID in each conversation.
5258
final Map<DmNarrow, int> map;
5359

@@ -63,6 +69,11 @@ class RecentDmConversationsView extends PerAccountStoreBase with ChangeNotifier
6369
/// it might have been sent by anyone in its conversation.)
6470
final Map<int, int> latestMessagesByRecipient;
6571

72+
/// Same as [sorted] but excluding conversations where all the recipients are
73+
/// muted.
74+
QueueList<DmNarrow> get sortedFiltered => QueueList.from(
75+
sorted.whereNot((narrow) => userStore.allRecipientsMuted(narrow)));
76+
6677
/// Insert the key at the proper place in [sorted].
6778
///
6879
/// Optimized, taking O(1) time, for the case where that place is the start,

lib/model/store.dart

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,7 @@ class PerAccountStore extends PerAccountStoreBase with ChangeNotifier, EmojiStor
471471
accountId: accountId,
472472
selfUserId: account.userId,
473473
);
474+
final users = UserStoreImpl(core: core, initialSnapshot: initialSnapshot);
474475
final channels = ChannelStoreImpl(initialSnapshot: initialSnapshot);
475476
return PerAccountStore._(
476477
core: core,
@@ -496,7 +497,7 @@ class PerAccountStore extends PerAccountStoreBase with ChangeNotifier, EmojiStor
496497
typingStartedWaitPeriod: Duration(
497498
milliseconds: initialSnapshot.serverTypingStartedWaitPeriodMilliseconds),
498499
),
499-
users: UserStoreImpl(core: core, initialSnapshot: initialSnapshot),
500+
users: users,
500501
typingStatus: TypingStatus(core: core,
501502
typingStartedExpiryPeriod: Duration(milliseconds: initialSnapshot.serverTypingStartedExpiryPeriodMilliseconds),
502503
),
@@ -507,8 +508,11 @@ class PerAccountStore extends PerAccountStoreBase with ChangeNotifier, EmojiStor
507508
core: core,
508509
channelStore: channels,
509510
),
510-
recentDmConversationsView: RecentDmConversationsView(core: core,
511-
initial: initialSnapshot.recentPrivateConversations),
511+
recentDmConversationsView: RecentDmConversationsView(
512+
initial: initialSnapshot.recentPrivateConversations,
513+
core: core,
514+
userStore: users,
515+
),
512516
recentSenders: RecentSenders(),
513517
);
514518
}

lib/widgets/recent_dm_conversations.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class _RecentDmConversationsPageBodyState extends State<RecentDmConversationsPag
4949

5050
@override
5151
Widget build(BuildContext context) {
52-
final sorted = model!.sorted;
52+
final sorted = model!.sortedFiltered;
5353
return SafeArea(
5454
// Don't pad the bottom here; we want the list content to do that.
5555
bottom: false,

0 commit comments

Comments
 (0)