Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
user_topics: Rename and refactor 'get_muted_topics'.
Prakhar Pratyushba3867bed631
diff --git a/web/src/muted_topics_ui.js b/web/src/muted_topics_ui.jsindex 5f6e94e67a3..4e79351cf0b 100644--- a/web/src/muted_topics_ui.js+++ b/web/src/muted_topics_ui.js@@ -23,7 +23,9 @@ export function rerender_for_muted_topic(old_muted_topics) {// We only update those topics which could have been affected, because// we want to avoid doing a complete rerender of the recent topics view,// because that can be expensive.- const current_muted_topics = user_topics.get_muted_topics();+ const current_muted_topics = user_topics.get_user_topics_for_visibility_policy(+ user_topics.all_visibility_policies.MUTED,+ );const maybe_affected_topics = _.unionWith(old_muted_topics, current_muted_topics, _.isEqual);for (const topic_data of maybe_affected_topics) {@@ -32,7 +34,9 @@ export function rerender_for_muted_topic(old_muted_topics) {}export function handle_topic_updates(user_topic) {- const old_muted_topics = user_topics.get_muted_topics();+ const old_muted_topics = user_topics.get_user_topics_for_visibility_policy(+ user_topics.all_visibility_policies.MUTED,+ );user_topics.set_user_topic(user_topic);popover_menus.get_topic_menu_popover()?.hide();unread_ui.update_unread_counts();diff --git a/web/src/settings_muted_topics.js b/web/src/settings_muted_topics.jsindex 4cfb8fe9a8f..2a6e8815ec5 100644--- a/web/src/settings_muted_topics.js+++ b/web/src/settings_muted_topics.js@@ -9,7 +9,9 @@ import * as user_topics from "./user_topics";export let loaded = false;export function populate_list() {- const all_muted_topics = user_topics.get_muted_topics();+ const all_muted_topics = user_topics.get_user_topics_for_visibility_policy(+ user_topics.all_visibility_policies.MUTED,+ );const $muted_topics_table = $("#muted_topics_table");const $search_input = $("#muted_topics_search");diff --git a/web/src/user_topics.js b/web/src/user_topics.jsindex 2a3931bc3c0..ead71545166 100644--- a/web/src/user_topics.js+++ b/web/src/user_topics.js@@ -53,20 +53,20 @@ export function is_topic_muted(stream_id, topic) {return get_topic_visibility_policy(stream_id, topic) === all_visibility_policies.MUTED;}-export function get_muted_topics() {+export function get_user_topics_for_visibility_policy(visibility_policy) {const topics = [];for (const [stream_id, sub_dict] of all_user_topics) {const stream = stream_data.maybe_get_stream_name(stream_id);for (const topic of sub_dict.keys()) {- if (sub_dict.get(topic).visibility_policy === all_visibility_policies.MUTED) {- const date_muted = sub_dict.get(topic).date_updated;- const date_muted_str = timerender.render_now(new Date(date_muted)).time_str;+ if (sub_dict.get(topic).visibility_policy === visibility_policy) {+ const date_updated = sub_dict.get(topic).date_updated;+ const date_updated_str = timerender.render_now(new Date(date_updated)).time_str;topics.push({stream_id,stream,topic,- date_muted,- date_muted_str,+ date_updated,+ date_updated_str,});}}diff --git a/web/templates/muted_topic_ui_row.hbs b/web/templates/muted_topic_ui_row.hbsindex a298f477714..1e995a3858f 100644--- a/web/templates/muted_topic_ui_row.hbs+++ b/web/templates/muted_topic_ui_row.hbs@@ -1,8 +1,8 @@{{#with muted_topic}}-<tr data-stream-id="{{stream_id}}" data-stream="{{stream}}" data-topic="{{topic}}" data-date-muted="{{date_muted_str}}">+<tr data-stream-id="{{stream_id}}" data-stream="{{stream}}" data-topic="{{topic}}" data-date-muted="{{date_updated_str}}"><td>{{stream}}</td><td>{{topic}}</td>- <td class="topic_date_muted">{{date_muted_str}}</td>+ <td class="topic_date_muted">{{date_updated_str}}</td><td class="actions"><span><a class="settings-unmute-topic">{{t "Unmute" }}</a></span></td>diff --git a/web/tests/settings_muted_topics.test.js b/web/tests/settings_muted_topics.test.jsindex c2079655e5f..7c4de3ae9c5 100644--- a/web/tests/settings_muted_topics.test.js+++ b/web/tests/settings_muted_topics.test.js@@ -31,8 +31,8 @@ run_test("settings", ({override}) => {override(list_widget, "create", ($container, list) => {assert.deepEqual(list, [{- date_muted: 1577836800000,- date_muted_str: "Jan 1, 2020",+ date_updated: 1577836800000,+ date_updated_str: "Jan 1, 2020",stream: frontend.name,stream_id: frontend.stream_id,topic: "js",diff --git a/web/tests/user_topics.test.js b/web/tests/user_topics.test.jsindex 13e26625f4c..4e65536c6b7 100644--- a/web/tests/user_topics.test.js+++ b/web/tests/user_topics.test.js@@ -97,7 +97,12 @@ test("add_and_remove_unmutes", () => {});test("get_mutes", () => {- assert.deepEqual(user_topics.get_muted_topics(), []);+ assert.deepEqual(+ user_topics.get_user_topics_for_visibility_policy(+ user_topics.all_visibility_policies.MUTED,+ ),+ [],+ );user_topics.update_user_topics(office.stream_id,"gossip",@@ -111,20 +116,20 @@ test("get_mutes", () => {1577836700,);const all_muted_topics = user_topics- .get_muted_topics()- .sort((a, b) => a.date_muted - b.date_muted);+ .get_user_topics_for_visibility_policy(user_topics.all_visibility_policies.MUTED)+ .sort((a, b) => a.date_updated - b.date_updated);assert.deepEqual(all_muted_topics, [{- date_muted: 1577836700000,- date_muted_str: "Dec 31, 2019",+ date_updated: 1577836700000,+ date_updated_str: "Dec 31, 2019",stream: devel.name,stream_id: devel.stream_id,topic: "java",},{- date_muted: 1577836800000,- date_muted_str: "Jan 1, 2020",+ date_updated: 1577836800000,+ date_updated_str: "Jan 1, 2020",stream: office.name,stream_id: office.stream_id,topic: "gossip",@@ -162,22 +167,27 @@ test("set_user_topics", () => {user_topics.initialize();- assert.deepEqual(user_topics.get_muted_topics().sort(), [- {- date_muted: 1577836800000,- date_muted_str: "Jan 1, 2020",- stream: social.name,- stream_id: social.stream_id,- topic: "breakfast",- },- {- date_muted: 1577836800000,- date_muted_str: "Jan 1, 2020",- stream: design.name,- stream_id: design.stream_id,- topic: "typography",- },- ]);+ assert.deepEqual(+ user_topics+ .get_user_topics_for_visibility_policy(user_topics.all_visibility_policies.MUTED)+ .sort(),+ [+ {+ date_updated: 1577836800000,+ date_updated_str: "Jan 1, 2020",+ stream: social.name,+ stream_id: social.stream_id,+ topic: "breakfast",+ },+ {+ date_updated: 1577836800000,+ date_updated_str: "Jan 1, 2020",+ stream: design.name,+ stream_id: design.stream_id,+ topic: "typography",+ },+ ],+ );user_topics.set_user_topic({stream_id: design.stream_id,