mirror of https://github.com/zulip/zulip.git
people.js: Add get_mention_syntax to conditionally get @user|id syntax.
This is intended to replace all function calls for generating mention syntax for a target user.
This commit is contained in:
parent
608173657d
commit
b18f9def06
|
@ -698,6 +698,35 @@ run_test('track_duplicate_full_names', () => {
|
|||
assert(!people.is_duplicate_full_name('Stephen King JP'));
|
||||
});
|
||||
|
||||
run_test('track_duplicate_full_names', () => {
|
||||
var stephen1 = {
|
||||
email: 'stephen-the-author@example.com',
|
||||
user_id: 601,
|
||||
full_name: 'Stephen King',
|
||||
};
|
||||
var stephen2 = {
|
||||
email: 'stephen-the-explorer@example.com',
|
||||
user_id: 602,
|
||||
full_name: 'Stephen King',
|
||||
};
|
||||
var maria = {
|
||||
email: 'athens@example.com',
|
||||
user_id: 603,
|
||||
full_name: 'Maria Athens',
|
||||
};
|
||||
people.add(stephen1);
|
||||
people.add(stephen2);
|
||||
people.add(maria);
|
||||
|
||||
blueslip.set_test_data('warn', 'get_mention_syntax called without user_id.');
|
||||
assert.equal(people.get_mention_syntax('Stephen King'), '@**Stephen King**');
|
||||
assert.equal(blueslip.get_test_logs('warn').length, 1);
|
||||
blueslip.clear_test_data();
|
||||
assert.equal(people.get_mention_syntax('Stephen King', 601), '@**Stephen King|601**');
|
||||
assert.equal(people.get_mention_syntax('Stephen King', 602), '@**Stephen King|602**');
|
||||
assert.equal(people.get_mention_syntax('Maria Athens', 603), '@**Maria Athens**');
|
||||
});
|
||||
|
||||
run_test('initialize', () => {
|
||||
people.init();
|
||||
|
||||
|
|
|
@ -773,6 +773,18 @@ exports.is_duplicate_full_name = function (full_name) {
|
|||
return false;
|
||||
};
|
||||
|
||||
exports.get_mention_syntax = function (full_name, user_id) {
|
||||
var mention = '@**' + full_name;
|
||||
if (!user_id) {
|
||||
blueslip.warn('get_mention_syntax called without user_id.');
|
||||
}
|
||||
if (people.is_duplicate_full_name(full_name) && user_id) {
|
||||
mention += '|' + user_id;
|
||||
}
|
||||
mention += '**';
|
||||
return mention;
|
||||
};
|
||||
|
||||
exports.add = function add(person) {
|
||||
if (person.user_id) {
|
||||
people_by_user_id_dict.set(person.user_id, person);
|
||||
|
|
Loading…
Reference in New Issue