shortcuts: Update `Shift + M` shortcut to work for unmute topics too.

Renamed toggle_topic_mute function to toggle_topic_visibility_policy.

In toggle_topic_visibility_policy function if topic is either muted or
unmuted it will set the topic's visibility_policy to Inherit else, if
stream is muted or unmuted topic's visibility_policy will be set to
unmuted and muted respectively.

Updated set_user_topic_visibility_policy to only show feedback widget
in case of muting topics with hotkey.

Fixes #25125
This commit is contained in:
Hardik Dharmani 2023-04-15 21:29:26 +05:30 committed by Tim Abbott
parent 043d54d170
commit 82bf1ba58a
4 changed files with 45 additions and 30 deletions

View File

@ -136,7 +136,7 @@ const keypress_mappings = {
71: {name: "G_end", message_view_only: true}, // 'G'
74: {name: "vim_page_down", message_view_only: true}, // 'J'
75: {name: "vim_page_up", message_view_only: true}, // 'K'
77: {name: "toggle_topic_mute", message_view_only: true}, // 'M'
77: {name: "toggle_topic_visibility_policy", message_view_only: true}, // 'M'
80: {name: "narrow_private", message_view_only: true}, // 'P'
82: {name: "respond_to_author", message_view_only: true}, // 'R'
83: {name: "narrow_by_topic", message_view_only: true}, // 'S'
@ -991,8 +991,8 @@ export function process_hotkey(e, hotkey) {
reactions.toggle_emoji_reaction(msg.id, first_reaction.emoji_name);
return true;
}
case "toggle_topic_mute":
muted_topics_ui.toggle_topic_mute(msg);
case "toggle_topic_visibility_policy":
muted_topics_ui.toggle_topic_visibility_policy(msg);
return true;
case "toggle_message_collapse":
condense.toggle_collapse(msg);

View File

@ -6,6 +6,7 @@ import * as popover_menus from "./popover_menus";
import * as recent_topics_ui from "./recent_topics_ui";
import * as settings_muted_topics from "./settings_muted_topics";
import * as stream_list from "./stream_list";
import * as sub_store from "./sub_store";
import * as unread_ui from "./unread_ui";
import * as user_topics from "./user_topics";
@ -38,23 +39,35 @@ export function handle_topic_updates(user_topic) {
rerender_for_muted_topic(old_muted_topics);
}
export function toggle_topic_mute(message) {
export function toggle_topic_visibility_policy(message) {
const stream_id = message.stream_id;
const topic = message.topic;
if (user_topics.is_topic_muted(stream_id, topic)) {
if (
user_topics.is_topic_muted(stream_id, topic) ||
user_topics.is_topic_unmuted(stream_id, topic)
) {
user_topics.set_user_topic_visibility_policy(
stream_id,
topic,
user_topics.all_visibility_policies.INHERIT,
);
} else if (message.type === "stream") {
user_topics.set_user_topic_visibility_policy(
stream_id,
topic,
user_topics.all_visibility_policies.MUTED,
true,
);
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 {
user_topics.set_user_topic_visibility_policy(
stream_id,
topic,
user_topics.all_visibility_policies.MUTED,
true,
);
}
}
}

View File

@ -100,24 +100,26 @@ export function set_user_topic_visibility_policy(stream_id, topic, visibility_po
// only useful when muting from the keyboard, since you
// know what you did if you triggered muting with the
// mouse.
const stream_name = stream_data.maybe_get_stream_name(stream_id);
feedback_widget.show({
populate($container) {
const rendered_html = render_topic_muted();
$container.html(rendered_html);
$container.find(".stream").text(stream_name);
$container.find(".topic").text(topic);
},
on_undo() {
set_user_topic_visibility_policy(
stream_id,
topic,
all_visibility_policies.INHERIT,
);
},
title_text: $t({defaultMessage: "Topic muted"}),
undo_button_text: $t({defaultMessage: "Undo mute"}),
});
if (visibility_policy === all_visibility_policies.MUTED) {
const stream_name = stream_data.maybe_get_stream_name(stream_id);
feedback_widget.show({
populate($container) {
const rendered_html = render_topic_muted();
$container.html(rendered_html);
$container.find(".stream").text(stream_name);
$container.find(".topic").text(topic);
},
on_undo() {
set_user_topic_visibility_policy(
stream_id,
topic,
all_visibility_policies.INHERIT,
);
},
title_text: $t({defaultMessage: "Topic muted"}),
undo_button_text: $t({defaultMessage: "Undo mute"}),
});
}
},
});
}

View File

@ -405,7 +405,7 @@ run_test("emoji picker", ({override}) => {
run_test("G/M keys", () => {
// TODO: move
assert_mapping("G", navigate, "to_end");
assert_mapping("M", muted_topics_ui, "toggle_topic_mute");
assert_mapping("M", muted_topics_ui, "toggle_topic_visibility_policy");
});
run_test("n/p keys", () => {