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 @@ -1295,21 +1295,57 @@ 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 }); + if (singleMedia.blobURI) { + const { holder, ...rest } = mediaUpdate; + if (holder) { + console.log( + `mediaUpdate contained holder for media ${singleMedia.id} ` + + 'that has blobURI', + ); + } + media.push({ ...singleMedia, ...rest }); + } else { + invariant( + singleMedia.holder, + 'Encrypted media must have holder or blobURI', + ); + const { blobURI, ...rest } = mediaUpdate; + if (blobURI) { + console.log( + `mediaUpdate contained blobURI for media ${singleMedia.id} ` + + 'that has holder', + ); + } + media.push({ ...singleMedia, ...rest }); + } 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 }); + if (singleMedia.blobURI) { + const { holder, thumbnailHolder, ...rest } = mediaUpdate; + if (holder || thumbnailHolder) { + console.log( + 'mediaUpdate contained holder or thumbnailHolder for media ' + + `${singleMedia.id} that has blobURI`, + ); + } + media.push({ ...singleMedia, ...rest }); + } else { + invariant( + singleMedia.holder, + 'Encrypted media must have holder or blobURI', + ); + const { blobURI, thumbnailBlobURI, ...rest } = mediaUpdate; + if (blobURI || thumbnailBlobURI) { + console.log( + 'mediaUpdate contained blobURI or thumbnailBlobURI for media ' + + `${singleMedia.id} that has holder`, + ); + } + media.push({ ...singleMedia, ...rest }); + } replaced = true; } else if ( singleMedia.type === 'photo' && @@ -1374,34 +1410,7 @@ replaced = true; } else if (mediaUpdate.id) { const { id: newID } = mediaUpdate; - // branching for Flow - if (singleMedia.type === 'photo') { - media.push({ ...singleMedia, id: newID }); - } else if (singleMedia.type === 'video') { - media.push({ ...singleMedia, id: newID }); - } else if (singleMedia.type === 'encrypted_photo') { - // 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') { - // 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 }); - } - } + media.push({ ...singleMedia, id: newID }); replaced = true; } }