From ec927416a0570d86540a2b44a9fab90608ceb99e Mon Sep 17 00:00:00 2001 From: Kevin Mehall Date: Mon, 5 Aug 2013 14:15:35 -0400 Subject: [PATCH] Move "already read" check into process_read_messages and rename it. Functions were supposed to check that messages were unread before passing them to process_read_messages, but some didn't. The `mark_messages_as_read` function was essentially that, so take that name. (imported from commit 2917fe30d2defb8a047ec32e1bc70d379779276b) --- static/js/zulip.js | 34 ++++++++++++---------------------- 1 file changed, 12 insertions(+), 22 deletions(-) diff --git a/static/js/zulip.js b/static/js/zulip.js index 20777b3553..95daba7601 100644 --- a/static/js/zulip.js +++ b/static/js/zulip.js @@ -330,11 +330,16 @@ function process_loaded_for_unread(messages) { } // Takes a list of messages and marks them as read -function process_read_messages(messages, options) { +function mark_messages_as_read(messages, options) { options = options || {}; var processed = []; _.each(messages, function (message) { + if (!unread.message_unread(message)) { + // Don't do anything if the message is already read. + return; + } + message.flags = message.flags || []; message.flags.push('read'); @@ -358,7 +363,6 @@ function process_read_messages(messages, options) { if (narrowed_msg_list) { narrowed_msg_list.show_message_as_read(message, options); } - }); if (processed.length > 0) { @@ -369,9 +373,12 @@ function process_read_messages(messages, options) { } queued_flag_timer = setTimeout(send_queued_flags, 1000); + update_unread_counts(); } +} - update_unread_counts(); +function mark_message_as_read(message, options) { + mark_messages_as_read([message], options); } // If we ever materially change the algorithm for this function, we @@ -386,29 +393,12 @@ function process_visible_unread_messages(update_cursor) { mark_current_list_as_read(); } } else { - var visible_messages = viewport.visible_messages(); - var mark_as_read = _.filter(visible_messages, unread.message_unread); - - if (mark_as_read.length > 0) { - process_read_messages(mark_as_read); - } + mark_messages_as_read(viewport.visible_messages()); } } -function mark_messages_as_read(msg_list, options) { - var unread_msgs = _.filter(msg_list, unread.message_unread); - process_read_messages(unread_msgs, options); -} - function mark_current_list_as_read(options) { - var unread_msgs = _.filter(current_msg_list.all(), unread.message_unread); - process_read_messages(unread_msgs, options); -} - -function mark_message_as_read(message, options) { - // This seems like a rather pointless wrapper, but - // process_read_messages() should stay as an internal API. - process_read_messages([message], options); + mark_messages_as_read(current_msg_list.all(), options); } function respond_to_message(opts) {