mirror of https://github.com/zulip/zulip.git
user_topics_ui: Fix 'toggle_topic_visibility_policy' behavior.
This commit updates the stale logic in 'toggle_topic_visibility_policy' function. It was not updated after the addition of 'follow' visibility policy resulting in buggy behavior.
This commit is contained in:
parent
cbc3f84be4
commit
39c5bb9fa5
|
@ -1,4 +1,5 @@
|
|||
import $ from "jquery";
|
||||
import assert from "minimalistic-assert";
|
||||
|
||||
import * as inbox_util from "./inbox_util";
|
||||
import * as message_lists from "./message_lists";
|
||||
|
@ -94,23 +95,33 @@ export function toggle_topic_visibility_policy(message: Message): void {
|
|||
return;
|
||||
}
|
||||
|
||||
if (
|
||||
user_topics.is_topic_muted(stream_id, topic) ||
|
||||
user_topics.is_topic_unmuted(stream_id, topic)
|
||||
) {
|
||||
const sub = sub_store.get(stream_id);
|
||||
assert(sub !== undefined);
|
||||
|
||||
if (sub.is_muted) {
|
||||
if (user_topics.is_topic_unmuted_or_followed(stream_id, topic)) {
|
||||
user_topics.set_user_topic_visibility_policy(
|
||||
stream_id,
|
||||
topic,
|
||||
user_topics.all_visibility_policies.INHERIT,
|
||||
true,
|
||||
);
|
||||
} else {
|
||||
if (sub_store.get(stream_id)?.is_muted) {
|
||||
user_topics.set_user_topic_visibility_policy(
|
||||
stream_id,
|
||||
topic,
|
||||
user_topics.all_visibility_policies.UNMUTED,
|
||||
true,
|
||||
);
|
||||
}
|
||||
} else {
|
||||
if (user_topics.is_topic_muted(stream_id, topic)) {
|
||||
user_topics.set_user_topic_visibility_policy(
|
||||
stream_id,
|
||||
topic,
|
||||
user_topics.all_visibility_policies.INHERIT,
|
||||
true,
|
||||
);
|
||||
} else {
|
||||
user_topics.set_user_topic_visibility_policy(
|
||||
stream_id,
|
||||
|
|
|
@ -8,6 +8,7 @@ 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 sub_store = zrequire("sub_store");
|
||||
|
||||
const design = {
|
||||
stream_id: 101,
|
||||
|
@ -29,7 +30,7 @@ function update_visibility_policy(visibility_policy) {
|
|||
user_topics.update_user_topics(design.stream_id, design.name, "java", visibility_policy);
|
||||
}
|
||||
|
||||
test("toggle_topic_visibility_policy", () => {
|
||||
test("toggle_topic_visibility_policy", ({override_rewire}) => {
|
||||
// Mute a topic
|
||||
assert.ok(!user_topics.is_topic_muted(design.stream_id, "java"));
|
||||
update_visibility_policy(user_topics.all_visibility_policies.MUTED);
|
||||
|
@ -47,4 +48,57 @@ test("toggle_topic_visibility_policy", () => {
|
|||
// 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"));
|
||||
|
||||
override_rewire(
|
||||
user_topics,
|
||||
"set_user_topic_visibility_policy",
|
||||
(stream_id, topic_name, visibility_policy) => {
|
||||
const stream_name = sub_store.maybe_get_stream_name(stream_id);
|
||||
user_topics.update_user_topics(stream_id, stream_name, topic_name, visibility_policy);
|
||||
},
|
||||
);
|
||||
|
||||
design.subscribed = true;
|
||||
|
||||
// For NOT muted channel
|
||||
user_topics_ui.toggle_topic_visibility_policy(message);
|
||||
assert.ok(
|
||||
user_topics.get_topic_visibility_policy(design.stream_id, "java") ===
|
||||
user_topics.all_visibility_policies.INHERIT,
|
||||
);
|
||||
|
||||
user_topics_ui.toggle_topic_visibility_policy(message);
|
||||
assert.ok(user_topics.is_topic_muted(design.stream_id, "java"));
|
||||
|
||||
update_visibility_policy(user_topics.all_visibility_policies.UNMUTED);
|
||||
user_topics_ui.toggle_topic_visibility_policy(message);
|
||||
assert.ok(user_topics.is_topic_muted(design.stream_id, "java"));
|
||||
|
||||
update_visibility_policy(user_topics.all_visibility_policies.FOLLOWED);
|
||||
user_topics_ui.toggle_topic_visibility_policy(message);
|
||||
assert.ok(user_topics.is_topic_muted(design.stream_id, "java"));
|
||||
|
||||
// For muted channel
|
||||
design.is_muted = true;
|
||||
|
||||
update_visibility_policy(user_topics.all_visibility_policies.INHERIT);
|
||||
user_topics_ui.toggle_topic_visibility_policy(message);
|
||||
assert.ok(user_topics.is_topic_unmuted(design.stream_id, "java"));
|
||||
|
||||
update_visibility_policy(user_topics.all_visibility_policies.MUTED);
|
||||
user_topics_ui.toggle_topic_visibility_policy(message);
|
||||
assert.ok(user_topics.is_topic_unmuted(design.stream_id, "java"));
|
||||
|
||||
user_topics_ui.toggle_topic_visibility_policy(message);
|
||||
assert.ok(
|
||||
user_topics.get_topic_visibility_policy(design.stream_id, "java") ===
|
||||
user_topics.all_visibility_policies.INHERIT,
|
||||
);
|
||||
|
||||
update_visibility_policy(user_topics.all_visibility_policies.FOLLOWED);
|
||||
user_topics_ui.toggle_topic_visibility_policy(message);
|
||||
assert.ok(
|
||||
user_topics.get_topic_visibility_policy(design.stream_id, "java") ===
|
||||
user_topics.all_visibility_policies.INHERIT,
|
||||
);
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue