people: Fix `get_mention_syntax` when `full_name` matches wildcard.

When quoting a reply or mentioning a person having full name matching
wildcard mention, in such case, `get_mention_syntax` doesn't return
mention syntax of format: **full_name|user_id**.
As a result, a normal user can't mention such users and users who
can mention them may unwillingly trigger wildcard mention.
This commit fixes such issue.
This commit is contained in:
akshatdalton 2021-05-19 12:41:18 +00:00 committed by Tim Abbott
parent b636a9199b
commit 78b59fa756
2 changed files with 30 additions and 1 deletions

View File

@ -233,6 +233,18 @@ const plain_noah = {
full_name: "Nooaah Emerson",
};
const all1 = {
email: "all1@example.com",
user_id: 1202,
full_name: "all",
};
const all2 = {
email: "all2@example.com",
user_id: 1203,
full_name: "all",
};
// This is for error checking--never actually
// tell people.js about this user.
const unknown_user = {
@ -1014,6 +1026,16 @@ test_people("get_mention_syntax", () => {
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**");
// Following tests handle a special case when `full_name` matches with a wildcard.
//
// At this point, there is no duplicate full name, `all`, so we should still get
// mention syntax with `user_id` appended to it.
people.add_active_user(all1);
assert.equal(people.get_mention_syntax("all", 1202), "@**all|1202**");
people.add_active_user(all2);
assert.equal(people.get_mention_syntax("all", 1203), "@**all|1203**");
});
test_people("initialize", () => {

View File

@ -1108,13 +1108,20 @@ export function get_mention_syntax(full_name, user_id, silent) {
if (!user_id) {
blueslip.warn("get_mention_syntax called without user_id.");
}
if (is_duplicate_full_name(full_name) && user_id) {
if (
(is_duplicate_full_name(full_name) || full_name_matches_wildcard_mention(full_name)) &&
user_id
) {
mention += "|" + user_id;
}
mention += "**";
return mention;
}
function full_name_matches_wildcard_mention(full_name) {
return ["all", "everyone", "stream"].includes(full_name);
}
export function _add_user(person) {
/*
This is common code to add any user, even