Skip to content

Commit 381b1f6

Browse files
committed
unreads: In @-mentions count, exclude messages in muted DM conversations
As we do in the actual message list.
1 parent 72f172d commit 381b1f6

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed

lib/model/message_list.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,9 @@ class MessageListView with ChangeNotifier, _MessageSequence {
691691
return true;
692692

693693
case MentionsNarrow():
694+
// If changing this, consider whether [Unreads.countInMentionsNarrow]
695+
// should be changed correspondingly, so the message-list view matches
696+
// the unread-count badge.
694697
case StarredMessagesNarrow():
695698
case KeywordSearchNarrow():
696699
if (message.conversation case DmConversation(:final allRecipientIds)) {

lib/model/unreads.dart

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,30 @@ class Unreads extends PerAccountStoreBase with ChangeNotifier {
220220

221221
int countInDmNarrow(DmNarrow narrow) => dms[narrow]?.length ?? 0;
222222

223-
int countInMentionsNarrow() => mentions.length;
223+
/// The unread count for the mentions narrow.
224+
///
225+
/// This excludes DM messages in conversations that are considered muted,
226+
/// by [UserStore.shouldMuteDmConversation].
227+
// If changing which messages to exclude, consider whether the @-mentions
228+
// view should change its "is-message-visible" code correspondingly,
229+
// so the unread-count badge matches what you see in that view.
230+
// TODO: deduplicate "is-message-visible" code
231+
// between [Unreads] and [MessageListView]?
232+
// TODO(#370): maintain this count incrementally, rather than recomputing from scratch
233+
int countInMentionsNarrow() {
234+
int c = 0;
235+
for (final messageId in mentions) {
236+
final narrow = locatorMap[messageId];
237+
if (narrow == null) continue;
238+
switch (narrow) {
239+
case DmNarrow():
240+
if (channelStore.shouldMuteDmConversation(narrow)) continue;
241+
case TopicNarrow():
242+
}
243+
c++;
244+
}
245+
return c;
246+
}
224247

225248
// TODO: Implement unreads handling.
226249
int countInStarredMessagesNarrow() => 0;

test/model/unreads_test.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,12 +254,17 @@ void main() {
254254
final stream = eg.stream();
255255
prepare();
256256
await store.addStream(stream);
257+
await store.setUserTopic(stream, 'a', UserTopicVisibilityPolicy.muted);
258+
await store.setMutedUsers([eg.thirdUser.userId]);
257259
fillWithMessages([
258260
eg.streamMessage(stream: stream, flags: []),
259261
eg.streamMessage(stream: stream, flags: [MessageFlag.mentioned]),
262+
eg.streamMessage(stream: stream, topic: 'a', flags: [MessageFlag.mentioned]),
260263
eg.streamMessage(stream: stream, flags: [MessageFlag.wildcardMentioned]),
264+
eg.dmMessage(from: eg.otherUser, to: [eg.selfUser], flags: [MessageFlag.mentioned]),
265+
eg.dmMessage(from: eg.thirdUser, to: [eg.selfUser], flags: [MessageFlag.mentioned]),
261266
]);
262-
check(model.countInMentionsNarrow()).equals(2);
267+
check(model.countInMentionsNarrow()).equals(4);
263268
});
264269

265270
test('countInStarredMessagesNarrow', () async {

0 commit comments

Comments
 (0)