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 @@ -272,6 +272,30 @@ return removeUserAvatar; } +function useRemoveThreadAvatar(threadID: string): () => Promise { + const dispatchActionPromise = useDispatchActionPromise(); + const changeThreadSettingsCall = useServerCall(changeThreadSettings); + + const removeThreadAvatar = React.useCallback(async () => { + const removeAvatarRequest: UpdateUserAvatarRemoveRequest = { + type: 'remove', + }; + + const updateThreadRequest: UpdateThreadRequest = { + threadID, + changes: { + avatar: removeAvatarRequest, + }, + }; + dispatchActionPromise( + changeThreadSettingsActionTypes, + changeThreadSettingsCall(updateThreadRequest), + ); + }, [changeThreadSettingsCall, dispatchActionPromise, threadID]); + + return removeThreadAvatar; +} + type ShowAvatarActionSheetOptions = { +id: 'emoji' | 'image' | 'cancel' | 'remove', +onPress?: () => mixed, @@ -381,4 +405,5 @@ useSelectFromGalleryAndUpdateUserAvatar, useSelectFromGalleryAndUpdateThreadAvatar, useRemoveUserAvatar, + useRemoveThreadAvatar, }; 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 @@ -6,6 +6,7 @@ import type { RawThreadInfo, ThreadInfo } from 'lib/types/thread-types.js'; import { + useRemoveThreadAvatar, useSelectFromGalleryAndUpdateThreadAvatar, useShowAvatarActionSheet, } from './avatar-hooks.js'; @@ -23,12 +24,19 @@ const selectFromGalleryAndUpdateThreadAvatar = useSelectFromGalleryAndUpdateThreadAvatar(threadInfo.id); + const removeThreadAvatar = useRemoveThreadAvatar(threadInfo.id); + const actionSheetConfig = React.useMemo( () => [ { id: 'emoji', onPress: onPressEmojiAvatarFlow }, { id: 'image', onPress: selectFromGalleryAndUpdateThreadAvatar }, + { id: 'remove', onPress: removeThreadAvatar }, + ], + [ + onPressEmojiAvatarFlow, + removeThreadAvatar, + selectFromGalleryAndUpdateThreadAvatar, ], - [onPressEmojiAvatarFlow, selectFromGalleryAndUpdateThreadAvatar], ); const showAvatarActionSheet = useShowAvatarActionSheet(actionSheetConfig);