2013-08-20 22:05:56 +02:00
|
|
|
var muting = (function () {
|
|
|
|
|
|
|
|
var exports = {};
|
|
|
|
|
2013-09-10 21:33:59 +02:00
|
|
|
var muted_topics = new Dict({fold_case: true});
|
2013-08-20 22:05:56 +02:00
|
|
|
|
2017-02-08 10:45:21 +01:00
|
|
|
function set_muted_topic(stream, topic) {
|
2013-08-20 22:05:56 +02:00
|
|
|
var sub_dict = muted_topics.get(stream);
|
|
|
|
if (!sub_dict) {
|
2013-09-10 21:33:59 +02:00
|
|
|
sub_dict = new Dict({fold_case: true});
|
2013-08-20 22:05:56 +02:00
|
|
|
muted_topics.set(stream, sub_dict);
|
|
|
|
}
|
|
|
|
sub_dict.set(topic, true);
|
2017-02-08 10:45:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
exports.mute_topic = function (stream, topic) {
|
|
|
|
set_muted_topic(stream, topic);
|
2016-03-24 13:51:14 +01:00
|
|
|
unread.update_unread_counts();
|
2013-08-20 22:05:56 +02:00
|
|
|
};
|
|
|
|
|
2013-09-09 20:33:25 +02:00
|
|
|
exports.unmute_topic = function (stream, topic) {
|
|
|
|
var sub_dict = muted_topics.get(stream);
|
|
|
|
if (sub_dict) {
|
|
|
|
sub_dict.del(topic);
|
|
|
|
}
|
2016-03-24 13:51:14 +01:00
|
|
|
unread.update_unread_counts();
|
2013-09-09 20:33:25 +02:00
|
|
|
};
|
|
|
|
|
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;
|
|
|
|
}
|
2013-08-20 22:05:56 +02:00
|
|
|
var sub_dict = muted_topics.get(stream);
|
|
|
|
return sub_dict && sub_dict.get(topic);
|
|
|
|
};
|
|
|
|
|
2013-09-10 17:01:38 +02:00
|
|
|
exports.get_muted_topics = function () {
|
|
|
|
var topics = [];
|
|
|
|
muted_topics.each(function (sub_dict, stream) {
|
|
|
|
_.each(sub_dict.keys(), function (topic) {
|
|
|
|
topics.push([stream, topic]);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
return topics;
|
|
|
|
};
|
|
|
|
|
2013-09-10 20:34:41 +02:00
|
|
|
exports.set_muted_topics = function (tuples) {
|
2013-09-10 21:33:59 +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-08 10:45:21 +01:00
|
|
|
set_muted_topic(stream, topic);
|
2013-09-10 20:34:41 +02:00
|
|
|
});
|
2017-02-08 10:45:21 +01:00
|
|
|
unread.update_unread_counts();
|
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;
|
|
|
|
}
|