Skip to content

Commit

Permalink
message_edit: Close message edit UI after message is moved.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jai2201 committed Aug 9, 2022
1 parent aa796af commit 33977cc
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
6 changes: 1 addition & 5 deletions frontend_tests/node_tests/message_events.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};

let rendered_mgs;
Expand All @@ -103,7 +99,7 @@ run_test("update_messages", () => {

const side_effects = [
[condense, "un_cache_message_content_height"],
[message_edit, "end_message_row_edit"],
[message_edit, "end_message_edit"],
[notifications, "received_messages"],
[unread_ui, "update_unread_counts"],
[stream_list, "update_streams_sidebar"],
Expand Down
11 changes: 11 additions & 0 deletions static/js/message_edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -805,6 +805,17 @@ export function end_message_row_edit($row) {
$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) {
const msg_list = message_lists.current;
let message_id = rows.id_for_recipient_row($row);
Expand Down
6 changes: 2 additions & 4 deletions static/js/message_events.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,8 @@ export function update_messages(events) {
msg.is_me_message = event.is_me_message;
}

const $row = message_lists.current.get_row(event.message_id);
if ($row.length > 0) {
message_edit.end_message_row_edit($row);
}
// mark the current message edit attempt as complete.
message_edit.end_message_edit(event.message_id);

const new_topic = util.get_edit_event_topic(event);

Expand Down

0 comments on commit 33977cc

Please sign in to comment.