Load attachments before writing them upon export
This commit is contained in:
parent
7eeabb5b1a
commit
43ab320d31
2 changed files with 7 additions and 3 deletions
|
@ -506,9 +506,11 @@ async function writeAttachment(attachment, options) {
|
||||||
await stream.close();
|
await stream.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
async function writeAttachments(attachments, options) {
|
async function writeAttachments(rawAttachments, options) {
|
||||||
const { name } = options;
|
const { name } = options;
|
||||||
|
|
||||||
|
const { loadAttachmentData } = Signal.Migrations;
|
||||||
|
const attachments = await Promise.all(rawAttachments.map(loadAttachmentData));
|
||||||
const promises = _.map(
|
const promises = _.map(
|
||||||
attachments,
|
attachments,
|
||||||
(attachment, index) => writeAttachment(attachment, Object.assign({}, options, {
|
(attachment, index) => writeAttachment(attachment, Object.assign({}, options, {
|
||||||
|
@ -626,7 +628,7 @@ async function exportConversation(db, conversation, options) {
|
||||||
const jsonString = JSON.stringify(stringify(message));
|
const jsonString = JSON.stringify(stringify(message));
|
||||||
stream.write(jsonString);
|
stream.write(jsonString);
|
||||||
|
|
||||||
if (attachments && attachments.length) {
|
if (attachments && attachments.length > 0) {
|
||||||
const exportAttachments = () => writeAttachments(attachments, {
|
const exportAttachments = () => writeAttachments(attachments, {
|
||||||
dir: attachmentsDir,
|
dir: attachmentsDir,
|
||||||
name,
|
name,
|
||||||
|
|
|
@ -116,6 +116,8 @@ const readAttachmentData = Attachments.createReader(attachmentsPath);
|
||||||
const writeNewAttachmentData = Attachments.createWriterForNew(attachmentsPath);
|
const writeNewAttachmentData = Attachments.createWriterForNew(attachmentsPath);
|
||||||
const writeExistingAttachmentData = Attachments.createWriterForExisting(attachmentsPath);
|
const writeExistingAttachmentData = Attachments.createWriterForExisting(attachmentsPath);
|
||||||
|
|
||||||
|
const loadAttachmentData = Attachment.loadData(readAttachmentData);
|
||||||
|
|
||||||
// Injected context functions to keep `Message` agnostic from Electron:
|
// Injected context functions to keep `Message` agnostic from Electron:
|
||||||
const upgradeSchemaContext = {
|
const upgradeSchemaContext = {
|
||||||
writeNewAttachmentData,
|
writeNewAttachmentData,
|
||||||
|
@ -140,7 +142,7 @@ window.Signal.Migrations.deleteAttachmentData =
|
||||||
window.Signal.Migrations.getPlaceholderMigrations = getPlaceholderMigrations;
|
window.Signal.Migrations.getPlaceholderMigrations = getPlaceholderMigrations;
|
||||||
window.Signal.Migrations.importMessage =
|
window.Signal.Migrations.importMessage =
|
||||||
Message.createImporter(writeExistingAttachmentData);
|
Message.createImporter(writeExistingAttachmentData);
|
||||||
window.Signal.Migrations.loadAttachmentData = Attachment.loadData(readAttachmentData);
|
window.Signal.Migrations.loadAttachmentData = loadAttachmentData;
|
||||||
window.Signal.Migrations.Migrations0DatabaseWithAttachmentData =
|
window.Signal.Migrations.Migrations0DatabaseWithAttachmentData =
|
||||||
require('./js/modules/migrations/migrations_0_database_with_attachment_data');
|
require('./js/modules/migrations/migrations_0_database_with_attachment_data');
|
||||||
window.Signal.Migrations.Migrations1DatabaseWithoutAttachmentData =
|
window.Signal.Migrations.Migrations1DatabaseWithoutAttachmentData =
|
||||||
|
|
Loading…
Reference in a new issue