mirror of
https://github.com/zulip/zulip.git
synced 2025-11-13 10:26:28 +00:00
compose: Automatically change @ mentions to silent mentions in 1:1 DMs.
It is common for users in other chat tools to start off a direct message with @ mentioning the addressee. However, this results in potentially unexpected behavior in Zulip, where the message is highlighted and shows up in @ mentions in addition to DMs. We want to prevent this behaviour by automatically changing the @ mentions to silent @ mentions for the user. These changes only apply to 1:1 DMs and not group chats. Fixes: #17998.
This commit is contained in:
@@ -691,3 +691,22 @@ export function validate(scheduling_message) {
|
||||
}
|
||||
return validate_stream_message(scheduling_message);
|
||||
}
|
||||
|
||||
export function convert_mentions_to_silent_in_direct_messages(mention_text, full_name, user_id) {
|
||||
if (compose_state.get_message_type() !== "private") {
|
||||
return mention_text;
|
||||
}
|
||||
|
||||
const recipient_user_id = compose_pm_pill.get_user_ids();
|
||||
if (recipient_user_id.toString() !== user_id.toString()) {
|
||||
return mention_text;
|
||||
}
|
||||
|
||||
const mention_str = people.get_mention_syntax(full_name, user_id, false);
|
||||
const silent_mention_str = people.get_mention_syntax(full_name, user_id, true);
|
||||
mention_text = mention_text.replace(mention_str, silent_mention_str);
|
||||
// also replace other mentions...
|
||||
compose_ui.replace_syntax(mention_str, silent_mention_str);
|
||||
|
||||
return mention_text;
|
||||
}
|
||||
|
||||
@@ -862,15 +862,20 @@ export function content_typeahead_selected(item, event) {
|
||||
// that functionality yet, and we haven't gotten much
|
||||
// feedback on this being an actual pitfall.
|
||||
} else {
|
||||
const mention_text = people.get_mention_syntax(
|
||||
let mention_text = people.get_mention_syntax(
|
||||
item.full_name,
|
||||
item.user_id,
|
||||
is_silent,
|
||||
);
|
||||
beginning += mention_text + " ";
|
||||
if (!is_silent) {
|
||||
compose_validate.warn_if_mentioning_unsubscribed_user(item, $textbox);
|
||||
mention_text = compose_validate.convert_mentions_to_silent_in_direct_messages(
|
||||
mention_text,
|
||||
item.full_name,
|
||||
item.user_id,
|
||||
);
|
||||
}
|
||||
beginning += mention_text + " ";
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -476,6 +476,11 @@ test("content_typeahead_selected", ({override}) => {
|
||||
fake_this.completing = "mention";
|
||||
|
||||
override(compose_validate, "warn_if_mentioning_unsubscribed_user", () => {});
|
||||
override(
|
||||
compose_validate,
|
||||
"convert_mentions_to_silent_in_direct_messages",
|
||||
(mention_text) => mention_text,
|
||||
);
|
||||
|
||||
fake_this.query = "@**Mark Tw";
|
||||
fake_this.token = "Mark Tw";
|
||||
|
||||
Reference in New Issue
Block a user