2013-08-20 22:05:56 +02:00
|
|
|
var muting = (function () {
|
|
|
|
|
|
|
|
var exports = {};
|
|
|
|
|
2017-05-17 15:50:48 +02:00
|
|
|
var muted_topics = new Dict({fold_case: true});
|
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-17 15:50:48 +02:00
|
|
|
var sub_dict = muted_topics.get(stream);
|
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-17 15:50:48 +02:00
|
|
|
muted_topics.set(stream, 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-17 15:50:48 +02:00
|
|
|
var sub_dict = muted_topics.get(stream);
|
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-17 15:50:48 +02:00
|
|
|
var sub_dict = muted_topics.get(stream);
|
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-17 15:50:48 +02:00
|
|
|
muted_topics.each(function (sub_dict, stream) {
|
2013-09-10 17:01:38 +02:00
|
|
|
_.each(sub_dict.keys(), function (topic) {
|
2017-05-17 15:50:48 +02:00
|
|
|
topics.push([stream, 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-17 15:50:48 +02:00
|
|
|
muted_topics = new Dict({fold_case: true});
|
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;
|
|
|
|
}
|
2018-05-28 08:04:36 +02:00
|
|
|
window.muting = muting;
|