uploads: Improve abstraction of upload.js by removing object exports.

The `upload_objects_by_message_edit_row` map object was being exported
to handle the uploads during the editing of a message. To improve the
abstraction, we move the logic being used to access
`upload_objects_by_message_edit_row` and itself into `upload.js`.

Similarly, the `compose_upload_object` constant which was being exported
to handle the cancelling of compose uploads. This commit removes this
export and instead defines a new method `compose_upload_cancel` to
handle the same.
This commit is contained in:
Sayam Samal
2024-02-16 04:55:31 +05:30
committed by Tim Abbott
parent 65be62e4cb
commit a7e7176aae
4 changed files with 45 additions and 31 deletions

View File

@@ -577,11 +577,10 @@ function start_edit_with_content($row, content, edit_box_open_callback) {
edit_box_open_callback();
}
const row_id = rows.id($row);
const upload_object = upload.setup_upload({
upload.setup_upload({
mode: "edit",
row: row_id,
});
upload.upload_objects_by_message_edit_row.set(row_id, upload_object);
}
export function start($row, edit_box_open_callback) {
@@ -791,25 +790,11 @@ export function end_inline_topic_edit($row) {
message_lists.current.hide_edit_topic_on_recipient_row($row);
}
function remove_uploads_from_row(row_id) {
const uploads_for_row = upload.upload_objects_by_message_edit_row.get(row_id);
if (!uploads_for_row) {
return;
}
// We need to cancel all uploads, reset their progress,
// and clear the files upon ending the edit.
upload.deactivate_upload(uploads_for_row, {
mode: "edit",
row: row_id,
});
// Since we removed all the uploads from the row, we should
// now remove the corresponding upload object from the store.
upload.upload_objects_by_message_edit_row.delete(row_id);
}
export function end_message_row_edit($row) {
const row_id = rows.id($row);
remove_uploads_from_row(row_id);
// Clean up the upload handler
upload.deactivate_upload({mode: "edit", row: row_id});
const message = message_lists.current.get(row_id);
if (message !== undefined && currently_editing_messages.has(message.id)) {