Use a dict in presence_info rather than strings

This allows us to extend it to contain more details, as we will shortly.

(imported from commit 59b14592609810c5ac634a8237928ce029f33a83)
This commit is contained in:
Luke Faraone 2014-02-14 15:05:51 -05:00 committed by Jessica McKellar
parent 61611a2dac
commit 0ac73e4d73
2 changed files with 18 additions and 16 deletions

View File

@ -98,9 +98,11 @@ exports.huddle_fraction_present = function (huddle, presence_info) {
var num_present = 0;
_.each(emails, function (email) {
var status = presence_info[email];
if (status && (status !== 'offline')) {
++num_present;
if (presence_info[email]) {
var status = presence_info[email].status;
if (status && (status !== 'offline')) {
++num_present;
}
}
});
@ -112,15 +114,15 @@ exports.huddle_fraction_present = function (huddle, presence_info) {
function sort_users(users, presence_info) {
// TODO sort by unread count first, once we support that
users.sort(function (a, b) {
if (presence_info[a] === 'active' && presence_info[b] !== 'active') {
if (presence_info[a].status === 'active' && presence_info[b].status !== 'active') {
return -1;
} else if (presence_info[b] === 'active' && presence_info[a] !== 'active') {
} else if (presence_info[b].status === 'active' && presence_info[a].status !== 'active') {
return 1;
}
if (presence_info[a] === 'idle' && presence_info[b] !== 'idle') {
if (presence_info[a].status === 'idle' && presence_info[b].status !== 'idle') {
return -1;
} else if (presence_info[b] === 'idle' && presence_info[a] !== 'idle') {
} else if (presence_info[b].status === 'idle' && presence_info[a].status !== 'idle') {
return 1;
}
@ -206,7 +208,7 @@ function actually_update_users() {
// the commit that added this comment.
function info_for(email) {
var presence = presence_info[email];
var presence = presence_info[email].status;
return {
name: people.get_by_email(email).full_name,
email: email,
@ -276,7 +278,7 @@ exports.update_huddles = function () {
function status_from_timestamp(baseline_time, presence) {
if (presence.website === undefined) {
return 'offline';
return {status: 'offline'};
}
var age = baseline_time - presence.website.timestamp;
@ -285,7 +287,7 @@ function status_from_timestamp(baseline_time, presence) {
if (age < OFFLINE_THRESHOLD_SECS) {
status = presence.website.status;
}
return status;
return {status: status};
}
function focus_ping() {

View File

@ -43,9 +43,9 @@ var activity = require('js/activity.js');
var users = ['alice@zulip.com', 'fred@zulip.com', 'jill@zulip.com'];
var user_info = {
'alice@zulip.com': 'inactive',
'fred@zulip.com': 'active',
'jill@zulip.com': 'active'
'alice@zulip.com': {status: 'inactive'},
'fred@zulip.com': {status: 'active'},
'jill@zulip.com': {status: 'active'}
};
activity._sort_users(users, user_info);
@ -141,10 +141,10 @@ var activity = require('js/activity.js');
var huddle = 'alice@zulip.com,fred@zulip.com,jill@zulip.com,mark@zulip.com';
var presence_list = {
'alice@zulip.com': 'active',
'fred@zulip.com': 'idle', // counts as present
'alice@zulip.com': {status: 'active'},
'fred@zulip.com': {status: 'idle'}, // counts as present
// jill not in list
'mark@zulip.com': 'offline' // does not count
'mark@zulip.com': {status: 'offline'} // does not count
};
assert.equal(