From 71b915e09d2f879bfe5ca4a5ec2cd7b9fcf71a1e Mon Sep 17 00:00:00 2001 From: Hardik Dharmani Date: Wed, 20 Sep 2023 16:55:50 +0530 Subject: [PATCH] unread: Fix logic for wildcard mentions in direct messages. Wildcard mentions in direct messages were not being count as mentions due to incorrect calculation of `is_unmuted_mention` variable in `update_message_for_mention()` function in `unread.js`. Fixed this by correcting the calculation of `is_unmuted_mention`. --- web/src/unread.js | 11 +++++++++-- web/tests/unread.test.js | 30 +++++++++++++++++++++++++----- 2 files changed, 34 insertions(+), 7 deletions(-) diff --git a/web/src/unread.js b/web/src/unread.js index a177ad63ee..9e97c2d098 100644 --- a/web/src/unread.js +++ b/web/src/unread.js @@ -709,10 +709,17 @@ export function update_message_for_mention(message, content_edited = false) { return false; } + // A message is said to have an unmuted mention if message contains a mention and + // if the message is a direct message or + // if the message is in a non muted topic in an unmuted stream or + // if the message is in a followed or an unmuted topic in a muted stream. const is_unmuted_mention = - message.type === "stream" && message.mentioned && - !user_topics.is_topic_muted(message.stream_id, message.topic); + (message.type === "private" || + (!stream_data.is_muted(message.stream_id) && + !user_topics.is_topic_muted(message.stream_id, message.topic)) || + (stream_data.is_muted(message.stream_id) && + user_topics.is_topic_unmuted_or_followed(message.stream_id, message.topic))); if (is_unmuted_mention || message.mentioned_me_directly) { unread_mentions_counter.add(message.id); diff --git a/web/tests/unread.test.js b/web/tests/unread.test.js index eea7fc41d0..2a73ae0c15 100644 --- a/web/tests/unread.test.js +++ b/web/tests/unread.test.js @@ -472,14 +472,32 @@ test("mentions", () => { assert.deepEqual(unread.get_msg_ids_for_mentions(), []); test_notifiable_count(counts.home_unread_messages, 0); - const muted_stream_id = 401; + const muted_stream_id = 900; + const unmuted_stream_id = 901; - user_topics.update_user_topics(401, "lunch", user_topics.all_visibility_policies.MUTED); + sub_store.add_hydrated_sub(muted_stream_id, { + muted_stream_id, + name: "muted stream for testing unread mentions", + subscribed: true, + is_muted: true, + }); + sub_store.add_hydrated_sub(unmuted_stream_id, { + unmuted_stream_id, + name: "unmuted stream for testing unread mention", + subscribed: true, + is_muted: false, + }); + + user_topics.update_user_topics( + muted_stream_id, + "lunch", + user_topics.all_visibility_policies.MUTED, + ); const already_read_message = { id: 14, type: "stream", - stream_id: 400, + stream_id: unmuted_stream_id, topic: "lunch", mentioned: true, mentioned_me_directly: true, @@ -489,7 +507,7 @@ test("mentions", () => { const mention_me_message = { id: 15, type: "stream", - stream_id: 400, + stream_id: unmuted_stream_id, topic: "lunch", mentioned: true, mentioned_me_directly: true, @@ -499,7 +517,7 @@ test("mentions", () => { const mention_all_message = { id: 16, type: "stream", - stream_id: 400, + stream_id: unmuted_stream_id, topic: "lunch", mentioned: true, mentioned_me_directly: false, @@ -577,8 +595,10 @@ test("mentions", () => { }); test("mention updates", () => { + // Unread message in an unmuted stream. const message = { id: 17, + stream_id: 901, unread: false, type: "stream", topic: "hello",