Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

people: Update get_mention_syntax to better account for wildcards.

Lauryn Menard48a486a5844e
diff --git a/web/src/people.ts b/web/src/people.ts
index 1fb76b73bb4..ff7b4006f85 100644
--- a/web/src/people.ts
+++ b/web/src/people.ts
@@ -1353,7 +1353,7 @@ export function is_duplicate_full_name(full_name: string): boolean {
return ids !== undefined && ids.size > 1;
}
-export function get_mention_syntax(full_name: string, user_id: number, silent: boolean): string {
+export function get_mention_syntax(full_name: string, user_id?: number, silent = false): string {
let mention = "";
if (silent) {
mention += "@_**";
@@ -1361,13 +1361,11 @@ export function get_mention_syntax(full_name: string, user_id: number, silent: b
mention += "@**";
}
mention += full_name;
- if (!user_id) {
+ const wildcard_match = full_name_matches_wildcard_mention(full_name);
+ if (user_id === undefined && !wildcard_match) {
blueslip.warn("get_mention_syntax called without user_id.");
}
- if (
- (is_duplicate_full_name(full_name) || full_name_matches_wildcard_mention(full_name)) &&
- user_id
- ) {
+ if ((is_duplicate_full_name(full_name) || wildcard_match) && user_id !== undefined) {
mention += `|${user_id}`;
}
mention += "**";
@@ -1375,7 +1373,7 @@ export function get_mention_syntax(full_name: string, user_id: number, silent: b
}
function full_name_matches_wildcard_mention(full_name: string): boolean {
- return ["all", "everyone", "stream"].includes(full_name);
+ return ["all", "everyone", "stream", "topic"].includes(full_name);
}
export function _add_user(person: User): void {
diff --git a/web/tests/people.test.js b/web/tests/people.test.js
index c625618dcd8..030197f40a3 100644
--- a/web/tests/people.test.js
+++ b/web/tests/people.test.js
@@ -1150,6 +1150,12 @@ test_people("track_duplicate_full_names", () => {
});
test_people("get_mention_syntax", () => {
+ // blueslip warning is not raised for wildcard mentions without a user_id
+ assert.equal(people.get_mention_syntax("all"), "@**all**");
+ assert.equal(people.get_mention_syntax("everyone", undefined, true), "@_**everyone**");
+ assert.equal(people.get_mention_syntax("stream"), "@**stream**");
+ assert.equal(people.get_mention_syntax("topic"), "@**topic**");
+
people.add_active_user(stephen1);
people.add_active_user(stephen2);
people.add_active_user(maria);
@@ -1161,7 +1167,7 @@ test_people("get_mention_syntax", () => {
blueslip.reset();
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("Stephen King", 602, true), "@_**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.
@@ -1172,7 +1178,8 @@ test_people("get_mention_syntax", () => {
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**");
+ assert.ok(people.is_duplicate_full_name("all"));
+ assert.equal(people.get_mention_syntax("all", 1203, true), "@_**all|1203**");
});
test_people("initialize", () => {