mirror of
https://github.com/zulip/zulip.git
synced 2025-11-06 15:03:34 +00:00
Move unread-related functions from zulip.js to unread.js.
(imported from commit efc0dd84c2cd30b0203b906af6991475d8a63985)
This commit is contained in:
@@ -171,6 +171,105 @@ exports.num_unread_for_person = function (email) {
|
||||
return unread_privates.get(email).num_items();
|
||||
};
|
||||
|
||||
exports.update_unread_counts = function () {
|
||||
if (suppress_unread_counts) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Pure computation:
|
||||
var res = unread.get_counts();
|
||||
|
||||
// Side effects from here down:
|
||||
// This updates some DOM elements directly, so try to
|
||||
// avoid excessive calls to this.
|
||||
stream_list.update_dom_with_unread_counts(res);
|
||||
notifications.update_title_count(res.home_unread_messages);
|
||||
notifications.update_pm_count(res.private_message_count);
|
||||
notifications_bar.update(res.home_unread_messages);
|
||||
};
|
||||
|
||||
exports.enable = function enable() {
|
||||
suppress_unread_counts = false;
|
||||
exports.update_unread_counts();
|
||||
};
|
||||
|
||||
exports.mark_all_as_read = function mark_all_as_read(cont) {
|
||||
_.each(all_msg_list.all(), function (msg) {
|
||||
msg.flags = msg.flags || [];
|
||||
msg.flags.push('read');
|
||||
});
|
||||
unread.declare_bankruptcy();
|
||||
exports.update_unread_counts();
|
||||
|
||||
channel.post({
|
||||
url: '/json/update_message_flags',
|
||||
idempotent: true,
|
||||
data: {messages: JSON.stringify([]),
|
||||
all: true,
|
||||
op: 'add',
|
||||
flag: 'read'},
|
||||
success: cont});
|
||||
};
|
||||
|
||||
// Takes a list of messages and marks them as read
|
||||
exports.mark_messages_as_read = function mark_messages_as_read (messages, options) {
|
||||
options = options || {};
|
||||
var processed = false;
|
||||
|
||||
_.each(messages, function (message) {
|
||||
if (!unread.message_unread(message)) {
|
||||
// Don't do anything if the message is already read.
|
||||
return;
|
||||
}
|
||||
if (current_msg_list === narrowed_msg_list) {
|
||||
unread_messages_read_in_narrow = true;
|
||||
}
|
||||
|
||||
if (options.from !== "server") {
|
||||
message_flags.send_read(message);
|
||||
}
|
||||
summary.maybe_mark_summarized(message);
|
||||
|
||||
message.unread = false;
|
||||
unread.process_read_message(message, options);
|
||||
home_msg_list.show_message_as_read(message, options);
|
||||
all_msg_list.show_message_as_read(message, options);
|
||||
if (narrowed_msg_list) {
|
||||
narrowed_msg_list.show_message_as_read(message, options);
|
||||
}
|
||||
notifications.close_notification(message);
|
||||
processed = true;
|
||||
});
|
||||
|
||||
if (processed) {
|
||||
exports.update_unread_counts();
|
||||
}
|
||||
};
|
||||
|
||||
exports.mark_message_as_read = function mark_message_as_read(message, options) {
|
||||
exports.mark_messages_as_read([message], options);
|
||||
};
|
||||
|
||||
// If we ever materially change the algorithm for this function, we
|
||||
// may need to update notifications.received_messages as well.
|
||||
exports.process_visible = function process_visible(update_cursor) {
|
||||
if (! notifications.window_has_focus()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (feature_flags.mark_read_at_bottom) {
|
||||
if (viewport.bottom_message_visible()) {
|
||||
exports.mark_current_list_as_read();
|
||||
}
|
||||
} else {
|
||||
exports.mark_messages_as_read(viewport.visible_messages(true));
|
||||
}
|
||||
};
|
||||
|
||||
exports.mark_current_list_as_read = function mark_current_list_as_read(options) {
|
||||
exports.mark_messages_as_read(current_msg_list.all(), options);
|
||||
};
|
||||
|
||||
return exports;
|
||||
}());
|
||||
if (typeof module !== 'undefined') {
|
||||
|
||||
Reference in New Issue
Block a user