diff --git a/lib/components/base-edit-thread-avatar-provider.react.js b/lib/components/base-edit-thread-avatar-provider.react.js --- a/lib/components/base-edit-thread-avatar-provider.react.js +++ b/lib/components/base-edit-thread-avatar-provider.react.js @@ -44,12 +44,7 @@ +children: React.Node, }; function BaseEditThreadAvatarProvider(props: Props): React.Node { - const { - displayFailureAlert, - useUploadSelectedMedia, - activeThreadID, - children, - } = props; + const { useUploadSelectedMedia, activeThreadID, children } = props; const updateThreadAvatarLoadingStatus: LoadingStatus = useSelector( createLoadingStatusSelector( @@ -128,20 +123,13 @@ }, }; const action = changeThreadSettingsActionTypes.started; - const promise = (async () => { - try { - return await changeThreadSettingsCall(updateThreadRequest); - } catch (e) { - displayFailureAlert(); - throw e; - } - })(); + const promise = changeThreadSettingsCall(updateThreadRequest); dispatchActionPromise(changeThreadSettingsActionTypes, promise, { customKeyName: `${action}:${threadID}:avatar`, }); await promise; }, - [changeThreadSettingsCall, dispatchActionPromise, displayFailureAlert], + [changeThreadSettingsCall, dispatchActionPromise], ); const context = React.useMemo( 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 @@ -308,6 +308,32 @@ return selectFromGalleryAndUpdateUserAvatar; } +function useNativeSetThreadAvatar(): ( + threadID: string, + avatarRequest: UpdateUserAvatarRequest, +) => Promise { + const editThreadAvatarContext = React.useContext(EditThreadAvatarContext); + invariant(editThreadAvatarContext, 'editThreadAvatarContext must be defined'); + const { setThreadAvatar } = editThreadAvatarContext; + + const nativeSetThreadAvatar = React.useCallback( + async ( + threadID: string, + avatarRequest: UpdateUserAvatarRequest, + ): Promise => { + try { + await setThreadAvatar(threadID, avatarRequest); + } catch (e) { + displayAvatarUpdateFailureAlert(); + throw e; + } + }, + [setThreadAvatar], + ); + + return nativeSetThreadAvatar; +} + function useNativeUpdateThreadImageAvatar(): ( selection: NativeMediaSelection, threadID: string, @@ -486,5 +512,6 @@ useNativeSetUserAvatar, useNativeUpdateUserImageAvatar, useSelectFromGalleryAndUpdateThreadAvatar, + useNativeSetThreadAvatar, useNativeUpdateThreadImageAvatar, }; diff --git a/native/avatars/edit-thread-avatar.react.js b/native/avatars/edit-thread-avatar.react.js --- a/native/avatars/edit-thread-avatar.react.js +++ b/native/avatars/edit-thread-avatar.react.js @@ -9,6 +9,7 @@ import type { RawThreadInfo, ThreadInfo } from 'lib/types/thread-types.js'; import { + useNativeSetThreadAvatar, useSelectFromGalleryAndUpdateThreadAvatar, useShowAvatarActionSheet, } from './avatar-hooks.js'; @@ -30,8 +31,9 @@ const editThreadAvatarContext = React.useContext(EditThreadAvatarContext); invariant(editThreadAvatarContext, 'editThreadAvatarContext should be set'); - const { threadAvatarSaveInProgress, setThreadAvatar } = - editThreadAvatarContext; + const { threadAvatarSaveInProgress } = editThreadAvatarContext; + + const nativeSetThreadAvatar = useNativeSetThreadAvatar(); const selectFromGalleryAndUpdateThreadAvatar = useSelectFromGalleryAndUpdateThreadAvatar(); @@ -60,8 +62,8 @@ }, [navigate, threadInfo.id]); const removeAvatar = React.useCallback( - () => setThreadAvatar(threadInfo.id, { type: 'remove' }), - [setThreadAvatar, threadInfo.id], + () => nativeSetThreadAvatar(threadInfo.id, { type: 'remove' }), + [nativeSetThreadAvatar, threadInfo.id], ); const actionSheetConfig = React.useMemo(() => { diff --git a/native/chat/settings/emoji-thread-avatar-creation.react.js b/native/chat/settings/emoji-thread-avatar-creation.react.js --- a/native/chat/settings/emoji-thread-avatar-creation.react.js +++ b/native/chat/settings/emoji-thread-avatar-creation.react.js @@ -7,6 +7,7 @@ import { savedEmojiAvatarSelectorForThread } from 'lib/selectors/thread-selectors.js'; import type { RawThreadInfo, ThreadInfo } from 'lib/types/thread-types.js'; +import { useNativeSetThreadAvatar } from '../../avatars/avatar-hooks.js'; import EmojiAvatarCreation from '../../avatars/emoji-avatar-creation.react.js'; import type { ChatNavigationProp } from '../../chat/chat.react.js'; import { displayActionResultModal } from '../../navigation/action-result-modal.js'; @@ -33,16 +34,17 @@ const editThreadAvatarContext = React.useContext(EditThreadAvatarContext); invariant(editThreadAvatarContext, 'editThreadAvatarContext should be set'); + const { threadAvatarSaveInProgress } = editThreadAvatarContext; + + const nativeSetThreadAvatar = useNativeSetThreadAvatar(); - const { setThreadAvatar, threadAvatarSaveInProgress } = - editThreadAvatarContext; const setAvatar = React.useCallback( async avatarRequest => { - const result = await setThreadAvatar(threadID, avatarRequest); + const result = await nativeSetThreadAvatar(threadID, avatarRequest); displayActionResultModal('Avatar updated!'); return result; }, - [setThreadAvatar, threadID], + [nativeSetThreadAvatar, threadID], ); return (