Skip to content

Commit 4362559

Browse files
committed
msglist: Add message to mentions if mentioned
Fixes: zulip#649
1 parent a1b5579 commit 4362559

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-4
lines changed

lib/model/store.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ class PerAccountStore extends ChangeNotifier with EmojiStore, ChannelStore, Mess
407407
@override
408408
void reconcileMessages(List<Message> messages) {
409409
_messages.reconcileMessages(messages);
410-
// TODO(#649) notify [unreads] of the just-fetched messages
410+
unreads.reconcileMessages(messages);
411411
// TODO(#650) notify [recentDmConversationsView] of the just-fetched messages
412412
}
413413

lib/model/unreads.dart

Lines changed: 11 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
@@ -214,6 +212,16 @@ class Unreads extends ChangeNotifier {
214212
}
215213
}
216214

215+
void reconcileMessages(List<Message> messages) {
216+
for (final message in messages) {
217+
if (message.flags.contains(MessageFlag.read)) continue;
218+
if (message.flags.contains(MessageFlag.mentioned)
219+
|| message.flags.contains(MessageFlag.wildcardMentioned)) {
220+
mentions.add(message.id);
221+
}
222+
}
223+
}
224+
217225
void handleMessageEvent(MessageEvent event) {
218226
final message = event.message;
219227
if (message.flags.contains(MessageFlag.read)) {

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)