diff --git a/lib/reducers/message-reducer.js b/lib/reducers/message-reducer.js --- a/lib/reducers/message-reducer.js +++ b/lib/reducers/message-reducer.js @@ -1236,6 +1236,57 @@ ) { media.push({ ...singleMedia, ...mediaUpdate }); replaced = true; + } else if ( + singleMedia.type === 'photo' && + mediaUpdate.type === 'encrypted_photo' + ) { + // extract fields that are absent in encrypted_photo type + const { uri, localMediaSelection, ...original } = singleMedia; + const { holder, encryptionKey, ...update } = mediaUpdate; + invariant( + holder && encryptionKey, + 'holder and encryptionKey are required for encrypted_photo message', + ); + media.push({ + ...original, + ...update, + type: 'encrypted_photo', + holder, + encryptionKey, + }); + replaced = true; + } else if ( + singleMedia.type === 'video' && + mediaUpdate.type === 'encrypted_video' + ) { + const { uri, thumbnailURI, localMediaSelection, ...original } = + singleMedia; + const { + holder, + encryptionKey, + thumbnailHolder, + thumbnailEncryptionKey, + ...update + } = mediaUpdate; + invariant( + holder && encryptionKey, + 'holder and encryptionKey are required for encrypted_video message', + ); + invariant( + thumbnailHolder && thumbnailEncryptionKey, + 'thumbnailHolder and thumbnailEncryptionKey are required for ' + + 'encrypted_video message', + ); + media.push({ + ...original, + ...update, + type: 'encrypted_video', + holder, + encryptionKey, + thumbnailHolder, + thumbnailEncryptionKey, + }); + replaced = true; } } updatedMessage = { ...message, media };