mentions: Replace "channel" wildcard when selected via typeahead.

Until "stream" is renamed to "channel" in user facing strings,
when "channel" is selected from the composebox typeahead options,
the "stream" wildcard syntax will be inserted in the message
content instead.

Adds some helper functions to util.ts to initially be used to
check/convert "channel" to "stream" during the rename process,
with the intention of then converting those helpers for the
reverse (check/convert "stream" to "channel") in the final part
of the rename process.

Part of project to rename "stream" to "channel".
This commit is contained in:
Lauryn Menard
2024-04-03 19:55:26 +02:00
committed by Tim Abbott
parent e700e818e5
commit 80d4a704fe
3 changed files with 20 additions and 1 deletions

View File

@@ -1360,8 +1360,13 @@ export function get_mention_syntax(full_name: string, user_id?: number, silent =
} else {
mention += "@**";
}
mention += full_name;
const wildcard_match = full_name_matches_wildcard_mention(full_name);
if (wildcard_match && user_id === undefined) {
mention += util.canonicalize_stream_synonym(full_name);
} else {
mention += full_name;
}
if (user_id === undefined && !wildcard_match) {
blueslip.warn("get_mention_syntax called without user_id.");
}

View File

@@ -275,6 +275,19 @@ export function convert_message_topic(message: Message): void {
}
}
// TODO: When "stream" is renamed to "channel", update these stream
// synonym helper functions for the reverse logic.
export function is_stream_synonym(text: string): boolean {
return text === "channel";
}
export function canonicalize_stream_synonym(text: string): string {
if (is_stream_synonym(text.toLowerCase())) {
return "stream";
}
return text;
}
let inertDocument: Document | undefined;
export function clean_user_content_links(html: string): string {

View File

@@ -1154,6 +1154,7 @@ test_people("get_mention_syntax", () => {
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("channel"), "@**stream**");
assert.equal(people.get_mention_syntax("topic"), "@**topic**");
people.add_active_user(stephen1);