message_edit: Fix bug when multiple message edit forms are opened.

There is a bug when multiple message edit forms are opened at the
same time where undefined value of stream_id is sent to the server.
This happens because a global variable stream_widget is used to get
the id of stream selected in dropdown and value of stream_widget
variable keeps on changing when we open multiple message edit forms.
Thus, stream_widget can have the dropdown widget of already closed
edit form resulting in undefined value of stream id.

This commit changes the save_message_row_edit function to access
the dropdown element directly using message id instead of using
stream_widget.value() and thus we always use the correct dropdown
element to get the stream id.

We also move the stream_widget variable to be inside edit_message
function instead of being global variable for the module.

Fixes #19663.
This commit is contained in:
Sahil Batra 2021-09-07 22:44:41 +05:30 committed by Tim Abbott
parent 459ce92109
commit b8a1b13166
1 changed files with 3 additions and 2 deletions

View File

@ -37,7 +37,6 @@ import * as upload from "./upload";
const currently_editing_messages = new Map();
let currently_deleting_messages = [];
let currently_topic_editing_messages = [];
let stream_widget;
const currently_echoing_messages = new Map();
export const RESOLVED_TOPIC_PREFIX = "✔ ";
@ -352,6 +351,7 @@ function create_copy_to_clipboard_handler(row, source, message_id) {
}
function edit_message(row, raw_content) {
let stream_widget;
row.find(".message_reactions").hide();
condense.hide_message_expander(row);
condense.hide_message_condenser(row);
@ -807,7 +807,8 @@ export function save_message_row_edit(row) {
topic_changed = new_topic !== old_topic && new_topic.trim() !== "";
if (can_edit_stream) {
new_stream_id = Number.parseInt(stream_widget.value(), 10);
const dropdown_list_widget_value_elem = $(`#id_select_move_stream_${message_id}`);
new_stream_id = Number.parseInt(dropdown_list_widget_value_elem.data("value"), 10);
stream_changed = new_stream_id !== old_stream_id;
}
}