From 43ab320d315fd831492ddcdd035efa334c4e6496 Mon Sep 17 00:00:00 2001 From: Daniel Gasienica Date: Tue, 3 Apr 2018 21:16:24 -0400 Subject: [PATCH] Load attachments before writing them upon export --- js/modules/backup.js | 6 ++++-- preload.js | 4 +++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/js/modules/backup.js b/js/modules/backup.js index 5f7a0ff2906..a82e829eb77 100644 --- a/js/modules/backup.js +++ b/js/modules/backup.js @@ -506,9 +506,11 @@ async function writeAttachment(attachment, options) { await stream.close(); } -async function writeAttachments(attachments, options) { +async function writeAttachments(rawAttachments, options) { const { name } = options; + const { loadAttachmentData } = Signal.Migrations; + const attachments = await Promise.all(rawAttachments.map(loadAttachmentData)); const promises = _.map( attachments, (attachment, index) => writeAttachment(attachment, Object.assign({}, options, { @@ -626,7 +628,7 @@ async function exportConversation(db, conversation, options) { const jsonString = JSON.stringify(stringify(message)); stream.write(jsonString); - if (attachments && attachments.length) { + if (attachments && attachments.length > 0) { const exportAttachments = () => writeAttachments(attachments, { dir: attachmentsDir, name, diff --git a/preload.js b/preload.js index 118627af2dc..6451f9cab63 100644 --- a/preload.js +++ b/preload.js @@ -116,6 +116,8 @@ const readAttachmentData = Attachments.createReader(attachmentsPath); const writeNewAttachmentData = Attachments.createWriterForNew(attachmentsPath); const writeExistingAttachmentData = Attachments.createWriterForExisting(attachmentsPath); +const loadAttachmentData = Attachment.loadData(readAttachmentData); + // Injected context functions to keep `Message` agnostic from Electron: const upgradeSchemaContext = { writeNewAttachmentData, @@ -140,7 +142,7 @@ window.Signal.Migrations.deleteAttachmentData = window.Signal.Migrations.getPlaceholderMigrations = getPlaceholderMigrations; window.Signal.Migrations.importMessage = Message.createImporter(writeExistingAttachmentData); -window.Signal.Migrations.loadAttachmentData = Attachment.loadData(readAttachmentData); +window.Signal.Migrations.loadAttachmentData = loadAttachmentData; window.Signal.Migrations.Migrations0DatabaseWithAttachmentData = require('./js/modules/migrations/migrations_0_database_with_attachment_data'); window.Signal.Migrations.Migrations1DatabaseWithoutAttachmentData =