Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3401934
D8374.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
6 KB
Referenced Files
None
Subscribers
None
D8374.diff
View Options
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
@@ -139,7 +139,7 @@
return {
id,
type: 'encrypted_photo',
- holder: uri,
+ blobURI: uri,
dimensions,
thumbHash,
encryptionKey: uploadExtra.encryptionKey,
@@ -223,7 +223,7 @@
return {
type: 'encrypted_photo',
id: uploadID.toString(),
- holder: uri,
+ blobURI: uri,
encryptionKey,
dimensions,
thumbHash,
@@ -254,11 +254,11 @@
return {
type: 'encrypted_video',
id: uploadID.toString(),
- holder: uri,
+ blobURI: uri,
encryptionKey,
dimensions,
thumbnailID,
- thumbnailHolder: thumbnailURI,
+ thumbnailBlobURI: thumbnailURI,
thumbnailEncryptionKey,
thumbnailThumbHash,
};
@@ -334,7 +334,7 @@
media.push({
type: 'encrypted_photo',
id: primaryUploadID,
- holder: primaryUploadURI,
+ blobURI: primaryUploadURI,
encryptionKey,
dimensions,
thumbHash,
@@ -367,11 +367,11 @@
const video = {
type: 'encrypted_video',
id: primaryUploadID,
- holder: primaryUploadURI,
+ blobURI: primaryUploadURI,
encryptionKey,
dimensions,
thumbnailID: thumbnailUploadID,
- thumbnailHolder: thumbnailUploadURI,
+ thumbnailBlobURI: thumbnailUploadURI,
thumbnailEncryptionKey: thumbnailUploadExtra.encryptionKey,
thumbnailThumbHash,
};
diff --git a/lib/media/media-utils.js b/lib/media/media-utils.js
--- a/lib/media/media-utils.js
+++ b/lib/media/media-utils.js
@@ -2,6 +2,11 @@
import invariant from 'invariant';
+import {
+ FUTURE_CODE_VERSION,
+ hasMinCodeVersion,
+} from '../shared/version-utils.js';
+import type { PlatformDetails } from '../types/device-types.js';
import type {
EncryptedImage,
EncryptedVideo,
@@ -11,6 +16,7 @@
MultimediaMessageInfo,
RawMultimediaMessageInfo,
} from '../types/message-types.js';
+import type { RawMediaMessageInfo } from '../types/messages/media.js';
import {
isBlobServiceURI,
getBlobFetchableURL,
@@ -56,6 +62,53 @@
);
}
+/** Clients before FUTURE_CODE_VERSION understand only `holder`
+ * and `thumbnailHolder` fields, while newer clients understand `blobURI`
+ * and `thumbnailBlobURI`. This function formats the multimedia message
+ * to be understandable by clients based on their version
+ */
+function versionSpecificMediaMessageFormat(
+ rawMessageInfo: RawMediaMessageInfo,
+ platformDetails: ?PlatformDetails,
+): RawMediaMessageInfo {
+ const isBlobURISupported = hasMinCodeVersion(platformDetails, {
+ native: FUTURE_CODE_VERSION,
+ });
+ const media = rawMessageInfo.media.map(singleMedia => {
+ if (singleMedia.type === 'photo' || singleMedia.type === 'video') {
+ return singleMedia;
+ }
+
+ if (singleMedia.type === 'encrypted_photo') {
+ const { blobURI, holder, ...photoMedia } = singleMedia;
+ const mediaURI = encryptedMediaBlobURI(singleMedia);
+ return isBlobURISupported
+ ? { ...photoMedia, blobURI: mediaURI }
+ : { ...photoMedia, holder: mediaURI };
+ }
+
+ // encrypted_video
+ const {
+ blobURI,
+ holder,
+ thumbnailBlobURI,
+ thumbnailHolder,
+ ...videoMedia
+ } = singleMedia;
+ const mediaURI = encryptedMediaBlobURI(singleMedia);
+ const thumbnailURI = encryptedVideoThumbnailBlobURI(singleMedia);
+
+ return isBlobURISupported
+ ? { ...videoMedia, blobURI: mediaURI, thumbnailBlobURI: thumbnailURI }
+ : { ...videoMedia, holder: mediaURI, thumbnailHolder: thumbnailURI };
+ });
+
+ return {
+ ...rawMessageInfo,
+ media,
+ };
+}
+
function fetchableMediaURI(uri: string): string {
if (isBlobServiceURI(uri)) {
const blobHash = blobHashFromBlobServiceURI(uri);
@@ -107,6 +160,7 @@
multimediaMessagePreview,
isLocalUploadID,
isMediaBlobServiceHosted,
+ versionSpecificMediaMessageFormat,
getNextLocalUploadID,
fetchableMediaURI,
encryptedMediaBlobURI,
diff --git a/lib/shared/messages/multimedia-message-spec.js b/lib/shared/messages/multimedia-message-spec.js
--- a/lib/shared/messages/multimedia-message-spec.js
+++ b/lib/shared/messages/multimedia-message-spec.js
@@ -10,6 +10,7 @@
} from './message-spec.js';
import { joinResult } from './utils.js';
import {
+ versionSpecificMediaMessageFormat,
isMediaBlobServiceHosted,
contentStringForMediaArray,
multimediaMessagePreview,
@@ -214,10 +215,15 @@
return rawMessageInfo;
}
- const containsBlobServiceMedia = rawMessageInfo.media.some(
+ const messageInfo = versionSpecificMediaMessageFormat(
+ rawMessageInfo,
+ platformDetails,
+ );
+
+ const containsBlobServiceMedia = messageInfo.media.some(
isMediaBlobServiceHosted,
);
- const containsEncryptedMedia = rawMessageInfo.media.some(
+ const containsEncryptedMedia = messageInfo.media.some(
media =>
media.type === 'encrypted_photo' || media.type === 'encrypted_video',
);
@@ -226,28 +232,28 @@
!containsEncryptedMedia &&
hasMinCodeVersion(platformDetails, { native: 158 })
) {
- return rawMessageInfo;
+ return messageInfo;
}
if (
!containsBlobServiceMedia &&
hasMinCodeVersion(platformDetails, { native: 205 })
) {
- return rawMessageInfo;
+ return messageInfo;
}
if (hasMinCodeVersion(platformDetails, { native: FUTURE_CODE_VERSION })) {
- return rawMessageInfo;
+ return messageInfo;
}
- const { id } = rawMessageInfo;
+ const { id } = messageInfo;
invariant(id !== null && id !== undefined, 'id should be set on server');
return {
type: messageTypes.UNSUPPORTED,
id,
- threadID: rawMessageInfo.threadID,
- creatorID: rawMessageInfo.creatorID,
- time: rawMessageInfo.time,
- robotext: multimediaMessagePreview(rawMessageInfo),
- unsupportedMessageInfo: rawMessageInfo,
+ threadID: messageInfo.threadID,
+ creatorID: messageInfo.creatorID,
+ time: messageInfo.time,
+ robotext: multimediaMessagePreview(messageInfo),
+ unsupportedMessageInfo: messageInfo,
};
},
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Dec 3, 2:36 PM (21 h, 52 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2612024
Default Alt Text
D8374.diff (6 KB)
Attached To
Mode
D8374: [lib][keyserver] Use blobURI based on client version
Attached
Detach File
Event Timeline
Log In to Comment