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.

filter: Fix combined feed navigating to muted unread message.

Aman Agrawalb22adc1d5f62
diff --git a/web/src/filter.ts b/web/src/filter.ts
index 31b7209be4b..2763b79b8a9 100644
--- a/web/src/filter.ts
+++ b/web/src/filter.ts
@@ -123,9 +123,15 @@ function message_in_home(message: Message): boolean {
return true;
}
+ if (user_topics.is_topic_muted(message.stream_id, message.topic)) {
+ // If topic is muted, we don't show the message.
+ return false;
+ }
+
return (
+ // If stream is muted, we show the message if topic is unmuted or followed.
!stream_data.is_muted(message.stream_id) ||
- user_topics.is_topic_unmuted(message.stream_id, message.topic)
+ user_topics.is_topic_unmuted_or_followed(message.stream_id, message.topic)
);
}
diff --git a/web/tests/filter.test.js b/web/tests/filter.test.js
index 8ad854037a9..32ecbdba85a 100644
--- a/web/tests/filter.test.js
+++ b/web/tests/filter.test.js
@@ -11,6 +11,7 @@ const $ = require("./lib/zjquery");
const {page_params, realm} = require("./lib/zpage_params");
const message_store = mock_esm("../src/message_store");
+const user_topics = mock_esm("../src/user_topics");
const resolved_topic = zrequire("../shared/src/resolved_topic");
const stream_data = zrequire("stream_data");
@@ -753,7 +754,7 @@ test("canonicalization", () => {
assert.equal(term.operand, "link");
});
-test("predicate_basics", () => {
+test("predicate_basics", ({override}) => {
// Predicates are functions that accept a message object with the message
// attributes (not content), and return true if the message belongs in a
// given narrow. If the narrow parameters include a search, the predicate
@@ -831,10 +832,33 @@ test("predicate_basics", () => {
assert.ok(!predicate({type: stream_message, topic: "foo"}));
const unknown_stream_id = 999;
+ override(user_topics, "is_topic_muted", () => false);
+ override(user_topics, "is_topic_unmuted_or_followed", () => false);
predicate = get_predicate([["in", "home"]]);
assert.ok(!predicate({stream_id: unknown_stream_id, stream: "unknown"}));
assert.ok(predicate({type: direct_message}));
+ // Muted topic is not part of in-home.
+ with_overrides(({override}) => {
+ override(user_topics, "is_topic_muted", () => true);
+ assert.ok(!predicate({stream_id, topic: "bar"}));
+ });
+
+ // Muted stream is not part of in-home.
+ const muted_stream = {
+ stream_id: 94924,
+ name: "muted",
+ is_muted: true,
+ };
+ stream_data.add_sub(muted_stream);
+ assert.ok(!predicate({stream_id: muted_stream.stream_id, topic: "bar"}));
+
+ // Muted stream but topic is unmuted or followed is part of in-home.
+ with_overrides(({override}) => {
+ override(user_topics, "is_topic_unmuted_or_followed", () => true);
+ assert.ok(predicate({stream_id: muted_stream.stream_id, topic: "bar"}));
+ });
+
make_sub("kiosk", 1234);
with_overrides(({override}) => {
override(page_params, "narrow_stream", "kiosk");