Files
zulip/static/js/muting.js
Steve Howell a4c80089f3 page load: Fix two bugs related to muting/unreads.
The first bug fixed here has been around for a long
time--we were redundantly updating unread counts
indirectly via muting_ui.initialize(). The
unread counts also get updated in
unread_ui.initialize(), when we have more valid
state.  (And it's worth noting here that the unread
counts get updated yet again once message fetches
complete.)

The second bug was a very recent regression from
my recent stream name -> stream id cleanup in the
muting system.  We now depend on stream_data to
initialize muting data, so we need to initialize
muting.js slightly later in the process.

These fixes are intertwined, because they were both
somewhat caused by the anti-pattern of having
muting_ui.js initialize unread_ui.js and muting.js,
instead of doing more direct, fine-grained initialization
from ui_init.js.

Essentially we replace this code:

    exports.update_muted_topics = function (muted_topics) {
        muting.set_muted_topics(muted_topics);
        unread_ui.update_unread_counts();
    };

with this:

    exports.initialize = function () {
        exports.set_muted_topics(page_params.muted_topics);
    };

And the modules load like this:

    stream_data
    ...
    muting
    ...
    unread_ui

And we don't need any page-load initialization for muting_ui,
which is mostly used for Settings/Muted topics.
2018-12-15 13:44:30 -08:00

69 lines
1.6 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) {
topics.push([stream_id, 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);
});
};
exports.initialize = function () {
exports.set_muted_topics(page_params.muted_topics);
};
return exports;
}());
if (typeof module !== 'undefined') {
module.exports = muting;
}
window.muting = muting;