Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

unread: Fix logic for wildcard mentions in direct messages.

Hardik Dharmani71b915e09d2f
diff --git a/web/src/unread.js b/web/src/unread.js
index a177ad63eef..9e97c2d098e 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 eea7fc41d08..2a73ae0c156 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",