people: Update get_mention_syntax to better account for wildcards.

In `composebox_typeahead`, it is completely possible to call
`people.get_mention_syntax` for a wildcard mention, which will not
have a `user_id`.

Updates `get_mention_syntax` to not raise a blueslip error if the
mention syntax is for a wildcard mention.

Adds "topic" to the array of possible wildcard mention strings.

Tightens the types for the parameters for `get_mention_syntax`, by
setting `user_id` to be number or undefined, and by setting `silent`
to default to false (which is expected in a number of modules where
this function is called).
This commit is contained in:
Lauryn Menard
2024-04-03 17:38:44 +02:00
committed by Tim Abbott
parent 6b31823c23
commit 48a486a584
2 changed files with 14 additions and 9 deletions

View File

@@ -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 {