Add activity.short_huddle_name().

(imported from commit e3f0389298631fd06169dbc9559691470ac19d00)
This commit is contained in:
Steve Howell
2013-11-04 16:59:03 -05:00
parent 9adcba1e6d
commit 7bde1f7716
2 changed files with 43 additions and 0 deletions

View File

@@ -74,6 +74,24 @@ exports.full_huddle_name = function (huddle) {
return names.join(', '); return names.join(', ');
}; };
exports.short_huddle_name = function (huddle) {
var emails = huddle.split(',');
var names = _.map(emails.slice(0,2), function (email) {
var person = people_dict.get(email);
return person ? person.full_name : email;
});
var others = emails.length - 2;
if (others === 1) {
names.push("+ 1 other");
} else if (others >= 2) {
names.push("+ " + others + " others");
}
return names.join(', ');
};
exports.huddle_fraction_present = function (huddle, presence_info) { exports.huddle_fraction_present = function (huddle, presence_info) {
var emails = huddle.split(','); var emails = huddle.split(',');

View File

@@ -29,6 +29,9 @@ set_global('people_dict', new global.Dict.from({
}, },
'jill@zulip.com': { 'jill@zulip.com': {
full_name: 'Jill Hill' full_name: 'Jill Hill'
},
'mark@zulip.com': {
full_name: 'Marky Mark'
} }
})); }));
@@ -104,6 +107,28 @@ var activity = require('js/activity.js');
); );
}()); }());
(function test_short_huddle_name() {
assert.equal(
activity.short_huddle_name('alice@zulip.com'),
'Alice Smith'
);
assert.equal(
activity.short_huddle_name('alice@zulip.com,jill@zulip.com'),
'Alice Smith, Jill Hill'
);
assert.equal(
activity.short_huddle_name('alice@zulip.com,fred@zulip.com,jill@zulip.com'),
'Alice Smith, Fred Flintstone, + 1 other'
);
assert.equal(
activity.short_huddle_name('alice@zulip.com,fred@zulip.com,jill@zulip.com,mark@zulip.com'),
'Alice Smith, Fred Flintstone, + 2 others'
);
}());
(function test_huddle_fraction_present() { (function test_huddle_fraction_present() {
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';