message_edit: Don't send content to server if msg edit is disabled.

We ensure that if message edit is disabled, then we don't send
content in request to the server.

Refactored by tabbott to match the existing pattern for how we do this
for topic/stream edits.
This commit is contained in:
Aman Agrawal
2022-08-08 11:24:37 +00:00
committed by Tim Abbott
parent e758ec400b
commit c5489c9d2b

View File

@@ -880,7 +880,11 @@ export function save_message_row_edit($row) {
let changed = false;
let edit_locally_echoed = false;
const new_content = $row.find(".message_edit_content").val();
const $edit_content_input = $row.find(".message_edit_content");
let content_changed = false;
let new_content;
const old_content = message.raw_content;
let topic_changed = false;
let new_topic;
const old_topic = message.topic;
@@ -891,6 +895,12 @@ export function save_message_row_edit($row) {
show_message_edit_spinner($row);
if ($edit_content_input.attr("readonly") !== "readonly") {
new_content = $edit_content_input.val();
content_changed = old_content !== new_content;
changed = content_changed;
}
if (message.type === "stream") {
new_topic = $row.find(".message_edit_topic").val();
topic_changed = new_topic !== old_topic && new_topic.trim() !== "";
@@ -942,9 +952,8 @@ export function save_message_row_edit($row) {
if (stream_changed) {
request.stream_id = new_stream_id;
}
if (new_content !== message.raw_content) {
if (content_changed) {
request.content = new_content;
changed = true;
}
if (!changed) {