diff --git a/keyserver/src/fetchers/upload-fetchers.js b/keyserver/src/fetchers/upload-fetchers.js --- a/keyserver/src/fetchers/upload-fetchers.js +++ b/keyserver/src/fetchers/upload-fetchers.js @@ -105,15 +105,34 @@ const id = row.uploadID.toString(); const dimensions = { width, height }; const uri = getUploadURL(id, secret); + const isEncrypted = !!uploadExtra.encryptionKey; if (type === 'photo') { - return { id, type: 'photo', uri, dimensions }; - } else if (loop) { - // $FlowFixMe add thumbnailID, thumbnailURI once they're in DB - return { id, type: 'video', uri, dimensions, loop }; + if (!isEncrypted) { + return { id, type: 'photo', uri, dimensions }; + } + return { + id, + type: 'encrypted_photo', + holder: uri, + dimensions, + encryptionKey: uploadExtra.encryptionKey, + }; + } + + let video; + if (!isEncrypted) { + video = { id, type: 'video', uri, dimensions }; } else { - // $FlowFixMe add thumbnailID, thumbnailURI once they're in DB - return { id, type: 'video', uri, dimensions }; + video = { + id, + type: 'encrypted_video', + holder: uri, + dimensions, + encryptionKey: uploadExtra.encryptionKey, + }; } + // $FlowFixMe add thumbnailID, thumbnailURI once they're in DB + return loop ? { ...video, loop } : video; } async function fetchMedia( diff --git a/keyserver/src/responders/message-responders.js b/keyserver/src/responders/message-responders.js --- a/keyserver/src/responders/message-responders.js +++ b/keyserver/src/responders/message-responders.js @@ -188,13 +188,20 @@ throw new ServerError('invalid_parameters'); } - const messageData = createMediaMessageData({ - localID, - threadID, - creatorID: viewer.id, - media, - sidebarCreation, - }); + // We use the MULTIMEDIA type for encrypted photos + const containsEncryptedMedia = media.some( + m => m.type === 'encrypted_photo' || m.type === 'encrypted_video', + ); + const messageData = createMediaMessageData( + { + localID, + threadID, + creatorID: viewer.id, + media, + sidebarCreation, + }, + { forceMultimediaMessageType: containsEncryptedMedia }, + ); const [newMessageInfo] = await createMessages(viewer, [messageData]); const { id } = newMessageInfo; invariant(