diff --git a/native/account/registration/registration-server-call.js b/native/account/registration/registration-server-call.js --- a/native/account/registration/registration-server-call.js +++ b/native/account/registration/registration-server-call.js @@ -567,7 +567,10 @@ ({ updateUserAvatarRequest } = avatarData); } else { const { mediaSelection } = avatarData; - updateUserAvatarRequest = await uploadSelectedMedia(mediaSelection); + updateUserAvatarRequest = await uploadSelectedMedia( + mediaSelection, + true, + ); if (!updateUserAvatarRequest) { return; } diff --git a/native/avatars/avatar-hooks.js b/native/avatars/avatar-hooks.js --- a/native/avatars/avatar-hooks.js +++ b/native/avatars/avatar-hooks.js @@ -19,10 +19,7 @@ extensionFromFilename, filenameFromPathOrURI, } from 'lib/media/file-utils.js'; -import type { - AvatarDBContent, - UpdateUserAvatarRequest, -} from 'lib/types/avatar-types.js'; +import type { UpdateUserAvatarRequest } from 'lib/types/avatar-types.js'; import type { NativeMediaSelection, MediaLibrarySelection, @@ -54,13 +51,18 @@ ); } -function useUploadProcessedMedia(): MediaResult => Promise { +function useUploadProcessedMedia(): ( + media: MediaResult, + shouldUploadMetadataToKeyserver: boolean, +) => Promise { const callUploadMultimedia = useLegacyAshoatKeyserverCall(uploadMultimedia); const callBlobServiceUpload = useBlobServiceUpload(); - const uploadProcessedMultimedia: MediaResult => Promise = + const uploadProcessedMultimedia: MediaResult => Promise = React.useCallback( - async processedMedia => { - if (!useBlobServiceUploads) { + async (processedMedia, shouldUploadMetadataToKeyserver) => { + const useBlobService = + !shouldUploadMetadataToKeyserver || useBlobServiceUploads; + if (!useBlobService) { const { uploadURI, filename, mime, dimensions } = processedMedia; const { id } = await callUploadMultimedia( { @@ -94,7 +96,7 @@ dimensions, thumbHash, } = encryptionResult; - const { id } = await callBlobServiceUpload({ + const { id, uri } = await callBlobServiceUpload({ uploadInput: { blobInput: { type: 'uri', @@ -108,9 +110,19 @@ thumbHash, loop: false, }, - keyserverOrThreadID: authoritativeKeyserverID, + keyserverOrThreadID: shouldUploadMetadataToKeyserver + ? authoritativeKeyserverID + : null, callbacks: { blobServiceUploadHandler }, }); + if (!shouldUploadMetadataToKeyserver) { + return { + type: 'thick_thread_image', + blobURI: uri, + thumbHash, + encryptionKey, + }; + } if (!id) { return undefined; } @@ -185,12 +197,18 @@ function useUploadSelectedMedia( setProcessingOrUploadInProgress?: (inProgress: boolean) => mixed, -): (selection: NativeMediaSelection) => Promise { +): ( + selection: NativeMediaSelection, + shouldUploadMetadataToKeyserver: boolean, +) => Promise { const processSelectedMedia = useProcessSelectedMedia(); const uploadProcessedMedia = useUploadProcessedMedia(); return React.useCallback( - async (selection: NativeMediaSelection) => { + async ( + selection: NativeMediaSelection, + shouldUploadMetadataToKeyserver, + ) => { setProcessingOrUploadInProgress?.(true); const urisToBeDisposed: Set = new Set([selection.uri]); @@ -220,10 +238,14 @@ return undefined; } - let uploadedMedia: ?AvatarDBContent; + let uploadedMedia: ?UpdateUserAvatarRequest; try { - uploadedMedia = await uploadProcessedMedia(processedMedia); + uploadedMedia = await uploadProcessedMedia( + processedMedia, + shouldUploadMetadataToKeyserver, + ); urisToBeDisposed.forEach(filesystem.unlink); + setProcessingOrUploadInProgress?.(false); } catch { urisToBeDisposed.forEach(filesystem.unlink); Alert.alert( @@ -319,7 +341,10 @@ return; } - const imageAvatarUpdateRequest = await uploadSelectedMedia(selection); + const imageAvatarUpdateRequest = await uploadSelectedMedia( + selection, + true, + ); if (!imageAvatarUpdateRequest) { return; } @@ -400,7 +425,10 @@ selection: NativeMediaSelection, threadID: string, ): Promise => { - const imageAvatarUpdateRequest = await uploadSelectedMedia(selection); + const imageAvatarUpdateRequest = await uploadSelectedMedia( + selection, + true, + ); if (!imageAvatarUpdateRequest) { return; }