message_edit: Close message edit UI after message is moved.

Currently, if we navigate to some other topic/stream
while the message is being moved, the message edit UI
still remains open as we do not get its `row` in
`message_lists.current` since the message has not moved yet
to the stream/topic we navigated.

Hence the correct thing to do would be to delete
the message_id from `currently_editing_messages` if it
exists there but we cannot find the row.

Fixes #21724.
This commit is contained in:
jai2201 2022-08-10 02:53:32 +05:30 committed by Tim Abbott
parent 56b2b838ee
commit 1986b37a04
3 changed files with 14 additions and 9 deletions

View File

@ -88,10 +88,6 @@ run_test("update_messages", () => {
}, },
]; ];
message_lists.current.get_row = (message_id) => {
assert.equal(message_id, 111);
return ["row-stub"];
};
message_lists.current.view = {}; message_lists.current.view = {};
let rendered_mgs; let rendered_mgs;
@ -103,7 +99,7 @@ run_test("update_messages", () => {
const side_effects = [ const side_effects = [
[condense, "un_cache_message_content_height"], [condense, "un_cache_message_content_height"],
[message_edit, "end_message_row_edit"], [message_edit, "end_message_edit"],
[notifications, "received_messages"], [notifications, "received_messages"],
[unread_ui, "update_unread_counts"], [unread_ui, "update_unread_counts"],
[stream_list, "update_streams_sidebar"], [stream_list, "update_streams_sidebar"],

View File

@ -805,6 +805,17 @@ export function end_message_row_edit($row) {
$row.find("input.message_edit_topic").trigger("blur"); $row.find("input.message_edit_topic").trigger("blur");
} }
export function end_message_edit(message_id) {
const $row = message_lists.current.get_row(message_id);
if ($row.length > 0) {
end_message_row_edit($row);
} else if (currently_editing_messages.has(message_id)) {
// We should delete the message_id from currently_editing_messages
// if it exists there but we cannot find the row.
currently_editing_messages.delete(message_id);
}
}
export function save_inline_topic_edit($row) { export function save_inline_topic_edit($row) {
const msg_list = message_lists.current; const msg_list = message_lists.current;
let message_id = rows.id_for_recipient_row($row); let message_id = rows.id_for_recipient_row($row);

View File

@ -175,10 +175,8 @@ export function update_messages(events) {
msg.is_me_message = event.is_me_message; msg.is_me_message = event.is_me_message;
} }
const $row = message_lists.current.get_row(event.message_id); // mark the current message edit attempt as complete.
if ($row.length > 0) { message_edit.end_message_edit(event.message_id);
message_edit.end_message_row_edit($row);
}
// Save the content edit to the front end msg.edit_history // Save the content edit to the front end msg.edit_history
// before topic edits to ensure that combined topic / content // before topic edits to ensure that combined topic / content