diff --git a/static/js/muting.js b/static/js/muting.js index 49161225e7..3c40b698c0 100644 --- a/static/js/muting.js +++ b/static/js/muting.js @@ -25,6 +25,16 @@ exports.is_topic_muted = function (stream, topic) { return sub_dict && sub_dict.get(topic); }; +exports.get_muted_topics = function () { + var topics = []; + muted_topics.each(function (sub_dict, stream) { + _.each(sub_dict.keys(), function (topic) { + topics.push([stream, topic]); + }); + }); + return topics; +}; + return exports; }()); if (typeof module !== 'undefined') { diff --git a/zerver/tests/frontend/node/muting.js b/zerver/tests/frontend/node/muting.js index 7aa58153ec..5b5aa403b5 100644 --- a/zerver/tests/frontend/node/muting.js +++ b/zerver/tests/frontend/node/muting.js @@ -30,5 +30,14 @@ var muting = require('js/muting.js'); // test unknown stream is harmless too muting.unmute_topic('unknown', 'java'); assert(!muting.is_topic_muted('unknown', 'java')); - +}()); + +(function test_get_muted_topics() { + assert.deepEqual(muting.get_muted_topics(), []); + muting.mute_topic('office', 'gossip'); + muting.mute_topic('devel', 'java'); + assert.deepEqual(muting.get_muted_topics().sort(), [ + ['devel', 'java'], + ['office', 'gossip'] + ]); }());