refactor: Add unread.get_unread_message{_ids}().

This adds two similar functions to simplify
our batch processing of unread messages.

    unread.get_unread_messages
    unread.get_unread_message_ids

They are used to simplify two functions that loop
over messages.  Before this change, the functions
would short circuit the loop to ignore messages
that were already read; now they just use the
helpers before the loop.
This commit is contained in:
Steve Howell
2017-12-16 10:53:27 -05:00
committed by showell
parent a8cd7655d3
commit a1b221730b
3 changed files with 29 additions and 24 deletions

View File

@@ -333,8 +333,14 @@ exports.message_unread = function (message) {
message.flags.indexOf('read') === -1;
};
exports.id_flagged_as_unread = function (message_id) {
return unread_messages.has(message_id);
exports.get_unread_message_ids = function (message_ids) {
return _.filter(message_ids, unread_messages.has);
};
exports.get_unread_messages = function (message) {
return _.filter(message, function (message) {
return unread_messages.has(message.id);
});
};
exports.update_unread_topics = function (msg, event) {