mirror of https://github.com/zulip/zulip.git
Move set_presence_list from ui.js to activity.js.
Since ui.set_presence_list is only called from activity.js, I am inlining the code into activity.update_users(). This also allows us to move ui.presence_descriptions into activity.js, which is the right home for presence-related things. (imported from commit 0ff239275c544a86c14d517bc386d06726b81cd9)
This commit is contained in:
parent
82fd0f2b52
commit
7f3115fa53
|
@ -13,6 +13,13 @@ var ACTIVE_PING_INTERVAL_MS = 50 * 1000;
|
|||
/* Mark users as offline after 140 seconds since their last checkin */
|
||||
var OFFLINE_THRESHOLD_SECS = 140;
|
||||
|
||||
|
||||
var presence_descriptions = {
|
||||
active: 'is active',
|
||||
away: 'was recently active',
|
||||
idle: 'is not active'
|
||||
};
|
||||
|
||||
/* Keep in sync with views.py:json_update_active_status() */
|
||||
exports.ACTIVE = "active";
|
||||
exports.IDLE = "idle";
|
||||
|
@ -76,7 +83,52 @@ function focus_lost() {
|
|||
|
||||
function update_users() {
|
||||
var users = sort_users(Object.keys(presence_info), presence_info);
|
||||
ui.set_presence_list(users, presence_info);
|
||||
|
||||
if (page_params.domain === 'mit.edu') {
|
||||
return; // MIT realm doesn't have a presence list
|
||||
}
|
||||
|
||||
var my_info = {
|
||||
name: page_params.fullname,
|
||||
email: page_params.email,
|
||||
type: (activity.has_focus) ? activity.ACTIVE : activity.IDLE,
|
||||
type_desc: presence_descriptions.active,
|
||||
my_fullname: true
|
||||
};
|
||||
|
||||
function info_for(email) {
|
||||
var presence = presence_info[email];
|
||||
return {
|
||||
name: people_dict.get(email).full_name,
|
||||
email: email,
|
||||
type: presence,
|
||||
type_desc: presence_descriptions[presence]
|
||||
};
|
||||
}
|
||||
|
||||
var user_emails = _.filter(users, function (email) {
|
||||
return people_dict.has(email);
|
||||
});
|
||||
|
||||
var user_info = [my_info].concat(_.map(user_emails, info_for));
|
||||
|
||||
$('#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();
|
||||
}
|
||||
|
||||
function status_from_timestamp(baseline_time, presence) {
|
||||
|
|
|
@ -1619,60 +1619,6 @@ exports.register_scroll_handler = function () {
|
|||
}));
|
||||
};
|
||||
|
||||
var presence_descriptions = {
|
||||
active: 'is active',
|
||||
away: 'was recently active',
|
||||
idle: 'is not active'
|
||||
};
|
||||
|
||||
exports.set_presence_list = function (users, presence_info) {
|
||||
if (page_params.domain === 'mit.edu') {
|
||||
return; // MIT realm doesn't have a presence list
|
||||
}
|
||||
|
||||
var my_info = {
|
||||
name: page_params.fullname,
|
||||
email: page_params.email,
|
||||
type: (activity.has_focus) ? activity.ACTIVE : activity.IDLE,
|
||||
type_desc: presence_descriptions.active,
|
||||
my_fullname: true
|
||||
};
|
||||
|
||||
function info_for(email) {
|
||||
var presence = presence_info[email];
|
||||
return {
|
||||
name: people_dict.get(email).full_name,
|
||||
email: email,
|
||||
type: presence,
|
||||
type_desc: presence_descriptions[presence]
|
||||
};
|
||||
}
|
||||
|
||||
var user_emails = _.filter(users, function (email) {
|
||||
return people_dict.has(email);
|
||||
});
|
||||
|
||||
var user_info = [my_info].concat(_.map(user_emails, info_for));
|
||||
|
||||
$('#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();
|
||||
};
|
||||
|
||||
// Save the compose content cursor position and restore when we
|
||||
// shift-tab back in (see hotkey.js).
|
||||
var saved_compose_cursor = 0;
|
||||
|
|
Loading…
Reference in New Issue