diff --git a/ts/types/MessageAttachment.ts b/ts/types/MessageAttachment.ts index a997f2425..32d069f5f 100644 --- a/ts/types/MessageAttachment.ts +++ b/ts/types/MessageAttachment.ts @@ -28,6 +28,17 @@ export const deleteExternalMessageFiles = async (message: { if (attachments && attachments.length) { 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) { diff --git a/ts/types/attachments/migrations.ts b/ts/types/attachments/migrations.ts index 5626803d6..cc7870833 100644 --- a/ts/types/attachments/migrations.ts +++ b/ts/types/attachments/migrations.ts @@ -145,26 +145,27 @@ export const loadData = async (attachment: any) => { // deleteData :: (RelativePath -> IO Unit) // Attachment -> // IO Unit -export const deleteData = () => { - return async (attachment: { path: string; thumbnail: any; screenshot: any }) => { - if (!isValid(attachment)) { - throw new TypeError('deleteData: attachment is not valid'); - } +// NOTE Flattening this function seemed to have worked +export const deleteData = async (attachment: { path: string; thumbnail: any; screenshot: any }) => { + if (!isValid(attachment)) { + throw new TypeError('deleteData: attachment is not valid'); + } - const { path, thumbnail, screenshot } = attachment; - if (isString(path)) { - await deleteOnDisk(path); - } + const { path, thumbnail, screenshot } = attachment; - if (thumbnail && isString(thumbnail.path)) { - await deleteOnDisk(thumbnail.path); - } + if (isString(path)) { + await deleteOnDisk(path); + } - if (screenshot && isString(screenshot.path)) { - await deleteOnDisk(screenshot.path); - } - }; + if (thumbnail && isString(thumbnail.path)) { + await deleteOnDisk(thumbnail.path); + } + + if (screenshot && isString(screenshot.path)) { + await deleteOnDisk(screenshot.path); + } }; + type CaptureDimensionType = { contentType: string; path: string }; export const captureDimensionsAndScreenshot = async ( diff --git a/ts/util/expiringMessages.ts b/ts/util/expiringMessages.ts index feee80527..9bfe2f5f3 100644 --- a/ts/util/expiringMessages.ts +++ b/ts/util/expiringMessages.ts @@ -49,8 +49,16 @@ export async function destroyMessagesAndUpdateRedux( const conversationWithChanges = uniq(messages.map(m => m.conversationKey)); 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 - await Data.removeMessagesByIds(messages.map(m => m.messageId)); + await Data.removeMessagesByIds(messageIds); } catch (e) { window.log.error('destroyMessages: removeMessagesByIds failed', e && e.message ? e.message : e); }