From 65d49b5ad891d2e43922cee7c318009e38d19c8f Mon Sep 17 00:00:00 2001 From: Lalit Date: Wed, 28 Jun 2023 16:54:25 +0530 Subject: [PATCH] recent_topics_ui: Cut dependency on `muted_topics_ui.js`. --- web/src/click_handlers.js | 9 ++++----- web/src/muted_topics_ui.js | 6 ------ web/src/recent_topics_ui.js | 21 ++++++++++++++++----- web/src/user_topics.js | 6 ++++++ 4 files changed, 26 insertions(+), 16 deletions(-) diff --git a/web/src/click_handlers.js b/web/src/click_handlers.js index 69b5d07d52..eaac081660 100644 --- a/web/src/click_handlers.js +++ b/web/src/click_handlers.js @@ -22,7 +22,6 @@ import * as hashchange from "./hashchange"; import * as message_edit from "./message_edit"; import * as message_lists from "./message_lists"; import * as message_store from "./message_store"; -import * as muted_topics_ui from "./muted_topics_ui"; import * as narrow from "./narrow"; import * as navigate from "./navigate"; import {page_params} from "./page_params"; @@ -388,7 +387,7 @@ export function initialize() { // Mute topic in a unmuted stream $("body").on("click", ".message_header .stream_unmuted.on_hover_topic_mute", (e) => { e.stopPropagation(); - muted_topics_ui.mute_or_unmute_topic( + user_topics.set_visibility_policy_for_element( $(e.target), user_topics.all_visibility_policies.MUTED, ); @@ -397,7 +396,7 @@ export function initialize() { // Unmute topic in a unmuted stream $("body").on("click", ".message_header .stream_unmuted.on_hover_topic_unmute", (e) => { e.stopPropagation(); - muted_topics_ui.mute_or_unmute_topic( + user_topics.set_visibility_policy_for_element( $(e.target), user_topics.all_visibility_policies.INHERIT, ); @@ -406,7 +405,7 @@ export function initialize() { // Unmute topic in a muted stream $("body").on("click", ".message_header .stream_muted.on_hover_topic_unmute", (e) => { e.stopPropagation(); - muted_topics_ui.mute_or_unmute_topic( + user_topics.set_visibility_policy_for_element( $(e.target), user_topics.all_visibility_policies.UNMUTED, ); @@ -415,7 +414,7 @@ export function initialize() { // Mute topic in a muted stream $("body").on("click", ".message_header .stream_muted.on_hover_topic_mute", (e) => { e.stopPropagation(); - muted_topics_ui.mute_or_unmute_topic( + user_topics.set_visibility_policy_for_element( $(e.target), user_topics.all_visibility_policies.INHERIT, ); diff --git a/web/src/muted_topics_ui.js b/web/src/muted_topics_ui.js index 64270f6e13..2c393b5011 100644 --- a/web/src/muted_topics_ui.js +++ b/web/src/muted_topics_ui.js @@ -54,9 +54,3 @@ export function toggle_topic_visibility_policy(message) { } } } - -export function mute_or_unmute_topic($elt, visibility_policy) { - const stream_id = Number.parseInt($elt.attr("data-stream-id"), 10); - const topic = $elt.attr("data-topic-name"); - user_topics.set_user_topic_visibility_policy(stream_id, topic, visibility_policy); -} diff --git a/web/src/recent_topics_ui.js b/web/src/recent_topics_ui.js index 3e5d200e0f..3c3439d792 100644 --- a/web/src/recent_topics_ui.js +++ b/web/src/recent_topics_ui.js @@ -17,7 +17,6 @@ import {localstorage} from "./localstorage"; import * as message_store from "./message_store"; import * as message_util from "./message_util"; import * as message_view_header from "./message_view_header"; -import * as muted_topics_ui from "./muted_topics_ui"; import * as muted_users from "./muted_users"; import * as narrow from "./narrow"; import * as narrow_state from "./narrow_state"; @@ -1271,7 +1270,10 @@ export function initialize() { const $elt = $(e.target); const topic_row_index = $elt.closest("tr").index(); focus_clicked_element(topic_row_index, COLUMNS.mute); - muted_topics_ui.mute_or_unmute_topic($elt, user_topics.all_visibility_policies.MUTED); + user_topics.set_visibility_policy_for_element( + $elt, + user_topics.all_visibility_policies.MUTED, + ); }); // Unmute topic in a unmuted stream @@ -1280,7 +1282,10 @@ export function initialize() { const $elt = $(e.target); const topic_row_index = $elt.closest("tr").index(); focus_clicked_element(topic_row_index, COLUMNS.mute); - muted_topics_ui.mute_or_unmute_topic($elt, user_topics.all_visibility_policies.INHERIT); + user_topics.set_visibility_policy_for_element( + $elt, + user_topics.all_visibility_policies.INHERIT, + ); }); // Unmute topic in a muted stream @@ -1289,7 +1294,10 @@ export function initialize() { const $elt = $(e.target); const topic_row_index = $elt.closest("tr").index(); focus_clicked_element(topic_row_index, COLUMNS.mute); - muted_topics_ui.mute_or_unmute_topic($elt, user_topics.all_visibility_policies.UNMUTED); + user_topics.set_visibility_policy_for_element( + $elt, + user_topics.all_visibility_policies.UNMUTED, + ); }); // Mute topic in a muted stream @@ -1298,7 +1306,10 @@ export function initialize() { const $elt = $(e.target); const topic_row_index = $elt.closest("tr").index(); focus_clicked_element(topic_row_index, COLUMNS.mute); - muted_topics_ui.mute_or_unmute_topic($elt, user_topics.all_visibility_policies.INHERIT); + user_topics.set_visibility_policy_for_element( + $elt, + user_topics.all_visibility_policies.INHERIT, + ); }); $("body").on("click", "#recent_topics_search", (e) => { diff --git a/web/src/user_topics.js b/web/src/user_topics.js index ad6650d00d..1399bfbaf0 100644 --- a/web/src/user_topics.js +++ b/web/src/user_topics.js @@ -136,6 +136,12 @@ export function set_user_topic_visibility_policy( }); } +export function set_visibility_policy_for_element($elt, visibility_policy) { + const stream_id = Number.parseInt($elt.attr("data-stream-id"), 10); + const topic = $elt.attr("data-topic-name"); + set_user_topic_visibility_policy(stream_id, topic, visibility_policy); +} + export function set_user_topic(user_topic) { const stream_id = user_topic.stream_id; const topic = user_topic.topic_name;