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.

hotkey: Fix 'Shift + M' to not work in unsubscribed channel.

Prakhar Pratyushcbc3f84be44b
diff --git a/web/src/user_topics_ui.ts b/web/src/user_topics_ui.ts
index ad79f41fe06..43f361bf8a8 100644
--- a/web/src/user_topics_ui.ts
+++ b/web/src/user_topics_ui.ts
@@ -8,6 +8,7 @@ import * as overlays from "./overlays";
import * as popover_menus from "./popover_menus";
import * as recent_view_ui from "./recent_view_ui";
import * as settings_user_topics from "./settings_user_topics";
+import * as stream_data from "./stream_data";
import * as stream_list from "./stream_list";
import * as sub_store from "./sub_store";
import * as unread_ui from "./unread_ui";
@@ -89,6 +90,10 @@ export function toggle_topic_visibility_policy(message: Message): void {
const stream_id = message.stream_id;
const topic = message.topic;
+ if (!stream_data.is_subscribed(stream_id)) {
+ return;
+ }
+
if (
user_topics.is_topic_muted(stream_id, topic) ||
user_topics.is_topic_unmuted(stream_id, topic)
diff --git a/web/tests/user_topics_ui.test.js b/web/tests/user_topics_ui.test.js
new file mode 100644
index 00000000000..887f902a4a7
--- /dev/null
+++ b/web/tests/user_topics_ui.test.js
@@ -0,0 +1,50 @@
+"use strict";
+
+const {strict: assert} = require("assert");
+
+const {zrequire} = require("./lib/namespace");
+const {run_test} = require("./lib/test");
+
+const user_topics = zrequire("user_topics");
+const user_topics_ui = zrequire("user_topics_ui");
+const stream_data = zrequire("stream_data");
+
+const design = {
+ stream_id: 101,
+ name: "design",
+ subscribed: false,
+ is_muted: false,
+};
+
+stream_data.add_sub(design);
+
+function test(label, f) {
+ run_test(label, (helpers) => {
+ user_topics.set_user_topics([]);
+ return f(helpers);
+ });
+}
+
+function update_visibility_policy(visibility_policy) {
+ user_topics.update_user_topics(design.stream_id, design.name, "java", visibility_policy);
+}
+
+test("toggle_topic_visibility_policy", () => {
+ // Mute a topic
+ assert.ok(!user_topics.is_topic_muted(design.stream_id, "java"));
+ update_visibility_policy(user_topics.all_visibility_policies.MUTED);
+ assert.ok(user_topics.is_topic_muted(design.stream_id, "java"));
+
+ // Unsubscribe the channel
+ design.subscribed = false;
+
+ const message = {
+ type: "stream",
+ stream_id: design.stream_id,
+ topic: "java",
+ };
+
+ // Verify that we can't toggle visibility policy in unsubscribed channel.
+ user_topics_ui.toggle_topic_visibility_policy(message);
+ assert.ok(user_topics.is_topic_muted(design.stream_id, "java"));
+});