Skip to content

Commit

Permalink
[native][web] Clean up dead conditions for media encryption
Browse files Browse the repository at this point in the history
Summary:
In D13890 and D13891 some hardcoded switches were flipped, producing a dead code.
Removed unnecessary conditions and simplified code a bit.

Depends on D13891

Test Plan: Flow, eslint, test plans from D13890, D13891 to check for regressions

Reviewers: ashoat

Reviewed By: ashoat

Subscribers: tomek

Differential Revision: https://phab.comm.dev/D13892
  • Loading branch information
barthap committed Nov 8, 2024
1 parent 39b8726 commit 95e169f
Show file tree
Hide file tree
Showing 8 changed files with 133 additions and 393 deletions.
69 changes: 0 additions & 69 deletions lib/actions/upload-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,74 +43,6 @@ export type MultimediaUploadCallbacks = Partial<{
+blobServiceUploadHandler: BlobServiceUploadHandler,
+timeout: ?number,
}>;
export type MultimediaUploadExtras = $ReadOnly<
Partial<{
...Dimensions,
+loop: boolean,
+encryptionKey: string,
+thumbHash: ?string,
}>,
>;

const uploadMultimedia =
(
callSingleKeyserverEndpoint: CallSingleKeyserverEndpoint,
): ((
multimedia: Object,
extras: MultimediaUploadExtras,
callbacks?: MultimediaUploadCallbacks,
) => Promise<UploadMultimediaResult>) =>
async (multimedia, extras, callbacks) => {
const onProgress = callbacks && callbacks.onProgress;
const abortHandler = callbacks && callbacks.abortHandler;
const performHTTPMultipartUpload =
callbacks && callbacks.performHTTPMultipartUpload;

const stringExtras: { [string]: string } = {};
if (extras.height !== null && extras.height !== undefined) {
stringExtras.height = extras.height.toString();
}
if (extras.width !== null && extras.width !== undefined) {
stringExtras.width = extras.width.toString();
}
if (extras.loop) {
stringExtras.loop = '1';
}
if (extras.encryptionKey) {
stringExtras.encryptionKey = extras.encryptionKey;
}
if (extras.thumbHash) {
stringExtras.thumbHash = extras.thumbHash;
}

// also pass MIME type if available
if (multimedia.type && typeof multimedia.type === 'string') {
stringExtras.mimeType = multimedia.type;
}

const response = await callSingleKeyserverEndpoint(
'upload_multimedia',
{
...stringExtras,
multimedia: [multimedia],
},
{
onProgress,
abortHandler,
performHTTPMultipartUpload: performHTTPMultipartUpload
? performHTTPMultipartUpload
: true,
},
);
const [uploadResult] = response.results;
return {
id: uploadResult.id,
uri: uploadResult.uri,
dimensions: uploadResult.dimensions,
mediaType: uploadResult.mediaType,
loop: uploadResult.loop,
};
};

export type DeleteUploadInput = {
+id: string,
Expand Down Expand Up @@ -447,7 +379,6 @@ function useMediaMetadataReassignment(): MediaMetadataReassignmentAction {
}

export {
uploadMultimedia,
useBlobServiceUpload,
useMediaMetadataReassignment,
updateMultimediaMessageMediaActionType,
Expand Down
11 changes: 0 additions & 11 deletions lib/facts/comm-staff-community.js

This file was deleted.

8 changes: 0 additions & 8 deletions lib/shared/thread-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -1623,13 +1623,6 @@ function patchThreadInfoToIncludeMentionedMembersOfParent(
});
}

function threadInfoInsideCommunity(
threadInfo: RawThreadInfo | ThreadInfo,
communityID: string,
): boolean {
return threadInfo.community === communityID || threadInfo.id === communityID;
}

type RoleAndMemberCount = {
[roleName: string]: number,
};
Expand Down Expand Up @@ -1956,7 +1949,6 @@ export {
useAvailableThreadMemberActions,
threadMembersWithoutAddedAdmin,
patchThreadInfoToIncludeMentionedMembersOfParent,
threadInfoInsideCommunity,
useRoleMemberCountsForCommunity,
useRoleNamesToSpecialRole,
useRoleUserSurfacedPermissions,
Expand Down
29 changes: 2 additions & 27 deletions native/avatars/avatar-hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,9 @@ import { Platform } from 'react-native';
import filesystem from 'react-native-fs';
import { useSafeAreaInsets } from 'react-native-safe-area-context';

import {
uploadMultimedia,
useBlobServiceUpload,
} from 'lib/actions/upload-actions.js';
import { useBlobServiceUpload } from 'lib/actions/upload-actions.js';
import { EditThreadAvatarContext } from 'lib/components/base-edit-thread-avatar-provider.react.js';
import { EditUserAvatarContext } from 'lib/components/edit-user-avatar-provider.react.js';
import { useLegacyAshoatKeyserverCall } from 'lib/keyserver-conn/legacy-keyserver-call.js';
import {
extensionFromFilename,
filenameFromPathOrURI,
Expand Down Expand Up @@ -44,8 +40,6 @@ import Alert from '../utils/alert.js';
import blobServiceUploadHandler from '../utils/blob-service-upload.js';
import { useStaffCanSee } from '../utils/staff-utils.js';

const useBlobServiceUploads = true;

function displayAvatarUpdateFailureAlert(): void {
Alert.alert(
'Couldn’t save avatar',
Expand All @@ -59,28 +53,9 @@ function useUploadProcessedMedia(): (
media: MediaResult,
metadataUploadLocation: 'keyserver' | 'none',
) => Promise<?UpdateUserAvatarRequest> {
const callUploadMultimedia = useLegacyAshoatKeyserverCall(uploadMultimedia);
const callBlobServiceUpload = useBlobServiceUpload();
return React.useCallback(
async (processedMedia, metadataUploadLocation) => {
const useBlobService =
metadataUploadLocation !== 'keyserver' || useBlobServiceUploads;
if (!useBlobService) {
const { uploadURI, filename, mime, dimensions } = processedMedia;
const { id } = await callUploadMultimedia(
{
uri: uploadURI,
name: filename,
type: mime,
},
dimensions,
);
if (!id) {
return undefined;
}
return { type: 'image', uploadID: id };
}

const { result: encryptionResult } = await encryptMedia(processedMedia);
if (!encryptionResult.success) {
throw new Error('Avatar media encryption failed.');
Expand Down Expand Up @@ -132,7 +107,7 @@ function useUploadProcessedMedia(): (
}
return { type: 'encrypted_image', uploadID: id };
},
[callUploadMultimedia, callBlobServiceUpload],
[callBlobServiceUpload],
);
}

Expand Down
Loading

0 comments on commit 95e169f

Please sign in to comment.