Page MenuHomePhabricator

D7645.id25801.diff
No OneTemporary

D7645.id25801.diff

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

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)

Event Timeline