compose: Validate stream message mentions on edit save.

This commit adds a message mentions validation for message editing.
The behavior will be similar to the validation on the compose box
when the user sends a message.

Fixes: #25411.
This commit is contained in:
Daniil Fadeev 2023-05-08 18:18:46 +04:00 committed by Tim Abbott
parent 1bab164d39
commit dd65ec2916
2 changed files with 27 additions and 4 deletions

View File

@ -474,10 +474,15 @@ export function initialize() {
`.${CSS.escape(compose_banner.CLASSNAMES.wildcard_warning)} .compose_banner_action_button`,
(event) => {
event.preventDefault();
const {$banner_container} = get_input_info(event);
const {$banner_container, is_edit_input} = get_input_info(event);
const $row = $(event.target).closest(".message_row");
compose_validate.clear_wildcard_warnings($banner_container);
compose_validate.set_user_acknowledged_wildcard_flag(true);
finish();
if (is_edit_input) {
message_edit.save_message_row_edit($row);
} else {
finish();
}
},
);

View File

@ -14,6 +14,7 @@ import * as compose from "./compose";
import * as compose_actions from "./compose_actions";
import * as compose_banner from "./compose_banner";
import * as compose_ui from "./compose_ui";
import * as compose_validate from "./compose_validate";
import * as composebox_typeahead from "./composebox_typeahead";
import * as condense from "./condense";
import * as confirm_dialog from "./confirm_dialog";
@ -883,6 +884,13 @@ export function save_inline_topic_edit($row) {
}
export function save_message_row_edit($row) {
const $banner_container = compose_banner.get_compose_banner_container(
$row.find(".message_edit_form textarea"),
);
const stream_id = Number.parseInt(
rows.get_message_recipient_header($row).attr("data-stream-id"),
10,
);
const msg_list = message_lists.current;
let message_id = rows.id($row);
const message = message_lists.current.get(message_id);
@ -892,8 +900,6 @@ export function save_message_row_edit($row) {
let new_content;
const old_content = message.raw_content;
show_message_edit_spinner($row);
const $edit_content_input = $row.find(".message_edit_content");
const can_edit_content = $edit_content_input.attr("readonly") !== "readonly";
if (can_edit_content) {
@ -901,6 +907,18 @@ export function save_message_row_edit($row) {
changed = old_content !== new_content;
}
const wildcard_mention = util.find_wildcard_mentions(new_content);
const is_stream_message_mentions_valid = compose_validate.validate_stream_message_mentions(
stream_id,
$banner_container,
wildcard_mention,
);
if (!is_stream_message_mentions_valid) {
return;
}
show_message_edit_spinner($row);
// Editing a not-yet-acked message (because the original send attempt failed)
// just results in the in-memory message being changed
if (message.locally_echoed) {