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:
Joelute
2023-10-11 20:22:29 -04:00
committed by Tim Abbott
parent 928cb7e09e
commit 4d1ade1f88
3 changed files with 31 additions and 2 deletions

View File

@@ -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;
}