From 94c75762b57c524d70c8383dcd98b19719059bf6 Mon Sep 17 00:00:00 2001 From: Daniel Gasienica Date: Tue, 3 Apr 2018 21:17:48 -0400 Subject: [PATCH] Add `Message.createAttachmentLoader` --- js/modules/types/message.js | 10 ++++++++++ preload.js | 1 + 2 files changed, 11 insertions(+) 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 =