diff --git a/js/modules/types/message.js b/js/modules/types/message.js index 3ce90f56c..3de94fa56 100644 --- a/js/modules/types/message.js +++ b/js/modules/types/message.js @@ -177,6 +177,16 @@ exports.upgradeSchema = async (message, { writeNewAttachmentData } = {}) => { ); }; +exports.createAttachmentLoader = (loadAttachmentData) => { + if (!isFunction(loadAttachmentData)) { + throw new TypeError('`loadAttachmentData` is required'); + } + + return async message => (Object.assign({}, message, { + attachments: await Promise.all(message.attachments.map(loadAttachmentData)), + })); +}; + // createImporter :: (RelativePath -> IO Unit) // Message -> // IO (Promise Message) diff --git a/preload.js b/preload.js index 6451f9cab..ce60d1f46 100644 --- a/preload.js +++ b/preload.js @@ -143,6 +143,7 @@ window.Signal.Migrations.getPlaceholderMigrations = getPlaceholderMigrations; window.Signal.Migrations.importMessage = Message.createImporter(writeExistingAttachmentData); window.Signal.Migrations.loadAttachmentData = loadAttachmentData; +window.Signal.Migrations.loadMessage = Message.createAttachmentLoader(loadAttachmentData); window.Signal.Migrations.Migrations0DatabaseWithAttachmentData = require('./js/modules/migrations/migrations_0_database_with_attachment_data'); window.Signal.Migrations.Migrations1DatabaseWithoutAttachmentData =