2013-08-20 22:05:56 +02:00
|
|
|
var muting = (function () {
|
|
|
|
|
|
|
|
var exports = {};
|
|
|
|
|
2017-05-14 23:35:18 +02:00
|
|
|
var muted_topics = new Dict();
|
2013-08-20 22:05:56 +02:00
|
|
|
|
2017-02-11 09:17:19 +01:00
|
|
|
exports.add_muted_topic = function (stream, topic) {
|
2017-05-14 23:35:18 +02:00
|
|
|
var stream_id = stream_data.get_stream_id(stream);
|
|
|
|
|
|
|
|
if (!stream_id) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var sub_dict = muted_topics.get(stream_id);
|
2013-08-20 22:05:56 +02:00
|
|
|
if (!sub_dict) {
|
2013-09-10 21:33:59 +02:00
|
|
|
sub_dict = new Dict({fold_case: true});
|
2017-05-14 23:35:18 +02:00
|
|
|
muted_topics.set(stream_id, sub_dict);
|
2013-08-20 22:05:56 +02:00
|
|
|
}
|
|
|
|
sub_dict.set(topic, true);
|
|
|
|
};
|
|
|
|
|
2017-02-11 09:17:19 +01:00
|
|
|
exports.remove_muted_topic = function (stream, topic) {
|
2017-05-14 23:35:18 +02:00
|
|
|
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);
|
2013-09-09 20:33:25 +02:00
|
|
|
if (sub_dict) {
|
|
|
|
sub_dict.del(topic);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-08-20 22:05:56 +02:00
|
|
|
exports.is_topic_muted = function (stream, topic) {
|
2013-09-10 22:42:48 +02:00
|
|
|
if (stream === undefined) {
|
|
|
|
return false;
|
|
|
|
}
|
2017-05-14 23:35:18 +02:00
|
|
|
|
|
|
|
var stream_id = stream_data.get_stream_id(stream);
|
|
|
|
|
|
|
|
if (!stream_id) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
var sub_dict = muted_topics.get(stream_id);
|
2013-08-20 22:05:56 +02:00
|
|
|
return sub_dict && sub_dict.get(topic);
|
|
|
|
};
|
|
|
|
|
2013-09-10 17:01:38 +02:00
|
|
|
exports.get_muted_topics = function () {
|
|
|
|
var topics = [];
|
2017-05-14 23:35:18 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2013-09-10 17:01:38 +02:00
|
|
|
_.each(sub_dict.keys(), function (topic) {
|
2017-05-14 23:35:18 +02:00
|
|
|
topics.push([sub.name, topic]);
|
2013-09-10 17:01:38 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
return topics;
|
|
|
|
};
|
|
|
|
|
2013-09-10 20:34:41 +02:00
|
|
|
exports.set_muted_topics = function (tuples) {
|
2017-05-14 23:35:18 +02:00
|
|
|
muted_topics = new Dict();
|
2013-09-10 20:34:41 +02:00
|
|
|
|
|
|
|
_.each(tuples, function (tuple) {
|
|
|
|
var stream = tuple[0];
|
|
|
|
var topic = tuple[1];
|
|
|
|
|
2017-02-11 09:17:19 +01:00
|
|
|
exports.add_muted_topic(stream, topic);
|
2013-09-10 20:34:41 +02:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2013-08-20 22:05:56 +02:00
|
|
|
return exports;
|
|
|
|
}());
|
|
|
|
if (typeof module !== 'undefined') {
|
|
|
|
module.exports = muting;
|
|
|
|
}
|