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 @@ -1437,12 +1437,20 @@ singleMedia.type === 'encrypted_photo' && mediaUpdate.type === 'encrypted_photo' ) { + // TODO: Remove this $FlowFixMe after updating Flow to 0.202 + // There's no way in Flow to refine both of these types appropriately + // so they can be spread together. + // $FlowFixMe media.push({ ...singleMedia, ...mediaUpdate }); replaced = true; } else if ( singleMedia.type === 'encrypted_video' && mediaUpdate.type === 'encrypted_video' ) { + // TODO: Remove this $FlowFixMe after updating Flow to 0.202 + // There's no way in Flow to refine both of these types appropriately + // so they can be spread together. + // $FlowFixMe media.push({ ...singleMedia, ...mediaUpdate }); replaced = true; } else if ( @@ -1451,16 +1459,22 @@ ) { // extract fields that are absent in encrypted_photo type const { uri, localMediaSelection, ...original } = singleMedia; - const { holder, encryptionKey, ...update } = mediaUpdate; + const { + holder: newHolder, + blobURI: newBlobURI, + encryptionKey, + ...update + } = mediaUpdate; + const blobURI = newBlobURI ?? newHolder; invariant( - holder && encryptionKey, + blobURI && encryptionKey, 'holder and encryptionKey are required for encrypted_photo message', ); media.push({ ...original, ...update, type: 'encrypted_photo', - holder, + blobURI, encryptionKey, }); replaced = true; @@ -1471,18 +1485,22 @@ const { uri, thumbnailURI, localMediaSelection, ...original } = singleMedia; const { - holder, + holder: newHolder, + blobURI: newBlobURI, encryptionKey, - thumbnailHolder, + thumbnailHolder: newThumbnailHolder, + thumbnailBlobURI: newThumbnailBlobURI, thumbnailEncryptionKey, ...update } = mediaUpdate; + const blobURI = newBlobURI ?? newHolder; invariant( - holder && encryptionKey, + blobURI && encryptionKey, 'holder and encryptionKey are required for encrypted_video message', ); + const thumbnailBlobURI = newThumbnailBlobURI ?? newThumbnailHolder; invariant( - thumbnailHolder && thumbnailEncryptionKey, + thumbnailBlobURI && thumbnailEncryptionKey, 'thumbnailHolder and thumbnailEncryptionKey are required for ' + 'encrypted_video message', ); @@ -1490,9 +1508,9 @@ ...original, ...update, type: 'encrypted_video', - holder, + blobURI, encryptionKey, - thumbnailHolder, + thumbnailBlobURI, thumbnailEncryptionKey, }); replaced = true; @@ -1504,9 +1522,27 @@ } else if (singleMedia.type === 'video') { media.push({ ...singleMedia, id: newID }); } else if (singleMedia.type === 'encrypted_photo') { - media.push({ ...singleMedia, id: newID }); + // TODO: Try removing this branching after Flow 0.202 update + if (singleMedia.blobURI) { + media.push({ ...singleMedia, id: newID }); + } else { + invariant( + singleMedia.holder, + 'Encrypted media must have holder or blobURI', + ); + media.push({ ...singleMedia, id: newID }); + } } else if (singleMedia.type === 'encrypted_video') { - media.push({ ...singleMedia, id: newID }); + // TODO: Try removing this branching after Flow 0.202 update + if (singleMedia.blobURI) { + media.push({ ...singleMedia, id: newID }); + } else { + invariant( + singleMedia.holder, + 'Encrypted media must have holder or blobURI', + ); + media.push({ ...singleMedia, id: newID }); + } } replaced = true; } diff --git a/lib/types/media-types.js b/lib/types/media-types.js --- a/lib/types/media-types.js +++ b/lib/types/media-types.js @@ -77,7 +77,7 @@ export type UpdateMultimediaMessageMediaPayload = { +messageID: string, +currentMediaID: string, - +mediaUpdate: Shape, + +mediaUpdate: MediaShape, }; export type UploadDeletionRequest = { @@ -763,6 +763,11 @@ ]); export type Media = Image | Video | EncryptedImage | EncryptedVideo; +export type MediaShape = + | Shape + | Shape