Skip to content

Commit 2055c11

Browse files
committed
store: Exclude DM conversations with muted users
1 parent 9eafd48 commit 2055c11

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

lib/model/recent_dm_conversations.dart

Lines changed: 20 additions & 1 deletion
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,7 +18,9 @@ class RecentDmConversationsView extends PerAccountStoreBase with ChangeNotifier
1718
factory RecentDmConversationsView({
1819
required CorePerAccountStore core,
1920
required List<RecentDmConversation> initial,
21+
required UserStore userStore,
2022
}) {
23+
initial = _filterRecentDmConversations(initial, userStore);
2124
final entries = initial.map((conversation) => MapEntry(
2225
DmNarrow.ofRecentDmConversation(conversation, selfUserId: core.selfUserId),
2326
conversation.maxMessageId,
@@ -35,18 +38,32 @@ class RecentDmConversationsView extends PerAccountStoreBase with ChangeNotifier
3538

3639
return RecentDmConversationsView._(
3740
core: core,
41+
userStore: userStore,
3842
map: Map.fromEntries(entries),
3943
sorted: QueueList.from(entries.map((e) => e.key)),
4044
latestMessagesByRecipient: latestMessagesByRecipient,
4145
);
4246
}
4347

48+
static List<RecentDmConversation> _filterRecentDmConversations(
49+
List<RecentDmConversation> recentDms,
50+
UserStore userStore,
51+
) {
52+
return recentDms
53+
.where((conversation) =>
54+
conversation.userIds.any((id) => !userStore.isUserMuted(id)))
55+
.toList();
56+
}
57+
4458
RecentDmConversationsView._({
4559
required super.core,
60+
required UserStore userStore,
4661
required this.map,
4762
required this.sorted,
4863
required this.latestMessagesByRecipient,
49-
});
64+
}) : _userStore = userStore;
65+
66+
final UserStore _userStore;
5067

5168
/// The latest message ID in each conversation.
5269
final Map<DmNarrow, int> map;
@@ -158,4 +175,6 @@ class RecentDmConversationsView extends PerAccountStoreBase with ChangeNotifier
158175
// TODO update from messages loaded in message lists. When doing so,
159176
// review handleMessageEvent so it acknowledges the subtle races that can
160177
// happen when taking data from outside the event system.
178+
179+
void handleMutedUsersEvent(MutedUsersEvent event) {}
161180
}

lib/model/store.dart

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,7 @@ class PerAccountStore extends PerAccountStoreBase with ChangeNotifier, EmojiStor
464464
accountId: accountId,
465465
selfUserId: account.userId,
466466
);
467+
final users = UserStoreImpl(core: core, initialSnapshot: initialSnapshot);
467468
final channels = ChannelStoreImpl(initialSnapshot: initialSnapshot);
468469
return PerAccountStore._(
469470
core: core,
@@ -487,7 +488,7 @@ class PerAccountStore extends PerAccountStoreBase with ChangeNotifier, EmojiStor
487488
typingStartedWaitPeriod: Duration(
488489
milliseconds: initialSnapshot.serverTypingStartedWaitPeriodMilliseconds),
489490
),
490-
users: UserStoreImpl(core: core, initialSnapshot: initialSnapshot),
491+
users: users,
491492
typingStatus: TypingStatus(core: core,
492493
typingStartedExpiryPeriod: Duration(milliseconds: initialSnapshot.serverTypingStartedExpiryPeriodMilliseconds),
493494
),
@@ -498,8 +499,11 @@ class PerAccountStore extends PerAccountStoreBase with ChangeNotifier, EmojiStor
498499
core: core,
499500
channelStore: channels,
500501
),
501-
recentDmConversationsView: RecentDmConversationsView(core: core,
502-
initial: initialSnapshot.recentPrivateConversations),
502+
recentDmConversationsView: RecentDmConversationsView(
503+
initial: initialSnapshot.recentPrivateConversations,
504+
core: core,
505+
userStore: users,
506+
),
503507
recentSenders: RecentSenders(),
504508
);
505509
}

0 commit comments

Comments
 (0)