From 7d153c9f8ac3e9c128cfeea73585f0a4a7ca9825 Mon Sep 17 00:00:00 2001 From: Steve Howell Date: Wed, 17 May 2017 06:50:48 -0700 Subject: [PATCH] Revert "muting.js: Track muted streams using stream id." This reverts commit c7f710b8d4430942797229d699c4b8775c2d3885. Because the back end still stores muted topics fundamentally using stream name as a key, trying to cut over the client to use stream id was just making things more brittle. Mutes would work after renaming the stream, which was progress in the change that we revert here, but only until page load. The other problem, which is more severe, is that the order of page loading functions would cause no mutes to happen at page load time. This could be fixed to some degree, but we should do a deeper fix on the back end. --- frontend_tests/node_tests/muting.js | 16 +---------- static/js/muting.js | 43 ++++++----------------------- 2 files changed, 9 insertions(+), 50 deletions(-) diff --git a/frontend_tests/node_tests/muting.js b/frontend_tests/node_tests/muting.js index 15207b8440..e4ef949a95 100644 --- a/frontend_tests/node_tests/muting.js +++ b/frontend_tests/node_tests/muting.js @@ -1,24 +1,10 @@ set_global('page_params', {}); add_dependencies({ - stream_data: 'js/stream_data', - unread: 'js/unread', -}); - -set_global('blueslip', { - warn: function () {}, + unread: 'js/unread.js', }); var muting = require('js/muting.js'); -function make_sub(name, stream_id) { - global.stream_data.add_sub(name, {stream_id: stream_id, name: name}); -} - -make_sub('devel', 1); -make_sub('office', 2); -make_sub('social', 3); -make_sub('design', 4); - (function test_edge_cases() { // private messages assert(!muting.is_topic_muted(undefined, undefined)); diff --git a/static/js/muting.js b/static/js/muting.js index 8d2ce25701..617f302ab5 100644 --- a/static/js/muting.js +++ b/static/js/muting.js @@ -2,32 +2,19 @@ var muting = (function () { var exports = {}; -var muted_topics = new Dict(); +var muted_topics = new Dict({fold_case: true}); exports.add_muted_topic = function (stream, topic) { - var stream_id = stream_data.get_stream_id(stream); - - if (!stream_id) { - return; - } - - var sub_dict = muted_topics.get(stream_id); + var sub_dict = muted_topics.get(stream); if (!sub_dict) { sub_dict = new Dict({fold_case: true}); - muted_topics.set(stream_id, sub_dict); + muted_topics.set(stream, sub_dict); } sub_dict.set(topic, true); }; exports.remove_muted_topic = function (stream, topic) { - var stream_id = stream_data.get_stream_id(stream); - - if (!stream_id) { - blueslip.warn('cannot unmute stream ' + stream); - return; - } - - var sub_dict = muted_topics.get(stream_id); + var sub_dict = muted_topics.get(stream); if (sub_dict) { sub_dict.del(topic); } @@ -37,36 +24,22 @@ exports.is_topic_muted = function (stream, topic) { if (stream === undefined) { return false; } - - var stream_id = stream_data.get_stream_id(stream); - - if (!stream_id) { - return false; - } - - var sub_dict = muted_topics.get(stream_id); + var sub_dict = muted_topics.get(stream); return sub_dict && sub_dict.get(topic); }; exports.get_muted_topics = function () { var topics = []; - muted_topics.each(function (sub_dict, stream_id) { - var sub = stream_data.get_sub_by_id(stream_id); - - if (!sub) { - blueslip.error('cannot find stream ' + stream_id); - return; - } - + muted_topics.each(function (sub_dict, stream) { _.each(sub_dict.keys(), function (topic) { - topics.push([sub.name, topic]); + topics.push([stream, topic]); }); }); return topics; }; exports.set_muted_topics = function (tuples) { - muted_topics = new Dict(); + muted_topics = new Dict({fold_case: true}); _.each(tuples, function (tuple) { var stream = tuple[0];