mirror of
https://github.com/zulip/zulip.git
synced 2025-10-24 16:43:57 +00:00
This fixes the most core data structures inside of muting.js. We still use stream names for incoming data to set_muted_topics and outgoing data from get_muted_topics. This will make us more resilient to stream name changes. Before, if you were logged on when a stream rename occured, topics that were muted under that stream would appear to be unmuted. (You could fix it with a reload, but it can be jarring to have a bunch of unread messages appear in your feed suddenly.) Fixes #11033
70 lines
1.7 KiB
JavaScript
70 lines
1.7 KiB
JavaScript
var muting = (function () {
|
|
|
|
var exports = {};
|
|
|
|
var muted_topics = new Dict();
|
|
|
|
exports.add_muted_topic = function (stream_id, topic) {
|
|
var sub_dict = muted_topics.get(stream_id);
|
|
if (!sub_dict) {
|
|
sub_dict = new Dict({fold_case: true});
|
|
muted_topics.set(stream_id, sub_dict);
|
|
}
|
|
sub_dict.set(topic, true);
|
|
};
|
|
|
|
exports.remove_muted_topic = function (stream_id, topic) {
|
|
var sub_dict = muted_topics.get(stream_id);
|
|
if (sub_dict) {
|
|
sub_dict.del(topic);
|
|
}
|
|
};
|
|
|
|
exports.is_topic_muted = function (stream_id, topic) {
|
|
if (stream_id === undefined) {
|
|
return false;
|
|
}
|
|
var sub_dict = muted_topics.get(stream_id);
|
|
return sub_dict && sub_dict.get(topic);
|
|
};
|
|
|
|
exports.get_muted_topics = function () {
|
|
var topics = [];
|
|
muted_topics.each(function (sub_dict, stream_id) {
|
|
_.each(sub_dict.keys(), function (topic) {
|
|
// TODO: make it so that callees can work w/stream_id
|
|
var stream_name = stream_data.maybe_get_stream_name(stream_id);
|
|
|
|
if (stream_name) {
|
|
topics.push([stream_name, topic]);
|
|
}
|
|
});
|
|
});
|
|
return topics;
|
|
};
|
|
|
|
exports.set_muted_topics = function (tuples) {
|
|
muted_topics = new Dict();
|
|
|
|
_.each(tuples, function (tuple) {
|
|
var stream_name = tuple[0];
|
|
var topic = tuple[1];
|
|
|
|
var stream_id = stream_data.get_stream_id(stream_name);
|
|
|
|
if (!stream_id) {
|
|
blueslip.warn('Unknown stream in set_muted_topics: ' + stream_name);
|
|
return;
|
|
}
|
|
|
|
exports.add_muted_topic(stream_id, topic);
|
|
});
|
|
};
|
|
|
|
return exports;
|
|
}());
|
|
if (typeof module !== 'undefined') {
|
|
module.exports = muting;
|
|
}
|
|
window.muting = muting;
|