mirror of
https://github.com/zulip/zulip.git
synced 2025-11-06 15:03:34 +00:00
message_edit: Ask users to delete attachments after editing.
currently, after a user edits a message and removes an reference to the uploaded file, the uploaded file stays on the storage taking up space. We want to ask the user to possibly delete the removed attachments if they are no longer needed. These changes applies a modal that will appear prompting the user to delete the attachments. Fixes: #25525. Co-authored-by: brijsiyag Co-authored-by: wandrew0
This commit is contained in:
@@ -2,6 +2,7 @@ import $ from "jquery";
|
||||
import type {z} from "zod";
|
||||
|
||||
import render_confirm_delete_attachment from "../templates/confirm_dialog/confirm_delete_attachment.hbs";
|
||||
import render_confirm_delete_detached_attachments_modal from "../templates/confirm_dialog/confirm_delete_detached_attachments.hbs";
|
||||
import render_settings_upload_space_stats from "../templates/settings/upload_space_stats.hbs";
|
||||
import render_uploaded_files_list from "../templates/settings/uploaded_files_list.hbs";
|
||||
|
||||
@@ -205,3 +206,58 @@ export function set_up_attachments(): void {
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function suggest_delete_detached_attachments(attachments_list: ServerAttachment[]): void {
|
||||
const html_body = render_confirm_delete_detached_attachments_modal({
|
||||
attachments_list,
|
||||
realm_allow_edit_history: realm.realm_allow_edit_history,
|
||||
});
|
||||
|
||||
// Since we want to delete multiple attachments, we want to be
|
||||
// able to keep track of attachments to delete and which ones to
|
||||
// retry if it fails.
|
||||
const attachments_map = new Map<number, ServerAttachment>();
|
||||
for (const attachment of attachments_list) {
|
||||
attachments_map.set(attachment.id, attachment);
|
||||
}
|
||||
|
||||
function do_delete_attachments(): void {
|
||||
dialog_widget.show_dialog_spinner();
|
||||
for (const [key, attachment] of attachments_map.entries()) {
|
||||
const id = Number(key);
|
||||
void channel.del({
|
||||
url: "/json/attachments/" + attachment.id,
|
||||
success() {
|
||||
attachments_map.delete(id);
|
||||
if (attachments_map.size === 0) {
|
||||
dialog_widget.hide_dialog_spinner();
|
||||
dialog_widget.close();
|
||||
}
|
||||
},
|
||||
error() {
|
||||
dialog_widget.hide_dialog_spinner();
|
||||
ui_report.error(
|
||||
$t_html({defaultMessage: "One or more files could not be deleted."}),
|
||||
undefined,
|
||||
$("#dialog_error"),
|
||||
);
|
||||
},
|
||||
});
|
||||
}
|
||||
// This is to open "Manage uploaded files" link.
|
||||
$("#confirm_delete_attachments_modal .uploaded_files_settings_link").on("click", (e) => {
|
||||
e.stopPropagation();
|
||||
dialog_widget.close();
|
||||
});
|
||||
}
|
||||
|
||||
dialog_widget.launch({
|
||||
id: "confirm_delete_attachments_modal",
|
||||
html_heading: $t_html({defaultMessage: "Delete uploaded files?"}),
|
||||
html_body,
|
||||
html_submit_button: $t_html({defaultMessage: "Delete"}),
|
||||
html_exit_button: $t_html({defaultMessage: "Don't delete"}),
|
||||
loading_spinner: true,
|
||||
on_click: do_delete_attachments,
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user