Add Message.createAttachmentLoader

This commit is contained in:
Daniel Gasienica 2018-04-03 21:17:48 -04:00
parent 43ab320d31
commit 94c75762b5
2 changed files with 11 additions and 0 deletions

View file

@ -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) // createImporter :: (RelativePath -> IO Unit)
// Message -> // Message ->
// IO (Promise Message) // IO (Promise Message)

View file

@ -143,6 +143,7 @@ window.Signal.Migrations.getPlaceholderMigrations = getPlaceholderMigrations;
window.Signal.Migrations.importMessage = window.Signal.Migrations.importMessage =
Message.createImporter(writeExistingAttachmentData); Message.createImporter(writeExistingAttachmentData);
window.Signal.Migrations.loadAttachmentData = loadAttachmentData; window.Signal.Migrations.loadAttachmentData = loadAttachmentData;
window.Signal.Migrations.loadMessage = Message.createAttachmentLoader(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 =