Revert "muting.js: Track muted streams using stream id."

This reverts commit c7f710b8d4.

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.
This commit is contained in:
Steve Howell 2017-05-17 06:50:48 -07:00
parent 11adbf5783
commit 7d153c9f8a
2 changed files with 9 additions and 50 deletions

View File

@ -1,24 +1,10 @@
set_global('page_params', {}); set_global('page_params', {});
add_dependencies({ add_dependencies({
stream_data: 'js/stream_data', unread: 'js/unread.js',
unread: 'js/unread',
});
set_global('blueslip', {
warn: function () {},
}); });
var muting = require('js/muting.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() { (function test_edge_cases() {
// private messages // private messages
assert(!muting.is_topic_muted(undefined, undefined)); assert(!muting.is_topic_muted(undefined, undefined));

View File

@ -2,32 +2,19 @@ var muting = (function () {
var exports = {}; var exports = {};
var muted_topics = new Dict(); var muted_topics = new Dict({fold_case: true});
exports.add_muted_topic = function (stream, topic) { exports.add_muted_topic = function (stream, topic) {
var stream_id = stream_data.get_stream_id(stream); var sub_dict = muted_topics.get(stream);
if (!stream_id) {
return;
}
var sub_dict = muted_topics.get(stream_id);
if (!sub_dict) { if (!sub_dict) {
sub_dict = new Dict({fold_case: true}); 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); sub_dict.set(topic, true);
}; };
exports.remove_muted_topic = function (stream, topic) { exports.remove_muted_topic = function (stream, topic) {
var stream_id = stream_data.get_stream_id(stream); var sub_dict = muted_topics.get(stream);
if (!stream_id) {
blueslip.warn('cannot unmute stream ' + stream);
return;
}
var sub_dict = muted_topics.get(stream_id);
if (sub_dict) { if (sub_dict) {
sub_dict.del(topic); sub_dict.del(topic);
} }
@ -37,36 +24,22 @@ exports.is_topic_muted = function (stream, topic) {
if (stream === undefined) { if (stream === undefined) {
return false; return false;
} }
var sub_dict = muted_topics.get(stream);
var stream_id = stream_data.get_stream_id(stream);
if (!stream_id) {
return false;
}
var sub_dict = muted_topics.get(stream_id);
return sub_dict && sub_dict.get(topic); return sub_dict && sub_dict.get(topic);
}; };
exports.get_muted_topics = function () { exports.get_muted_topics = function () {
var topics = []; var topics = [];
muted_topics.each(function (sub_dict, stream_id) { muted_topics.each(function (sub_dict, stream) {
var sub = stream_data.get_sub_by_id(stream_id);
if (!sub) {
blueslip.error('cannot find stream ' + stream_id);
return;
}
_.each(sub_dict.keys(), function (topic) { _.each(sub_dict.keys(), function (topic) {
topics.push([sub.name, topic]); topics.push([stream, topic]);
}); });
}); });
return topics; return topics;
}; };
exports.set_muted_topics = function (tuples) { exports.set_muted_topics = function (tuples) {
muted_topics = new Dict(); muted_topics = new Dict({fold_case: true});
_.each(tuples, function (tuple) { _.each(tuples, function (tuple) {
var stream = tuple[0]; var stream = tuple[0];