mirror of https://github.com/zulip/zulip.git
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:
parent
61611a2dac
commit
0ac73e4d73
|
@ -98,9 +98,11 @@ exports.huddle_fraction_present = function (huddle, presence_info) {
|
||||||
|
|
||||||
var num_present = 0;
|
var num_present = 0;
|
||||||
_.each(emails, function (email) {
|
_.each(emails, function (email) {
|
||||||
var status = presence_info[email];
|
if (presence_info[email]) {
|
||||||
if (status && (status !== 'offline')) {
|
var status = presence_info[email].status;
|
||||||
++num_present;
|
if (status && (status !== 'offline')) {
|
||||||
|
++num_present;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -112,15 +114,15 @@ exports.huddle_fraction_present = function (huddle, presence_info) {
|
||||||
function sort_users(users, presence_info) {
|
function sort_users(users, presence_info) {
|
||||||
// TODO sort by unread count first, once we support that
|
// TODO sort by unread count first, once we support that
|
||||||
users.sort(function (a, b) {
|
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;
|
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;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (presence_info[a] === 'idle' && presence_info[b] !== 'idle') {
|
if (presence_info[a].status === 'idle' && presence_info[b].status !== 'idle') {
|
||||||
return -1;
|
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;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -206,7 +208,7 @@ function actually_update_users() {
|
||||||
// the commit that added this comment.
|
// the commit that added this comment.
|
||||||
|
|
||||||
function info_for(email) {
|
function info_for(email) {
|
||||||
var presence = presence_info[email];
|
var presence = presence_info[email].status;
|
||||||
return {
|
return {
|
||||||
name: people.get_by_email(email).full_name,
|
name: people.get_by_email(email).full_name,
|
||||||
email: email,
|
email: email,
|
||||||
|
@ -276,7 +278,7 @@ exports.update_huddles = function () {
|
||||||
|
|
||||||
function status_from_timestamp(baseline_time, presence) {
|
function status_from_timestamp(baseline_time, presence) {
|
||||||
if (presence.website === undefined) {
|
if (presence.website === undefined) {
|
||||||
return 'offline';
|
return {status: 'offline'};
|
||||||
}
|
}
|
||||||
|
|
||||||
var age = baseline_time - presence.website.timestamp;
|
var age = baseline_time - presence.website.timestamp;
|
||||||
|
@ -285,7 +287,7 @@ function status_from_timestamp(baseline_time, presence) {
|
||||||
if (age < OFFLINE_THRESHOLD_SECS) {
|
if (age < OFFLINE_THRESHOLD_SECS) {
|
||||||
status = presence.website.status;
|
status = presence.website.status;
|
||||||
}
|
}
|
||||||
return status;
|
return {status: status};
|
||||||
}
|
}
|
||||||
|
|
||||||
function focus_ping() {
|
function focus_ping() {
|
||||||
|
|
|
@ -43,9 +43,9 @@ var activity = require('js/activity.js');
|
||||||
var users = ['alice@zulip.com', 'fred@zulip.com', 'jill@zulip.com'];
|
var users = ['alice@zulip.com', 'fred@zulip.com', 'jill@zulip.com'];
|
||||||
|
|
||||||
var user_info = {
|
var user_info = {
|
||||||
'alice@zulip.com': 'inactive',
|
'alice@zulip.com': {status: 'inactive'},
|
||||||
'fred@zulip.com': 'active',
|
'fred@zulip.com': {status: 'active'},
|
||||||
'jill@zulip.com': 'active'
|
'jill@zulip.com': {status: 'active'}
|
||||||
};
|
};
|
||||||
|
|
||||||
activity._sort_users(users, user_info);
|
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 huddle = 'alice@zulip.com,fred@zulip.com,jill@zulip.com,mark@zulip.com';
|
||||||
|
|
||||||
var presence_list = {
|
var presence_list = {
|
||||||
'alice@zulip.com': 'active',
|
'alice@zulip.com': {status: 'active'},
|
||||||
'fred@zulip.com': 'idle', // counts as present
|
'fred@zulip.com': {status: 'idle'}, // counts as present
|
||||||
// jill not in list
|
// jill not in list
|
||||||
'mark@zulip.com': 'offline' // does not count
|
'mark@zulip.com': {status: 'offline'} // does not count
|
||||||
};
|
};
|
||||||
|
|
||||||
assert.equal(
|
assert.equal(
|
||||||
|
|
Loading…
Reference in New Issue