Changeset View
Changeset View
Standalone View
Standalone View
lib/reducers/message-reducer.js
Show First 20 Lines • Show All 1,230 Lines • ▼ Show 20 Lines | if (message.type === messageTypes.IMAGES) { | ||||
media.push({ ...singleMedia, ...mediaUpdate }); | media.push({ ...singleMedia, ...mediaUpdate }); | ||||
replaced = true; | replaced = true; | ||||
} else if ( | } else if ( | ||||
singleMedia.type === 'video' && | singleMedia.type === 'video' && | ||||
mediaUpdate.type === 'video' | mediaUpdate.type === 'video' | ||||
) { | ) { | ||||
media.push({ ...singleMedia, ...mediaUpdate }); | media.push({ ...singleMedia, ...mediaUpdate }); | ||||
replaced = true; | 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 }; | updatedMessage = { ...message, media }; | ||||
} | } | ||||
invariant( | invariant( | ||||
replaced, | replaced, | ||||
`message ${id} did not contain media with ID ${currentMediaID}`, | `message ${id} did not contain media with ID ${currentMediaID}`, | ||||
▲ Show 20 Lines • Show All 216 Lines • Show Last 20 Lines |