mirror of
https://github.com/zulip/zulip.git
synced 2025-11-18 21:48:30 +00:00
Add activity.short_huddle_name().
(imported from commit e3f0389298631fd06169dbc9559691470ac19d00)
This commit is contained in:
@@ -74,6 +74,24 @@ exports.full_huddle_name = function (huddle) {
|
||||
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) {
|
||||
var emails = huddle.split(',');
|
||||
|
||||
|
||||
@@ -29,6 +29,9 @@ set_global('people_dict', new global.Dict.from({
|
||||
},
|
||||
'jill@zulip.com': {
|
||||
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() {
|
||||
var huddle = 'alice@zulip.com,fred@zulip.com,jill@zulip.com,mark@zulip.com';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user