From 04cdc896810bf16cf7c649bb87b775ed8583d4fe Mon Sep 17 00:00:00 2001 From: Aman Agrawal Date: Fri, 15 May 2020 17:57:36 +0530 Subject: [PATCH] recent_topics: Handle mute/unmute update to topic. * We don't remove topic data when it's muted. We will filter it before rendering. --- frontend_tests/node_tests/recent_topics.js | 13 +++++++++++++ static/js/muting_ui.js | 2 ++ static/js/recent_topics.js | 9 +++++++++ 3 files changed, 24 insertions(+) diff --git a/frontend_tests/node_tests/recent_topics.js b/frontend_tests/node_tests/recent_topics.js index e127f568e6..dfc395df7f 100644 --- a/frontend_tests/node_tests/recent_topics.js +++ b/frontend_tests/node_tests/recent_topics.js @@ -207,4 +207,17 @@ run_test('basic assertions', () => { assert.equal(Array.from(all_topics.keys()).toString(), '1:topic-7,1:topic-3,1:topic-1,1:topic-6,1:topic-5,1:topic-4,1:topic-2'); verify_topic_data(all_topics, stream1, topic7, id, true, 0, true); + + // unmute topic7 + rt.update_topic_is_muted(stream1, topic7, false); + all_topics = rt.get(); + verify_topic_data(all_topics, stream1, topic7, id, true, 0, false); + + // mute topic7 + rt.update_topic_is_muted(stream1, topic7, true); + all_topics = rt.get(); + verify_topic_data(all_topics, stream1, topic7, id, true, 0, true); + + // a topic gets muted which we are not tracking + assert.equal(rt.update_topic_is_muted(stream1, "topic-10", true), false); }); diff --git a/static/js/muting_ui.js b/static/js/muting_ui.js index 7307afa4a7..15176a9407 100644 --- a/static/js/muting_ui.js +++ b/static/js/muting_ui.js @@ -112,6 +112,7 @@ exports.mute = function (stream_id, topic) { title_text: i18n.t("Topic muted"), undo_button_text: i18n.t("Unmute"), }); + recent_topics.update_topic_is_muted(stream_id, topic, true); }; exports.unmute = function (stream_id, topic) { @@ -124,6 +125,7 @@ exports.unmute = function (stream_id, topic) { exports.rerender(); exports.persist_unmute(stream_id, topic); feedback_widget.dismiss(); + recent_topics.update_topic_is_muted(stream_id, topic, false); }; exports.toggle_mute = function (message) { diff --git a/static/js/recent_topics.js b/static/js/recent_topics.js index d8dbfba896..a7169d6b8a 100644 --- a/static/js/recent_topics.js +++ b/static/js/recent_topics.js @@ -34,6 +34,15 @@ exports.process_message = function (msg) { return true; }; +exports.update_topic_is_muted = function (stream_id, topic, is_muted) { + const key = stream_id + ":" + topic; + if (!topics.has(key)) { + return false; + } + const topic_data = topics.get(stream_id + ":" + topic); + topic_data.muted = is_muted; +}; + function get_sorted_topics() { // Sort all recent topics by last message time. return new Map(Array.from(topics.entries()).sort(function (a, b) {