diff --git a/lib/shared/dm-ops/send-multimedia-message-spec.js b/lib/shared/dm-ops/send-multimedia-message-spec.js --- a/lib/shared/dm-ops/send-multimedia-message-spec.js +++ b/lib/shared/dm-ops/send-multimedia-message-spec.js @@ -4,9 +4,17 @@ DMOperationSpec, ProcessDMOperationUtilities, } from './dm-op-spec.js'; -import type { DMSendMultimediaMessageOperation } from '../../types/dm-ops.js'; +import { + encryptedMediaBlobURI, + encryptedVideoThumbnailBlobURI, +} from '../../media/media-utils.js'; +import type { + DMSendMultimediaMessageOperation, + DMBlobOperation, +} from '../../types/dm-ops.js'; import { messageTypes } from '../../types/message-types-enum.js'; import type { ClientUpdateInfo } from '../../types/update-types.js'; +import { blobHashFromBlobServiceURI } from '../../utils/blob-service.js'; import { rawMessageInfoFromMessageData } from '../message-utils.js'; function createMessageDataWithInfoFromDMOperation( @@ -24,6 +32,34 @@ return { messageData, rawMessageInfo }; } +function getBlobOpsFromOperation( + dmOperation: DMSendMultimediaMessageOperation, +): Array { + const ops: Array = []; + + for (const media of dmOperation.media) { + if (media.type !== 'encrypted_photo' && media.type !== 'encrypted_video') { + continue; + } + const blobURI = encryptedMediaBlobURI(media); + ops.push({ + type: 'establish_holder', + blobHash: blobHashFromBlobServiceURI(blobURI), + dmOpType: 'inbound_only', + }); + if (media.type === 'encrypted_video') { + const thumbnailBlobURI = encryptedVideoThumbnailBlobURI(media); + ops.push({ + type: 'establish_holder', + blobHash: blobHashFromBlobServiceURI(thumbnailBlobURI), + dmOpType: 'inbound_only', + }); + } + } + + return ops; +} + const sendMultimediaMessageSpec: DMOperationSpec = Object.freeze({ notificationsCreationData: async ( @@ -42,10 +78,11 @@ createMessageDataWithInfoFromDMOperation(dmOperation); const rawMessageInfos = [rawMessageInfo]; const updateInfos: Array = []; + const blobOps = getBlobOpsFromOperation(dmOperation); return { rawMessageInfos, updateInfos, - blobOps: [], + blobOps, }; }, canBeProcessed: async (