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

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

@ -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) {

@ -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 (

@ -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);
}

Loading…
Cancel
Save