Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3245574
D7645.id25801.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
D7645.id25801.diff
View Options
diff --git a/native/avatars/edit-thread-avatar-provider.react.js b/native/avatars/edit-thread-avatar-provider.react.js
--- a/native/avatars/edit-thread-avatar-provider.react.js
+++ b/native/avatars/edit-thread-avatar-provider.react.js
@@ -80,46 +80,53 @@
updateThreadAvatarMediaUploadInProgress,
);
+ const updateImageThreadAvatar = React.useCallback(
+ async (selection: ?MediaLibrarySelection) => {
+ const imageAvatarUpdateRequest = await uploadThreadAvatarSelectedMedia(
+ selection,
+ );
+
+ if (!imageAvatarUpdateRequest) {
+ return;
+ }
+
+ const updateThreadRequest: UpdateThreadRequest = {
+ threadID: activeThreadID,
+ changes: {
+ avatar: imageAvatarUpdateRequest,
+ },
+ };
+
+ const action = changeThreadSettingsActionTypes.started;
+ dispatchActionPromise(
+ changeThreadSettingsActionTypes,
+ (async () => {
+ updateThreadAvatarMediaUploadInProgress(false);
+ try {
+ return await changeThreadSettingsCall(updateThreadRequest);
+ } catch (e) {
+ Alert.alert('Avatar update failed', 'Unable to update avatar.');
+ throw e;
+ }
+ })(),
+ {
+ customKeyName: `${action}:${activeThreadID}:avatar`,
+ },
+ );
+ },
+ [
+ activeThreadID,
+ changeThreadSettingsCall,
+ dispatchActionPromise,
+ updateThreadAvatarMediaUploadInProgress,
+ uploadThreadAvatarSelectedMedia,
+ ],
+ );
+
const selectFromGalleryAndUpdateThreadAvatar = React.useCallback(async () => {
const selection: ?MediaLibrarySelection = await selectFromGallery();
- const imageAvatarUpdateRequest = await uploadThreadAvatarSelectedMedia(
- selection,
- );
-
- if (!imageAvatarUpdateRequest) {
- return;
- }
-
- const updateThreadRequest: UpdateThreadRequest = {
- threadID: activeThreadID,
- changes: {
- avatar: imageAvatarUpdateRequest,
- },
- };
-
- const action = changeThreadSettingsActionTypes.started;
- dispatchActionPromise(
- changeThreadSettingsActionTypes,
- (async () => {
- updateThreadAvatarMediaUploadInProgress(false);
- try {
- return await changeThreadSettingsCall(updateThreadRequest);
- } catch (e) {
- Alert.alert('Avatar update failed', 'Unable to update avatar.');
- throw e;
- }
- })(),
- {
- customKeyName: `${action}:${activeThreadID}:avatar`,
- },
- );
- }, [
- activeThreadID,
- changeThreadSettingsCall,
- dispatchActionPromise,
- updateThreadAvatarMediaUploadInProgress,
- uploadThreadAvatarSelectedMedia,
- ]);
+ await updateImageThreadAvatar(selection);
+ }, [updateImageThreadAvatar]);
const removeThreadAvatar = React.useCallback(() => {
const removeAvatarRequest: UpdateUserAvatarRemoveRequest = {
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Nov 15, 7:25 PM (21 h, 42 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2495171
Default Alt Text
D7645.id25801.diff (2 KB)
Attached To
Mode
D7645: [native] improve factoring out redundant logic for saving an image thread avatar
Attached
Detach File
Event Timeline
Log In to Comment