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.

user_topics: Extract method to check if topic is visible `in-home`.

Aman Agrawal91714b5f1b49
diff --git a/web/src/filter.ts b/web/src/filter.ts
index 5346af34dbb..0ae7081ed1b 100644
--- a/web/src/filter.ts
+++ b/web/src/filter.ts
@@ -131,16 +131,7 @@ 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 channel is muted, we show the message if topic is unmuted or followed.
- !stream_data.is_muted(message.stream_id) ||
- user_topics.is_topic_unmuted_or_followed(message.stream_id, message.topic)
- );
+ return user_topics.is_topic_visible_in_home(message.stream_id, message.topic);
}
function message_matches_search_term(message: Message, operator: string, operand: string): boolean {
diff --git a/web/src/user_topics.ts b/web/src/user_topics.ts
index d6cace35322..1818719be19 100644
--- a/web/src/user_topics.ts
+++ b/web/src/user_topics.ts
@@ -11,6 +11,7 @@ import {$t} from "./i18n.ts";
import * as loading from "./loading.ts";
import * as settings_ui from "./settings_ui.ts";
import type {StateData, user_topic_schema} from "./state_data.ts";
+import * as stream_data from "./stream_data.ts";
import * as sub_store from "./sub_store.ts";
import * as timerender from "./timerender.ts";
import * as ui_report from "./ui_report.ts";
@@ -240,6 +241,20 @@ export function set_user_topics(user_topics: ServerUserTopic[]): void {
}
}
+export function is_topic_visible_in_home(stream_id: number, topic: string): boolean {
+ // This determines if topic will be visible in combined feed just based
+ // on topic visibility policy and stream properties.
+ if (is_topic_muted(stream_id, topic)) {
+ // If topic is muted, we don't show the message.
+ return false;
+ }
+
+ return (
+ // If channel is muted, we show the message if topic is unmuted or followed.
+ !stream_data.is_muted(stream_id) || is_topic_unmuted_or_followed(stream_id, topic)
+ );
+}
+
export function initialize(params: StateData["user_topics"]): void {
set_user_topics(params.user_topics);
}
diff --git a/web/tests/filter.test.cjs b/web/tests/filter.test.cjs
index 59447adb93d..b93762a2b54 100644
--- a/web/tests/filter.test.cjs
+++ b/web/tests/filter.test.cjs
@@ -997,15 +997,14 @@ test("predicate_basics", ({override}) => {
assert.ok(predicate({type: "stream", topic: "foo", stream_id: 5}));
const unknown_stream_id = new_stream_id();
- override(user_topics, "is_topic_muted", () => false);
- override(user_topics, "is_topic_unmuted_or_followed", () => false);
+ override(user_topics, "is_topic_visible_in_home", () => 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);
+ override(user_topics, "is_topic_visible_in_home", () => false);
assert.ok(!predicate({stream_id: foo_stream_id, topic: "bar"}));
});
@@ -1020,7 +1019,7 @@ test("predicate_basics", ({override}) => {
// 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);
+ override(user_topics, "is_topic_visible_in_home", () => true);
assert.ok(predicate({stream_id: muted_stream.stream_id, topic: "bar"}));
});