diff --git a/js/modules/types/message.js b/js/modules/types/message.js index 5f55e7d677..17ef082515 100644 --- a/js/modules/types/message.js +++ b/js/modules/types/message.js @@ -18,6 +18,9 @@ const PRIVATE = 'private'; // - Attachments: Sanitize Unicode order override characters. // Version 3 // - Attachments: Write attachment data to disk and store relative path to it. +// Version 4 +// - Quotes: Write thumbnail data to disk and store relative path to it. + const INITIAL_SCHEMA_VERSION = 0; @@ -158,13 +161,19 @@ exports._mapQuotedAttachments = upgradeAttachment => async (message, context) => } const upgradeWithContext = async (attachment) => { - if (!attachment || !attachment.thumbnail) { + const { thumbnail } = attachment; + if (!thumbnail) { return attachment; } - const thumbnail = await upgradeAttachment(attachment.thumbnail, context); + if (!thumbnail.data) { + console.log('Quoted attachment did not have thumbnail data; removing it'); + return omit(attachment, ['thumbnail']); + } + + const upgradedThumbnail = await upgradeAttachment(thumbnail, context); return Object.assign({}, attachment, { - thumbnail, + thumbnail: upgradedThumbnail, }); }; diff --git a/test/modules/types/message_test.js b/test/modules/types/message_test.js index e884b063e5..271ffe825b 100644 --- a/test/modules/types/message_test.js +++ b/test/modules/types/message_test.js @@ -410,6 +410,37 @@ describe('Message', () => { assert.deepEqual(result, message); }); + it('eliminates thumbnails with no data fielkd', async () => { + const upgradeAttachment = sinon.stub().throws(new Error("Shouldn't be called")); + const upgradeVersion = Message._mapQuotedAttachments(upgradeAttachment); + + const message = { + body: 'hey there!', + quote: { + text: 'hey!', + attachments: [{ + fileName: 'cat.gif', + contentType: 'image/gif', + thumbnail: { + fileName: 'failed to download!', + }, + }], + }, + }; + const expected = { + body: 'hey there!', + quote: { + text: 'hey!', + attachments: [{ + contentType: 'image/gif', + fileName: 'cat.gif', + }], + }, + }; + const result = await upgradeVersion(message); + assert.deepEqual(result, expected); + }); + it('calls provided async function for each quoted attachment', async () => { const upgradeAttachment = sinon.stub().resolves({ path: '/new/path/on/disk',