Move user list unread-count logic to templates.

When we rebuild the user list from scratch, set the unread
counts in the templates to avoid multiple DOM updates.

(imported from commit 2d0c9b0fb99b382332e464ba7c3caad95e05363e)
This commit is contained in:
Steve Howell
2013-12-16 13:53:21 -05:00
parent a8cd91d6c7
commit 1c67fdb95d
4 changed files with 17 additions and 15 deletions

View File

@@ -157,9 +157,17 @@ function update_users() {
var users = sort_users(Object.keys(presence_info), presence_info);
function get_num_unread(email) {
if (suppress_unread_counts) {
return 0;
}
return unread.num_unread_for_person(email);
}
var my_info = {
name: page_params.fullname,
email: page_params.email,
num_unread: get_num_unread(page_params.email),
type: (activity.has_focus) ? activity.ACTIVE : activity.IDLE,
type_desc: presence_descriptions.active,
my_fullname: true
@@ -170,6 +178,7 @@ function update_users() {
return {
name: people_dict.get(email).full_name,
email: email,
num_unread: get_num_unread(email),
type: presence,
type_desc: presence_descriptions[presence]
};
@@ -183,19 +192,6 @@ function update_users() {
$('#user_presences').html(templates.render('user_presence_rows', {users: user_info}));
// Update the counts in the presence list.
if (!suppress_unread_counts) {
// We do this after rendering the template, to avoid dealing with
// the suppress_unread_counts conditional in the template.
var set_count = function (email) {
stream_list.set_presence_list_count(email, unread.num_unread_for_person(email));
};
_.each(user_emails, set_count);
set_count(page_params.email);
}
// Update user fading, if necessary.
compose_fade.update_faded_users();
}