feat: made progress on attachment deletions but can confirm 100%

pull/2660/head
William Grant 3 years ago
parent 462f96341e
commit 386997f233

@ -28,6 +28,17 @@ export const deleteExternalMessageFiles = async (message: {
if (attachments && attachments.length) { if (attachments && attachments.length) {
await Promise.all(attachments.map(deleteData)); await Promise.all(attachments.map(deleteData));
// testing that the files were successfully deleted
try {
await Promise.all(
attachments.map(async (attachment: { path: string; thumbnail: any; screenshot: any }) => {
await readAttachmentData(attachment.path);
})
);
window.log.info(`WIP: failed in deleting files`);
} catch (err) {
window.log.info(`WIP: succeeded in deleting files`, err);
}
} }
if (quote && quote.attachments && quote.attachments.length) { if (quote && quote.attachments && quote.attachments.length) {

@ -145,26 +145,27 @@ export const loadData = async (attachment: any) => {
// deleteData :: (RelativePath -> IO Unit) // deleteData :: (RelativePath -> IO Unit)
// Attachment -> // Attachment ->
// IO Unit // IO Unit
export const deleteData = () => { // NOTE Flattening this function seemed to have worked
return async (attachment: { path: string; thumbnail: any; screenshot: any }) => { export const deleteData = async (attachment: { path: string; thumbnail: any; screenshot: any }) => {
if (!isValid(attachment)) { if (!isValid(attachment)) {
throw new TypeError('deleteData: attachment is not valid'); throw new TypeError('deleteData: attachment is not valid');
} }
const { path, thumbnail, screenshot } = attachment; const { path, thumbnail, screenshot } = attachment;
if (isString(path)) {
await deleteOnDisk(path);
}
if (thumbnail && isString(thumbnail.path)) { if (isString(path)) {
await deleteOnDisk(thumbnail.path); await deleteOnDisk(path);
} }
if (screenshot && isString(screenshot.path)) { if (thumbnail && isString(thumbnail.path)) {
await deleteOnDisk(screenshot.path); await deleteOnDisk(thumbnail.path);
} }
};
if (screenshot && isString(screenshot.path)) {
await deleteOnDisk(screenshot.path);
}
}; };
type CaptureDimensionType = { contentType: string; path: string }; type CaptureDimensionType = { contentType: string; path: string };
export const captureDimensionsAndScreenshot = async ( export const captureDimensionsAndScreenshot = async (

@ -49,8 +49,16 @@ export async function destroyMessagesAndUpdateRedux(
const conversationWithChanges = uniq(messages.map(m => m.conversationKey)); const conversationWithChanges = uniq(messages.map(m => m.conversationKey));
try { try {
const messageIds = messages.map(m => m.messageId);
// Delete any attachments
for (let i = 0; i < messageIds.length; i++) {
const message = await Data.getMessageById(messageIds[i]);
await message?.cleanup();
}
// Delete all those messages in a single sql call // Delete all those messages in a single sql call
await Data.removeMessagesByIds(messages.map(m => m.messageId)); await Data.removeMessagesByIds(messageIds);
} catch (e) { } catch (e) {
window.log.error('destroyMessages: removeMessagesByIds failed', e && e.message ? e.message : e); window.log.error('destroyMessages: removeMessagesByIds failed', e && e.message ? e.message : e);
} }

Loading…
Cancel
Save