Skip to content

Commit d49b265

Browse files
committed
msglist: Add message to mentions if mentioned
Fixes: zulip#649
1 parent 34da52f commit d49b265

File tree

3 files changed

+32
-4
lines changed

3 files changed

+32
-4
lines changed

lib/model/store.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ class PerAccountStore extends ChangeNotifier with ChannelStore, MessageStore {
375375
@override
376376
void reconcileMessages(List<Message> messages) {
377377
_messages.reconcileMessages(messages);
378-
// TODO(#649) notify [unreads] of the just-fetched messages
378+
unreads.onMessagesFetched(messages);
379379
// TODO(#650) notify [recentDmConversationsView] of the just-fetched messages
380380
}
381381

lib/model/unreads.dart

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ import 'channel.dart';
3232
/// unsubscribed streams and messages sent by muted users.
3333
// TODO When [oldUnreadsMissing], if you load a message list with very old unreads,
3434
// sync to those unreads, because the user has shown an interest in them.
35-
// TODO When loading a message list with stream messages, check all the stream
36-
// messages and refresh [mentions] (see [mentions] dartdoc).
3735
class Unreads extends ChangeNotifier {
3836
factory Unreads({
3937
required UnreadMessagesSnapshot initial,
@@ -103,7 +101,7 @@ class Unreads extends ChangeNotifier {
103101
/// a) the message is edited at all ([UpdateMessageEvent]),
104102
/// assuming it still has a direct or wildcard mention after the edit, or
105103
/// b) the message gains a direct @-mention ([UpdateMessageFlagsEvent]), or
106-
/// c) TODO unimplemented: the user loads the message in the message list
104+
/// c) the user loads the message in the message list
107105
/// But otherwise, assume its unread state remains unknown to [mentions].
108106
///
109107
/// [1] This item applies verbatim at Server 8.0+. For older servers, the
@@ -236,6 +234,19 @@ class Unreads extends ChangeNotifier {
236234
notifyListeners();
237235
}
238236

237+
void onMessagesFetched(List<Message> messages) {
238+
messages.forEach(_addMessageToMentionsIfMentioned);
239+
}
240+
241+
void _addMessageToMentionsIfMentioned(Message message) {
242+
if (message.flags.contains(MessageFlag.read)) return;
243+
if (!message.flags.contains(MessageFlag.mentioned)
244+
&& !message.flags.contains(MessageFlag.wildcardMentioned)) return;
245+
246+
mentions.add(message.id);
247+
}
248+
249+
239250
void handleUpdateMessageEvent(UpdateMessageEvent event) {
240251
final messageId = event.messageId;
241252

test/model/unreads_test.dart

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,23 @@ void main() {
240240
});
241241
});
242242

243+
group('onMessagesFetched', () {
244+
test('messages are added to mentions when they are not read and include mention', () async {
245+
final stream = eg.stream();
246+
prepare();
247+
await channelStore.addStream(stream);
248+
check(model.mentions).isEmpty();
249+
fillWithMessages([
250+
eg.streamMessage(stream: stream, flags: []),
251+
eg.streamMessage(stream: stream, flags: [MessageFlag.mentioned, MessageFlag.read]),
252+
eg.streamMessage(stream: stream, flags: [MessageFlag.mentioned]),
253+
eg.streamMessage(stream: stream, flags: [MessageFlag.wildcardMentioned]),
254+
]);
255+
256+
check(model.mentions.length).equals(2);
257+
});
258+
});
259+
243260
group('handleMessageEvent', () {
244261
for (final (isUnread, isStream, isDirectMentioned, isWildcardMentioned) in [
245262
(true, true, true, true ),

0 commit comments

Comments
 (0)