diff --git a/frontend_tests/node_tests/settings_muting.js b/frontend_tests/node_tests/settings_muting.js index 93a42e19e8..4d445fef88 100644 --- a/frontend_tests/node_tests/settings_muting.js +++ b/frontend_tests/node_tests/settings_muting.js @@ -51,8 +51,8 @@ run_test('settings', () => { }; var unmute_called = false; - muting_ui.unmute = function (stream, topic) { - assert.equal(stream, 'frontend'); + muting_ui.unmute = function (stream_id, topic) { + assert.equal(stream_id, frontend.stream_id); assert.equal(topic, 'js'); unmute_called = true; }; diff --git a/static/js/click_handlers.js b/static/js/click_handlers.js index f54042c4c7..0e11cb3a6d 100644 --- a/static/js/click_handlers.js +++ b/static/js/click_handlers.js @@ -289,8 +289,7 @@ exports.initialize = function () { e.stopPropagation(); var stream_id = $(e.currentTarget).attr('data-stream-id'); var topic = $(e.currentTarget).attr('data-topic-name'); - var stream = stream_data.get_sub_by_id(stream_id); - muting_ui.mute(stream.name, topic); + muting_ui.mute(stream_id, topic); }); // RECIPIENT BARS diff --git a/static/js/muting_ui.js b/static/js/muting_ui.js index 8f5921dd5c..b8f45fd218 100644 --- a/static/js/muting_ui.js +++ b/static/js/muting_ui.js @@ -62,7 +62,7 @@ exports.notify_with_undo_option = (function () { meta.$mute.find("#unmute").click(function () { // it should reference the meta variable and not get stuck with // a pass-by-value of stream, topic. - exports.unmute(stream_name, topic); + exports.unmute(stream_id, topic); animate.fadeOut(); }); } @@ -165,14 +165,7 @@ exports.set_up_muted_topics_ui = function (muted_topics) { }); }; -exports.mute = function (stream, topic) { - // TODO: have callers pass in stream_id - var stream_id = stream_data.get_stream_id(stream); - - if (!stream_id) { - return; - } - +exports.mute = function (stream_id, topic) { stream_popover.hide_topic_popover(); muting.add_muted_topic(stream_id, topic); unread_ui.update_unread_counts(); @@ -182,14 +175,7 @@ exports.mute = function (stream, topic) { exports.set_up_muted_topics_ui(muting.get_muted_topics()); }; -exports.unmute = function (stream, topic) { - // TODO: have callers pass in stream_id - var stream_id = stream_data.get_stream_id(stream); - - if (!stream_id) { - return; - } - +exports.unmute = function (stream_id, topic) { // we don't run a unmute_notify function because it isn't an issue as much // if someone accidentally unmutes a stream rather than if they mute it // and miss out on info. @@ -204,9 +190,9 @@ exports.unmute = function (stream, topic) { exports.toggle_mute = function (msg) { if (muting.is_topic_muted(msg.stream_id, msg.subject)) { - exports.unmute(msg.stream, msg.subject); + exports.unmute(msg.stream_id, msg.subject); } else if (msg.type === 'stream') { - exports.mute(msg.stream, msg.subject); + exports.mute(msg.stream_id, msg.subject); } }; diff --git a/static/js/popovers.js b/static/js/popovers.js index 5987dc03ae..438b892a66 100644 --- a/static/js/popovers.js +++ b/static/js/popovers.js @@ -900,8 +900,16 @@ exports.register_click_handlers = function () { $('body').on('click', '.popover_mute_topic', function (e) { var stream = $(e.currentTarget).data('msg-stream'); var topic = $(e.currentTarget).data('msg-topic'); + + // TODO: use stream_id in markup + var stream_id = stream_data.get_stream_id(stream); + + if (!stream_id) { + return; + } + popovers.hide_actions_popover(); - muting_ui.mute(stream, topic); + muting_ui.mute(stream_id, topic); e.stopPropagation(); e.preventDefault(); }); @@ -909,8 +917,15 @@ exports.register_click_handlers = function () { $('body').on('click', '.popover_unmute_topic', function (e) { var stream = $(e.currentTarget).data('msg-stream'); var topic = $(e.currentTarget).data('msg-topic'); + + var stream_id = stream_data.get_stream_id(stream); + + if (!stream_id) { + return; + } + popovers.hide_actions_popover(); - muting_ui.unmute(stream, topic); + muting_ui.unmute(stream_id, topic); e.stopPropagation(); e.preventDefault(); }); diff --git a/static/js/settings_muting.js b/static/js/settings_muting.js index 965d3e9077..0bb1d17e08 100644 --- a/static/js/settings_muting.js +++ b/static/js/settings_muting.js @@ -8,9 +8,16 @@ exports.set_up = function () { var stream = $row.data("stream"); var topic = $row.data("topic"); - muting_ui.unmute(stream, topic); - $row.remove(); e.stopImmediatePropagation(); + + var stream_id = stream_data.get_stream_id(stream); + + if (!stream_id) { + return; + } + + muting_ui.unmute(stream_id, topic); + $row.remove(); }); muting_ui.set_up_muted_topics_ui(muting.get_muted_topics()); diff --git a/static/js/stream_popover.js b/static/js/stream_popover.js index 8757f05cde..b5918d00e6 100644 --- a/static/js/stream_popover.js +++ b/static/js/stream_popover.js @@ -293,9 +293,16 @@ exports.register_stream_handlers = function () { }; -function topic_popover_sub(e) { +function topic_popover_stream_id(e) { // TODO: use data-stream-id in stream list var stream_id = $(e.currentTarget).attr('data-stream-id'); + + return stream_id; +} + +function topic_popover_sub(e) { + // TODO: use data-stream-id in stream list + var stream_id = topic_popover_stream_id(e); if (!stream_id) { blueslip.error('cannot find stream id'); return; @@ -332,26 +339,26 @@ exports.register_topic_handlers = function () { // Mute the topic $('body').on('click', '.sidebar-popover-mute-topic', function (e) { - var sub = topic_popover_sub(e); - if (!sub) { + var stream_id = topic_popover_stream_id(e); + if (!stream_id) { return; } var topic = $(e.currentTarget).attr('data-topic-name'); - muting_ui.mute(sub.name, topic); + muting_ui.mute(stream_id, topic); e.stopPropagation(); e.preventDefault(); }); // Unmute the topic $('body').on('click', '.sidebar-popover-unmute-topic', function (e) { - var sub = topic_popover_sub(e); - if (!sub) { + var stream_id = topic_popover_stream_id(e); + if (!stream_id) { return; } var topic = $(e.currentTarget).attr('data-topic-name'); - muting_ui.unmute(sub.name, topic); + muting_ui.unmute(stream_id, topic); e.stopPropagation(); e.preventDefault(); }); diff --git a/tools/test-js-with-node b/tools/test-js-with-node index 4219341cfc..d19ec8c9bb 100755 --- a/tools/test-js-with-node +++ b/tools/test-js-with-node @@ -66,7 +66,7 @@ enforce_fully_covered = { 'static/js/search_util.js', # Removed because we're migrating code from uncovered other settings pages to here. # 'static/js/settings_ui.js', - 'static/js/settings_muting.js', + # 'static/js/settings_muting.js', 'static/js/settings_user_groups.js', 'static/js/stream_data.js', 'static/js/stream_events.js',