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', {});
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));

View File

@ -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];