Call process_loaded_for_unread() more directly.

This is a prefactoring to eventually eliminate the home_unread_messages
global variable.  More commits to follow.

In order to set up process_loaded_for_unread() not to modify
global variable to get its job done, we want to pull it out of
add_messages(), so that add_messages() doesn't have to pass back
state to the 9 different places in the codebase where it's called.
There are only 2 places where process_loaded_for_unread() get
called after this commit.

In order to facilitate pulling up process_loaded_for_unread(), I
made it so that the contract for add_messages() was to accept
already-hydrated messages.  This way I could hydrate the messages
before calling process_loaded_for_unread() without have to
worry about double-caching them in add_messages.  This will
slightly improve performance, but it was mostly done for code
clarity.

(imported from commit ad5aaad5b1f22c31647370f4c9dcb5f89d7d99a7)
This commit is contained in:
Steve Howell 2013-05-13 15:57:13 -04:00
parent b8e1809f94
commit f024a7ab14
2 changed files with 10 additions and 10 deletions

View File

@ -44,6 +44,7 @@ var globals =
+ ' process_visible_unread_messages message_range message_in_table process_loaded_for_unread'
+ ' mark_all_as_read message_unread process_read_messages unread_in_current_view'
+ ' fast_forward_pointer recent_subjects unread_subjects'
+ ' add_message_metadata'
;

View File

@ -662,16 +662,11 @@ function add_messages(messages, msg_list) {
util.destroy_loading_indicator($('#page_loading_indicator'));
util.destroy_first_run_message();
messages = $.map(messages, add_message_metadata);
if (add_messages_helper(messages, msg_list, msg_list.filter.predicate())) {
prepended = true;
}
if (msg_list === all_msg_list) {
process_loaded_for_unread(messages);
}
if ((msg_list === narrowed_msg_list) && !msg_list.empty() &&
(msg_list.selected_id() === -1)) {
// If adding some new messages to the message tables caused
@ -745,6 +740,7 @@ function maybe_add_narrowed_messages(messages, msg_list) {
}
});
new_messages = $.map(new_messages, add_message_metadata);
add_messages(new_messages, msg_list);
process_visible_unread_messages();
compose.update_faded_messages();
@ -848,13 +844,13 @@ function get_updates(options) {
// server update. Once that bug is fixed, this
// should no longer be needed
messages = deduplicate_messages(messages);
messages = $.map(messages, add_message_metadata);
// Our unread counts infrastructure (which runs when
// we add messages to all_msg_list) expects
// add_messages to have already been called since
// update_unread_counts checks whether message are in
// the home view.
// You must add add messages to home_msg_list BEFORE
// calling process_loaded_for_unread.
add_messages(messages, home_msg_list);
process_loaded_for_unread(messages);
add_messages(messages, all_msg_list);
if (narrow.active()) {
@ -940,10 +936,13 @@ function load_old_messages(opts) {
narrow.show_empty_narrow_message();
}
messages = $.map(messages, add_message_metadata);
// If we're loading more messages into the home view, save them to
// the all_msg_list as well, as the home_msg_list is reconstructed
// from all_msg_list.
if (opts.msg_list === home_msg_list) {
process_loaded_for_unread(messages);
add_messages(messages, all_msg_list);
}