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.

compose paste: Convert mention HTML to markdown when quoting.

sandeep1f3861347f6f
diff --git a/web/src/compose_paste.ts b/web/src/compose_paste.ts
index e75a749f474..f6f0f26d8c3 100644
--- a/web/src/compose_paste.ts
+++ b/web/src/compose_paste.ts
@@ -9,8 +9,10 @@ import * as compose_banner from "./compose_banner.ts";
import * as compose_ui from "./compose_ui.ts";
import * as hash_util from "./hash_util.ts";
import {$t} from "./i18n.ts";
+import * as people from "./people.ts";
import * as stream_data from "./stream_data.ts";
import * as topic_link_util from "./topic_link_util.ts";
+import * as user_groups from "./user_groups.ts";
import * as util from "./util.ts";
const MINIMUM_PASTE_SIZE_FOR_FILE_TREATMENT = 2000;
@@ -245,6 +247,8 @@ function get_code_block_language(
return language;
}
+export const MENTION_SELECTOR = ".user-mention, .user-group-mention, .topic-mention";
+
export function paste_handler_converter(
paste_html: string,
$textarea?: JQuery<HTMLTextAreaElement>,
@@ -263,7 +267,11 @@ export function paste_handler_converter(
if (
has_single_child_with_valid_text &&
copied_html_fragment.firstElementChild !== null &&
- !outer_elements_to_retain.includes(copied_html_fragment.firstElementChild.nodeName)
+ !outer_elements_to_retain.includes(copied_html_fragment.firstElementChild.nodeName) &&
+ // A mention anywhere in the selection (even wrapped in a <p> or
+ // nested inside .mention-content-wrapper) must reach the Turndown
+ // mention rule, so never take the plain-text fast path for it.
+ copied_html_fragment.querySelector(MENTION_SELECTOR) === null
) {
// This will always return some text as it is already ensured
// that such a text node exists in `has_single_textful_child_node`.
@@ -290,6 +298,61 @@ export function paste_handler_converter(
headingStyle: "atx",
br: "",
});
+ turndownService.addRule("mentions", {
+ filter(node) {
+ return node.nodeName === "SPAN" && node.matches(MENTION_SELECTOR);
+ },
+ replacement(_content, node) {
+ assert(node instanceof HTMLElement);
+ const is_silent = node.classList.contains("silent");
+ const is_group = node.classList.contains("user-group-mention");
+
+ // Group mentions use single-asterisk syntax (@*name* / @_*name*);
+ // user, topic, and wildcard mentions use double-asterisk.
+ const delimiter = is_group ? "*" : "**";
+ const prefix = (is_silent ? "@_" : "@") + delimiter;
+
+ const user_id = node.getAttribute("data-user-id");
+ if (
+ node.classList.contains("user-mention") &&
+ !node.classList.contains("channel-wildcard-mention") &&
+ user_id !== null
+ ) {
+ // Look up canonical full_name from the people store so the markdown
+ // doesn't depend on the display text (which can include suffixes
+ // like "(guest)" added by rendered_markdown.ts). Fall back to the
+ // id-only @**|id** syntax if the user can't be resolved locally;
+ // the backend will resolve it on send.
+ const user = people.maybe_get_user_by_id(Number(user_id), true);
+ if (user !== undefined) {
+ return people.get_mention_syntax(
+ user.full_name,
+ Number(user_id),
+ is_silent,
+ true,
+ );
+ }
+ return `${prefix}|${user_id}${delimiter}`;
+ }
+
+ const group_id = node.getAttribute("data-user-group-id");
+ if (is_group && group_id !== null) {
+ // System groups render with a display name (e.g. "Owners")
+ // that differs from the mention name (e.g. "role:owners"),
+ // so look up the canonical name instead of the display text.
+ const group = user_groups.maybe_get_user_group_from_id(Number(group_id));
+ if (group !== undefined) {
+ return `${prefix}${group.name}${delimiter}`;
+ }
+ }
+
+ let name = (node.textContent ?? "").trim();
+ if (name.startsWith("@")) {
+ name = name.slice(1);
+ }
+ return `${prefix}${name}${delimiter}`;
+ },
+ });
turndownService.addRule("style", {
filter: "style",
replacement() {
diff --git a/web/src/compose_reply.ts b/web/src/compose_reply.ts
index 6a1e497705f..3e4aae8fa34 100644
--- a/web/src/compose_reply.ts
+++ b/web/src/compose_reply.ts
@@ -833,6 +833,7 @@ export let get_message_selection = (selection = window.getSelection()): string =
// in one selection), and also compute their combined bounding rect.
for (let i = 0; i < selection.rangeCount; i += 1) {
let range = selection.getRangeAt(i);
+ copy_messages.improve_mention_selection_range(range);
const range_common_ancestor = range.commonAncestorContainer;
let html_to_convert;
let message_content;
diff --git a/web/src/copy_messages.ts b/web/src/copy_messages.ts
index ee6c179f6cb..6b38bd3072c 100644
--- a/web/src/copy_messages.ts
+++ b/web/src/copy_messages.ts
@@ -7,6 +7,7 @@ import assert from "minimalistic-assert";
import render_copied_recipient_header from "../templates/copied_recipient_header.hbs";
import * as blueslip from "./blueslip.ts";
+import {MENTION_SELECTOR} from "./compose_paste.ts";
import * as message_lists from "./message_lists.ts";
import * as rows from "./rows.ts";
import {the} from "./util.ts";
@@ -421,6 +422,32 @@ function improve_time_selection_range(range: Range): void {
}
}
+export function improve_mention_selection_range(range: Range): void {
+ const start_element = get_nearest_html_element(range.startContainer);
+ const end_element = get_nearest_html_element(range.endContainer);
+ if (!start_element || !end_element) {
+ return;
+ }
+
+ const start_mention = start_element.closest(MENTION_SELECTOR);
+ const end_mention = end_element.closest(MENTION_SELECTOR);
+
+ if (!start_mention && !end_mention) {
+ return;
+ }
+
+ // Expand the range so a partial selection inside a mention pill
+ // becomes a selection of the full mention span. Otherwise the
+ // copied/quoted markdown ends up as a broken mention like
+ // @_amlet|34 from selecting "amlet" inside "King Hamlet".
+ if (start_mention) {
+ range.setStartBefore(start_mention);
+ }
+ if (end_mention) {
+ range.setEndAfter(end_mention);
+ }
+}
+
/*
Our paste behavior for KaTeX relies on processing the MathML
annotations generated by KaTeX in `<annotation>` tags. This
@@ -552,6 +579,7 @@ export function copy_handler(ev: ClipboardEvent): boolean {
let custom_handle_copy = false;
for (let i = 0; i < selection.rangeCount; i += 1) {
improve_time_selection_range(selection.getRangeAt(i));
+ improve_mention_selection_range(selection.getRangeAt(i));
improve_katex_selection_range(selection.getRangeAt(i));
if (maybe_update_range_for_code_blocks(selection.getRangeAt(i), ev)) {
diff --git a/web/src/people.ts b/web/src/people.ts
index 34acf4a1813..db2e904c5ec 100644
--- a/web/src/people.ts
+++ b/web/src/people.ts
@@ -1332,7 +1332,15 @@ export function get_unique_full_name(full_name: string, user_id: number): string
return unique_full_name;
}
-export function get_mention_syntax(full_name: string, user_id?: number, silent = false): string {
+export function get_mention_syntax(
+ full_name: string,
+ user_id?: number,
+ silent = false,
+ // Callers that build a mention from rendered HTML (e.g. paste
+ // handling) can't trust the display name, so they pin the mention
+ // to the id even when the name isn't ambiguous.
+ always_include_id = false,
+): string {
let mention = "";
if (silent) {
mention += "@_**";
@@ -1352,7 +1360,10 @@ export function get_mention_syntax(full_name: string, user_id?: number, silent =
if (user_id === undefined && !wildcard_match) {
blueslip.warn("get_mention_syntax called without user_id.");
}
- if ((is_duplicate_full_name(full_name) || wildcard_match) && user_id !== undefined) {
+ if (
+ (always_include_id || is_duplicate_full_name(full_name) || wildcard_match) &&
+ user_id !== undefined
+ ) {
mention += `|${user_id}`;
}
mention += "**";
diff --git a/web/tests/compose_paste.test.cjs b/web/tests/compose_paste.test.cjs
index afbf72aa814..5b8c610ba69 100644
--- a/web/tests/compose_paste.test.cjs
+++ b/web/tests/compose_paste.test.cjs
@@ -7,7 +7,9 @@ const {JSDOM} = require("jsdom");
const katex_tests = require("../../zerver/tests/fixtures/katex_test_cases.json");
const {parse} = require("../src/markdown.ts");
+const {make_user_group} = require("./lib/example_group.cjs");
const {make_stream} = require("./lib/example_stream.cjs");
+const {make_user} = require("./lib/example_user.cjs");
const {mock_esm, zrequire, set_global} = require("./lib/namespace.cjs");
const {run_test, noop} = require("./lib/test.cjs");
const {$} = require("./lib/zjquery.cjs");
@@ -21,7 +23,9 @@ const compose_ui = zrequire("compose_ui");
const linkifiers = zrequire("linkifiers");
const markdown = zrequire("markdown");
const markdown_config = zrequire("markdown_config");
+const people = zrequire("people");
const stream_data = zrequire("stream_data");
+const user_groups = zrequire("user_groups");
const {initialize_user_settings} = zrequire("user_settings");
set_global("document", {});
@@ -38,6 +42,19 @@ initialize_user_settings({
});
markdown.initialize(markdown_config.get_helpers());
+// User and group ids match the ids used in the mention test fixtures
+// below.
+const king_hamlet = make_user({user_id: 10, full_name: "King Hamlet"});
+const desdemona = make_user({user_id: 9, full_name: "Desdemona"});
+const polonius = make_user({user_id: 13, full_name: "Polonius"});
+people.add_active_user(king_hamlet);
+people.add_active_user(desdemona);
+people.add_active_user(polonius);
+
+const hamletcharacters = make_user_group({name: "hamletcharacters", id: 24});
+const owners = make_user_group({name: "role:owners", id: 25, is_system_group: true});
+user_groups.initialize({realm_user_groups: [hamletcharacters, owners]});
+
stream_data.add_sub_for_tests(
make_stream({
stream_id: 4,
@@ -662,4 +679,166 @@ run_test("paste_handler_converter", () => {
span_conversion_test.expected_output,
);
}
+ const meta = '<meta http-equiv="content-type" content="text/html; charset=utf-8">';
+
+ let firefox_input;
+
+ // Non-silent user mention
+ firefox_input =
+ meta +
+ '<p><span class="user-mention" data-user-id="10">' +
+ '<span class="mention-content-wrapper">@King Hamlet</span></span></p>';
+ assert.equal(compose_paste.paste_handler_converter(firefox_input), "@**King Hamlet|10**");
+
+ // Guest user mention: rendered_markdown.ts adds a "(guest)" suffix
+ // to the display name (commit 70c9d0765f). The people-store lookup
+ // returns the canonical full_name, so the suffix is dropped naturally.
+ firefox_input =
+ meta +
+ '<p><span class="user-mention" data-user-id="13">' +
+ '<span class="mention-content-wrapper">@Polonius (guest)</span></span></p>';
+ assert.equal(compose_paste.paste_handler_converter(firefox_input), "@**Polonius|13**");
+
+ // Silent user mention
+ firefox_input =
+ meta +
+ '<p><span class="user-mention silent" data-user-id="10">' +
+ '<span class="mention-content-wrapper">King Hamlet</span></span></p>';
+ assert.equal(compose_paste.paste_handler_converter(firefox_input), "@_**King Hamlet|10**");
+
+ // Self-mention adds a `user-mention-me` modifier class.
+ firefox_input =
+ meta +
+ '<p><span class="user-mention user-mention-me" data-user-id="9">' +
+ '<span class="mention-content-wrapper">@Desdemona</span></span></p>';
+ assert.equal(compose_paste.paste_handler_converter(firefox_input), "@**Desdemona|9**");
+
+ // Non-silent group mention (single-asterisk syntax)
+ firefox_input =
+ meta +
+ '<p><span class="user-group-mention" data-user-group-id="24">' +
+ '<span class="mention-content-wrapper">@hamletcharacters</span></span></p>';
+ assert.equal(compose_paste.paste_handler_converter(firefox_input), "@*hamletcharacters*");
+
+ // Silent group mention
+ firefox_input =
+ meta +
+ '<p><span class="user-group-mention silent" data-user-group-id="24">' +
+ '<span class="mention-content-wrapper">hamletcharacters</span></span></p>';
+ assert.equal(compose_paste.paste_handler_converter(firefox_input), "@_*hamletcharacters*");
+
+ // System group mention: the pill's display text ("Owners") differs from
+ // the mention name ("role:owners"), so we resolve the name by group id.
+ firefox_input =
+ meta +
+ '<p><span class="user-group-mention" data-user-group-id="25">' +
+ '<span class="mention-content-wrapper">@Owners</span></span></p>';
+ assert.equal(compose_paste.paste_handler_converter(firefox_input), "@*role:owners*");
+
+ // Non-silent topic mention
+ firefox_input =
+ meta +
+ '<p><span class="topic-mention">' +
+ '<span class="mention-content-wrapper">@topic</span></span></p>';
+ assert.equal(compose_paste.paste_handler_converter(firefox_input), "@**topic**");
+
+ // Silent topic mention
+ firefox_input =
+ meta +
+ '<p><span class="topic-mention silent">' +
+ '<span class="mention-content-wrapper">topic</span></span></p>';
+ assert.equal(compose_paste.paste_handler_converter(firefox_input), "@_**topic**");
+
+ // Non-silent channel wildcard mention (no |user_id suffix)
+ firefox_input =
+ meta +
+ '<p><span class="user-mention channel-wildcard-mention" data-user-id="*">' +
+ '<span class="mention-content-wrapper">@all</span></span></p>';
+ assert.equal(compose_paste.paste_handler_converter(firefox_input), "@**all**");
+
+ // Silent channel wildcard mention
+ firefox_input =
+ meta +
+ '<p><span class="user-mention channel-wildcard-mention silent" data-user-id="*">' +
+ '<span class="mention-content-wrapper">all</span></span></p>';
+ assert.equal(compose_paste.paste_handler_converter(firefox_input), "@_**all**");
+
+ // Mention inline with surrounding text.
+ firefox_input =
+ meta +
+ '<p>Hey <span class="user-mention" data-user-id="10">' +
+ '<span class="mention-content-wrapper">@King Hamlet</span></span>, how are you?</p>';
+ assert.equal(
+ compose_paste.paste_handler_converter(firefox_input),
+ "Hey @**King Hamlet|10**, how are you?",
+ );
+
+ // Lone mention without ancestor wrapper (bare span), as can happen
+ // when keyboard selection contains only the mention element.
+ firefox_input =
+ meta +
+ '<span class="user-mention" data-user-id="10">' +
+ '<span class="mention-content-wrapper">@King Hamlet</span></span>';
+ assert.equal(compose_paste.paste_handler_converter(firefox_input), "@**King Hamlet|10**");
+
+ // Unknown user (not in the people store) falls back to the id-only
+ // @**|id** syntax; the backend resolves it on send.
+ firefox_input =
+ meta +
+ '<p><span class="user-mention" data-user-id="9999">' +
+ '<span class="mention-content-wrapper">@Unknown</span></span></p>';
+ assert.equal(compose_paste.paste_handler_converter(firefox_input), "@**|9999**");
+
+ let chrome_input;
+
+ // Non-silent user mention.
+ chrome_input = `<html><body><!--StartFragment--><span class="user-mention" data-user-id="10" style="padding: 0px 3px; border-radius: 3px; white-space: nowrap; font-size: 0.95em; color: rgba(255, 255, 255, 0.8); background-color: rgba(100, 100, 206, 0.25); cursor: pointer; font-family: &quot;Source Sans 3 VF&quot;, sans-serif; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><span class="mention-content-wrapper" style="font-size: 1.0526em;">@King Hamlet</span></span><span style="color: rgb(222, 222, 222); font-family: &quot;Source Sans 3 VF&quot;, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(31, 40, 40); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial; display: inline !important; float: none;">, how are you?</span><!--EndFragment--></body></html>`;
+ assert.equal(
+ compose_paste.paste_handler_converter(chrome_input),
+ "@**King Hamlet|10**, how are you?",
+ );
+
+ // Silent user mention.
+ chrome_input = `<html><body><!--StartFragment--><span class="user-mention silent" data-user-id="10" style="padding: 0px 3px; border-radius: 3px; white-space: nowrap; font-size: 0.95em; color: rgba(255, 255, 255, 0.8); background-color: rgba(100, 100, 206, 0.45); cursor: pointer; font-family: &quot;Source Sans 3 VF&quot;, sans-serif; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><span class="mention-content-wrapper" style="font-size: 1.0526em;">King Hamlet</span></span><span style="color: rgb(222, 222, 222); font-family: &quot;Source Sans 3 VF&quot;, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(31, 40, 40); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial; display: inline !important; float: none;">, silent test</span><!--EndFragment--></body></html>`;
+ assert.equal(
+ compose_paste.paste_handler_converter(chrome_input),
+ "@_**King Hamlet|10**, silent test",
+ );
+
+ // Self-mention adds a user-mention-me modifier class.
+ chrome_input = `<html><body><!--StartFragment--><span class="user-mention user-mention-me" data-user-id="9" style="padding: 0px 3px; border-radius: 3px; white-space: nowrap; font-size: 0.95em; color: rgb(194, 194, 255); background-color: rgba(100, 100, 206, 0.45); cursor: pointer; font-weight: 600; font-family: &quot;Source Sans 3 VF&quot;, sans-serif; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><span class="mention-content-wrapper" style="font-size: 1.0526em;">@Desdemona</span></span><span style="color: rgb(222, 222, 222); font-family: &quot;Source Sans 3 VF&quot;, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(35, 35, 46); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial; display: inline !important; float: none;"> hello</span><!--EndFragment--></body></html>`;
+ assert.equal(compose_paste.paste_handler_converter(chrome_input), "@**Desdemona|9** hello");
+
+ // Guest user mention: rendered_markdown.ts adds a "(guest)" suffix to
+ // the display name (commit 70c9d0765f). The people-store lookup returns
+ // the canonical full_name, so the suffix is dropped naturally.
+ chrome_input = `<html><body><!--StartFragment--><span class="user-mention" data-user-id="13" style="padding: 0px 3px; border-radius: 3px; white-space: nowrap; font-size: 0.95em; color: rgba(255, 255, 255, 0.8); background-color: rgba(100, 100, 206, 0.45); cursor: pointer; font-family: &quot;Source Sans 3 VF&quot;, sans-serif; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><span class="mention-content-wrapper" style="font-size: 1.0526em;">@Polonius (guest)</span></span><span style="color: rgb(222, 222, 222); font-family: &quot;Source Sans 3 VF&quot;, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(34, 34, 34); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial; display: inline !important; float: none;"><span> </span>guest</span><!--EndFragment--></body></html>`;
+ assert.equal(compose_paste.paste_handler_converter(chrome_input), "@**Polonius|13** guest");
+
+ // Non-silent group mention (single-asterisk syntax).
+ chrome_input = `<html><body><!--StartFragment--><span class="user-group-mention user-mention-me" data-user-group-id="35" style="padding: 0px 3px; border-radius: 3px; white-space: nowrap; font-size: 0.95em; cursor: pointer; color: rgb(112, 203, 210); background-color: rgba(49, 150, 155, 0.2); font-weight: 600; font-family: &quot;Source Sans 3 VF&quot;, sans-serif; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><span class="mention-content-wrapper" style="font-size: 1.0526em;">@announce</span></span><span style="color: rgb(222, 222, 222); font-family: &quot;Source Sans 3 VF&quot;, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(31, 40, 40); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial; display: inline !important; float: none;"> group ping</span><!--EndFragment--></body></html>`;
+ assert.equal(compose_paste.paste_handler_converter(chrome_input), "@*announce* group ping");
+
+ // Silent group mention.
+ chrome_input = `<html><body><!--StartFragment--><span class="user-group-mention silent" data-user-group-id="24" style="padding: 0px 3px; border-radius: 3px; white-space: nowrap; font-size: 0.95em; cursor: pointer; color: rgba(255, 255, 255, 0.8); background-color: rgba(49, 150, 155, 0.3); font-family: &quot;Source Sans 3 VF&quot;, sans-serif; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><span class="mention-content-wrapper" style="font-size: 1.0526em;">hamletcharacters</span></span><span style="color: rgb(222, 222, 222); font-family: &quot;Source Sans 3 VF&quot;, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(31, 40, 40); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial; display: inline !important; float: none;">, silent group</span><!--EndFragment--></body></html>`;
+ assert.equal(
+ compose_paste.paste_handler_converter(chrome_input),
+ "@_*hamletcharacters*, silent group",
+ );
+
+ // Non-silent topic mention.
+ chrome_input = `<html><body><!--StartFragment--><span class="topic-mention user-mention-me" style="padding: 0px 3px; border-radius: 3px; white-space: nowrap; font-size: 0.95em; color: rgb(112, 203, 210); background-color: rgba(49, 150, 155, 0.2); font-weight: 600; font-family: &quot;Source Sans 3 VF&quot;, sans-serif; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><span class="mention-content-wrapper" style="font-size: 1.0526em;">@topic</span></span><span style="color: rgb(222, 222, 222); font-family: &quot;Source Sans 3 VF&quot;, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(31, 40, 40); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial; display: inline !important; float: none;"> topic test</span><!--EndFragment--></body></html>`;
+ assert.equal(compose_paste.paste_handler_converter(chrome_input), "@**topic** topic test");
+
+ // Silent topic mention.
+ chrome_input = `<html><body><!--StartFragment--><span class="topic-mention silent" style="padding: 0px 3px; border-radius: 3px; white-space: nowrap; font-size: 0.95em; color: rgba(255, 255, 255, 0.8); background-color: rgba(49, 150, 155, 0.2); font-family: &quot;Source Sans 3 VF&quot;, sans-serif; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><span class="mention-content-wrapper" style="font-size: 1.0526em;">topic</span></span><span style="color: rgb(222, 222, 222); font-family: &quot;Source Sans 3 VF&quot;, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(34, 34, 34); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial; display: inline !important; float: none;"> silent topic</span><!--EndFragment--></body></html>`;
+ assert.equal(compose_paste.paste_handler_converter(chrome_input), "@_**topic** silent topic");
+
+ // Non-silent channel wildcard mention (no |user_id suffix).
+ chrome_input = `<html><body><!--StartFragment--><span class="user-mention channel-wildcard-mention user-mention-me" data-user-id="*" style="padding: 0px 3px; border-radius: 3px; white-space: nowrap; font-size: 0.95em; color: rgb(112, 203, 210); background-color: rgba(49, 150, 155, 0.2); cursor: pointer; font-weight: 600; font-family: &quot;Source Sans 3 VF&quot;, sans-serif; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><span class="mention-content-wrapper" style="font-size: 1.0526em;">@all</span></span><span style="color: rgb(222, 222, 222); font-family: &quot;Source Sans 3 VF&quot;, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(31, 40, 40); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial; display: inline !important; float: none;"> wildcard</span><!--EndFragment--></body></html>`;
+ assert.equal(compose_paste.paste_handler_converter(chrome_input), "@**all** wildcard");
+
+ // Silent channel wildcard mention.
+ chrome_input = `<html><body><!--StartFragment--><span class="user-mention channel-wildcard-mention silent user-mention-me" data-user-id="*" style="padding: 0px 3px; border-radius: 3px; white-space: nowrap; font-size: 0.95em; color: rgb(112, 203, 210); background-color: rgba(49, 150, 155, 0.2); cursor: pointer; font-weight: 600; font-family: &quot;Source Sans 3 VF&quot;, sans-serif; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><span class="mention-content-wrapper" style="font-size: 1.0526em;">all</span></span><span style="color: rgb(222, 222, 222); font-family: &quot;Source Sans 3 VF&quot;, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(31, 40, 40); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial; display: inline !important; float: none;"> silently</span><!--EndFragment--></body></html>`;
+ assert.equal(compose_paste.paste_handler_converter(chrome_input), "@_**all** silently");
});
diff --git a/web/tests/people.test.cjs b/web/tests/people.test.cjs
index 79567340bfe..a1c0ef4e565 100644
--- a/web/tests/people.test.cjs
+++ b/web/tests/people.test.cjs
@@ -1320,6 +1320,12 @@ run_test("get_mention_syntax", () => {
assert.equal(people.get_mention_syntax("Stephen King", 602, true), "@_**Stephen King|602**");
assert.equal(people.get_mention_syntax("Maria Athens", 603), "@**Maria Athens**");
+ // With always_include_id, the id is pinned even when the name is unique.
+ assert.equal(
+ people.get_mention_syntax("Maria Athens", 603, false, true),
+ "@**Maria Athens|603**",
+ );
+
// 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