Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3386940
D7481.id25248.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
D7481.id25248.diff
View Options
diff --git a/native/components/edit-avatar.react.js b/native/components/edit-avatar.react.js
--- a/native/components/edit-avatar.react.js
+++ b/native/components/edit-avatar.react.js
@@ -6,16 +6,22 @@
import { View, TouchableOpacity, Platform } from 'react-native';
import { useSafeAreaInsets } from 'react-native-safe-area-context';
+import { uploadMultimedia } from 'lib/actions/upload-actions.js';
import {
extensionFromFilename,
filenameFromPathOrURI,
} from 'lib/media/file-utils.js';
import type { MediaLibrarySelection } from 'lib/types/media-types.js';
+import { useServerCall } from 'lib/utils/action-utils.js';
import CommIcon from '../components/comm-icon.react.js';
import SWMansionIcon from '../components/swmansion-icon.react.js';
import { getCompatibleMediaURI } from '../media/identifier-utils.js';
+import { processMedia } from '../media/media-utils.js';
+import type { MediaResult } from '../media/media-utils.js';
+import { useSelector } from '../redux/redux-utils.js';
import { useColors, useStyles } from '../themes/colors.js';
+import { useStaffCanSee } from '../utils/staff-utils.js';
type Props = {
+children: React.Node,
@@ -24,12 +30,44 @@
};
function EditAvatar(props: Props): React.Node {
const { onPressEmojiAvatarFlow, children, disabled } = props;
-
const { showActionSheetWithOptions } = useActionSheet();
const colors = useColors();
const styles = useStyles(unboundStyles);
+ const hasWiFi = useSelector(state => state.connectivity.hasWiFi);
+ const staffCanSee = useStaffCanSee();
+
+ const callUploadMultimedia = useServerCall(uploadMultimedia);
+
+ const uploadProcessedMedia = React.useCallback(
+ (processedMedia: MediaResult) => {
+ const { uploadURI, filename, mime } = processedMedia;
+
+ callUploadMultimedia(
+ {
+ uri: uploadURI,
+ name: filename,
+ type: mime,
+ },
+ { ...processedMedia.dimensions, loop: undefined },
+ );
+ },
+ [callUploadMultimedia],
+ );
+
+ const processSelectedMedia = React.useCallback(
+ async (selection: MediaLibrarySelection) => {
+ const { resultPromise } = processMedia(selection, {
+ hasWiFi,
+ finalFileHeaderCheck: staffCanSee,
+ });
+
+ return await resultPromise;
+ },
+ [hasWiFi, staffCanSee],
+ );
+
// eslint-disable-next-line no-unused-vars
const openPhotoGallery = React.useCallback(async () => {
try {
@@ -46,29 +84,34 @@
const asset = assets.pop();
const { width, height, assetId: mediaNativeID } = asset;
- const filename = asset.fileName || filenameFromPathOrURI(asset.uri) || '';
+ const assetFilename =
+ asset.fileName || filenameFromPathOrURI(asset.uri) || '';
const uri = getCompatibleMediaURI(
asset.uri,
- extensionFromFilename(filename),
+ extensionFromFilename(assetFilename),
);
const selection: MediaLibrarySelection = {
step: 'photo_library',
dimensions: { height, width },
uri,
- filename,
+ filename: assetFilename,
mediaNativeID,
selectTime: 0,
sendTime: 0,
retries: 0,
};
- return selection;
+ const processedMedia = await processSelectedMedia(selection);
+ if (!processedMedia.success) {
+ return;
+ }
+ uploadProcessedMedia(processedMedia);
} catch (e) {
console.log(e);
return;
}
- }, []);
+ }, [processSelectedMedia, uploadProcessedMedia]);
const editAvatarOptions = React.useMemo(() => {
const options = [
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Nov 30, 6:56 AM (20 h, 22 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2600019
Default Alt Text
D7481.id25248.diff (3 KB)
Attached To
Mode
D7481: [native] Process and upload image for image avatar in `EditAvatar`
Attached
Detach File
Event Timeline
Log In to Comment