forked from zulip/zulip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmuting.js
56 lines (46 loc) · 1.28 KB
/
muting.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
var muting = (function () {
var exports = {};
var muted_topics = new Dict({fold_case: true});
exports.add_muted_topic = function (stream, topic) {
var sub_dict = muted_topics.get(stream);
if (!sub_dict) {
sub_dict = new Dict({fold_case: true});
muted_topics.set(stream, sub_dict);
}
sub_dict.set(topic, true);
};
exports.remove_muted_topic = function (stream, topic) {
var sub_dict = muted_topics.get(stream);
if (sub_dict) {
sub_dict.del(topic);
}
};
exports.is_topic_muted = function (stream, topic) {
if (stream === undefined) {
return false;
}
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) {
_.each(sub_dict.keys(), function (topic) {
topics.push([stream, topic]);
});
});
return topics;
};
exports.set_muted_topics = function (tuples) {
muted_topics = new Dict({fold_case: true});
_.each(tuples, function (tuple) {
var stream = tuple[0];
var topic = tuple[1];
exports.add_muted_topic(stream, topic);
});
};
return exports;
}());
if (typeof module !== 'undefined') {
module.exports = muting;
}