right-sidebar: Fix group PMs online indicator.

People found it confusing that it would show up at light-green when
the users in the thread were idle.

Fixes #8242.
This commit is contained in:
LuisFSilva 2018-04-24 17:12:09 +01:00 committed by Tim Abbott
parent 02c3223985
commit a072b2a153
4 changed files with 29 additions and 9 deletions

View File

@ -263,9 +263,9 @@ presence.presence_info = presence_info;
let huddle = 'alice@zulip.com,fred@zulip.com,jill@zulip.com,mark@zulip.com'; let huddle = 'alice@zulip.com,fred@zulip.com,jill@zulip.com,mark@zulip.com';
huddle = people.emails_strings_to_user_ids_string(huddle); huddle = people.emails_strings_to_user_ids_string(huddle);
const presence_info = {}; var presence_info = {};
presence_info[alice.user_id] = { status: 'active' }; presence_info[alice.user_id] = { status: 'active' }; // counts as present
presence_info[fred.user_id] = { status: 'idle' }; // counts as present presence_info[fred.user_id] = { status: 'idle' }; // doest not count as present
// jill not in list // jill not in list
presence_info[mark.user_id] = { status: 'offline' }; // does not count presence_info[mark.user_id] = { status: 'offline' }; // does not count
presence.presence_info = presence_info; presence.presence_info = presence_info;
@ -273,6 +273,19 @@ presence.presence_info = presence_info;
assert.equal( assert.equal(
activity.huddle_fraction_present(huddle), activity.huddle_fraction_present(huddle),
'0.50'); '0.50');
huddle = 'alice@zulip.com,fred@zulip.com,jill@zulip.com,mark@zulip.com';
huddle = people.emails_strings_to_user_ids_string(huddle);
presence_info = {};
presence_info[alice.user_id] = { status: 'idle' };
presence_info[fred.user_id] = { status: 'idle' }; // does not count as present
// jill not in list
presence_info[mark.user_id] = { status: 'offline' }; // does not count
presence.presence_info = presence_info;
assert.equal(
activity.huddle_fraction_present(huddle),
false);
}()); }());
presence.presence_info = {}; presence.presence_info = {};

View File

@ -182,14 +182,17 @@ exports.huddle_fraction_present = function (huddle) {
var num_present = 0; var num_present = 0;
_.each(user_ids, function (user_id) { _.each(user_ids, function (user_id) {
if (presence.is_not_offline(user_id)) { if (presence.is_active(user_id)) {
num_present += 1; num_present += 1;
} }
}); });
var ratio = num_present / user_ids.length; if (num_present === user_ids.length) {
return 1;
return ratio.toFixed(2); } else if (num_present !== 0) {
return 0.5;
}
return false;
}; };
function focus_lost() { function focus_lost() {

View File

@ -20,12 +20,12 @@ function is_mobile(device) {
return MOBILE_DEVICES.indexOf(device) !== -1; return MOBILE_DEVICES.indexOf(device) !== -1;
} }
exports.is_not_offline = function (user_id) { exports.is_active = function (user_id) {
var presence_info = exports.presence_info; var presence_info = exports.presence_info;
if (presence_info[user_id]) { if (presence_info[user_id]) {
var status = presence_info[user_id].status; var status = presence_info[user_id].status;
if (status && (status !== 'offline')) { if (status && (status === "active")) {
return true; return true;
} }
} }

View File

@ -2,7 +2,11 @@
{{#each group_pms}} {{#each group_pms}}
<li data-user-ids="{{user_ids_string}}" class="group-pms-sidebar-entry narrow-filter"> <li data-user-ids="{{user_ids_string}}" class="group-pms-sidebar-entry narrow-filter">
<span class="selectable_sidebar_block"> <span class="selectable_sidebar_block">
{{#if fraction_present}}
<span class="group-pm-status-indicator" style="background:rgba(68,194,29,{{fraction_present}});"></span> <span class="group-pm-status-indicator" style="background:rgba(68,194,29,{{fraction_present}});"></span>
{{else}}
<span class="group-pm-status-indicator" style="background:rgb(255,255,255); border-color:rgb(127,127,127);"></span>
{{/if}}
<a href="{{href}}" data-name="{{name}}" title="{{name}}" class="group-pm-link">{{short_name}}</a> <a href="{{href}}" data-name="{{name}}" title="{{name}}" class="group-pm-link">{{short_name}}</a>
</span> </span>
<span class="count"><span class="value"></span></span> <span class="count"><span class="value"></span></span>