Bluesky app fork with some witchin' additions 💫
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Integrate more group chat settings (#10253)

authored by

DS Boyce and committed by
GitHub
a9e170b6 f51602b3

+58 -15
+58 -15
src/screens/Messages/ConversationSettings.tsx
··· 3 3 import {type ChatBskyConvoDefs, moderateProfile} from '@atproto/api' 4 4 import {plural} from '@lingui/core/macro' 5 5 import {Trans, useLingui} from '@lingui/react/macro' 6 - import {useNavigation} from '@react-navigation/native' 6 + import {StackActions, useNavigation} from '@react-navigation/native' 7 7 8 8 import {useBottomBarOffset} from '#/lib/hooks/useBottomBarOffset' 9 9 import {useInitialNumToRender} from '#/lib/hooks/useInitialNumToRender' ··· 22 22 import {useModerationOpts} from '#/state/preferences/moderation-opts' 23 23 import {useGetConvoAvailabilityQuery} from '#/state/queries/messages/get-convo-availability' 24 24 import {useGetConvoForMembers} from '#/state/queries/messages/get-convo-for-members' 25 + import {useLeaveConvo} from '#/state/queries/messages/leave-conversation' 25 26 import {useMuteConvo} from '#/state/queries/messages/mute-conversation' 26 27 import {useProfileBlockMutationQueue} from '#/state/queries/profile' 27 28 import {useSession} from '#/state/session' ··· 186 187 return ( 187 188 <List 188 189 data={items} 189 - contentContainerStyle={ 190 - IS_NATIVE && {paddingBottom: bottomBarOffset + ROW_SPACING} 191 - } 190 + contentContainerStyle={{paddingBottom: bottomBarOffset + ROW_SPACING}} 192 191 desktopFixedHeight 193 192 initialNumToRender={initialNumToRender} 194 193 keyExtractor={keyExtractor} ··· 670 669 const t = useTheme() 671 670 const {t: l} = useLingui() 672 671 672 + const navigation = useNavigation<NavigationProp>() 673 673 const convoState = useConvo() 674 674 const {currentAccount} = useSession() 675 675 ··· 686 686 Toast.show(l({message: 'Group chat unmuted', context: 'toast'})) 687 687 } 688 688 }, 689 - onError: () => { 690 - Toast.show(l`Could not mute group chat`, { 689 + onError: e => { 690 + logger.error('Failed to mute group chat', {message: e}) 691 + Toast.show(l`Failed to mute group chat`, { 692 + type: 'error', 693 + }) 694 + }, 695 + }) 696 + 697 + const {mutate: leaveConvo} = useLeaveConvo(convo.id, { 698 + onMutate: () => { 699 + navigation.dispatch(StackActions.pop(2)) 700 + }, 701 + onError: e => { 702 + logger.error('Failed to leave group chat', {message: e}) 703 + Toast.show(l({message: 'Failed to leave group chat', context: 'toast'}), { 691 704 type: 'error', 692 705 }) 693 706 }, ··· 696 709 const editNamePrompt = Prompt.usePromptControl() 697 710 const inviteLinkPrompt = Prompt.usePromptControl() 698 711 const lockChatPrompt = Prompt.usePromptControl() 712 + const leaveChatPrompt = Prompt.usePromptControl() 699 713 700 714 const [groupName, setGroupName] = useState( 701 715 convoState.getGroupInfo?.()?.name ?? '', ··· 705 719 const [isLocked, setIsLocked] = useState(false) 706 720 707 721 const handleToggleMute = () => { 708 - try { 709 - muteConvo({mute: !convo?.muted}) 710 - } catch (err) { 711 - const e = err as Error 712 - logger.error('Failed to mute group chat', {message: e}) 713 - Toast.show(l`There was an issue! ${e.toString()}`, {type: 'error'}) 714 - } 722 + muteConvo({mute: !convo?.muted}) 723 + } 724 + 725 + const handleLeaveChat = () => { 726 + leaveChatPrompt.open() 715 727 } 728 + 729 + const handleReportChat = () => {} 716 730 717 731 const handlePromptName = () => { 718 732 editNamePrompt.open() ··· 818 832 icon={FlagIcon} 819 833 label={l`Report this group chat`} 820 834 text={l`Report`} 821 - onPress={() => {}} 835 + onPress={handleReportChat} 822 836 /> 823 837 )} 824 838 {isOwner ? null : ( ··· 827 841 icon={ArrowBoxLeftIcon} 828 842 label={l`Leave this group chat`} 829 843 text={l`Leave`} 830 - onPress={() => {}} 844 + onPress={handleLeaveChat} 831 845 /> 832 846 )} 833 847 </View> ··· 843 857 onConfirm={handleConfirmInviteLink} 844 858 /> 845 859 <LockChatPrompt control={lockChatPrompt} onConfirm={handleConfirmLock} /> 860 + <LeaveChatPrompt 861 + control={leaveChatPrompt} 862 + groupName={groupName} 863 + onConfirm={leaveConvo} 864 + /> 846 865 </> 847 866 ) 848 867 } ··· 1036 1055 title={l`Lock group chat?`} 1037 1056 description={l`Members can still read chat history but can’t send new messages.`} 1038 1057 confirmButtonCta={l`Lock group chat`} 1058 + cancelButtonCta={l`Cancel`} 1059 + onConfirm={onConfirm} 1060 + /> 1061 + ) 1062 + } 1063 + 1064 + function LeaveChatPrompt({ 1065 + control, 1066 + groupName, 1067 + onConfirm, 1068 + }: { 1069 + control: Dialog.DialogOuterProps['control'] 1070 + groupName: string 1071 + onConfirm: () => void 1072 + }) { 1073 + const {t: l} = useLingui() 1074 + 1075 + return ( 1076 + <Prompt.Basic 1077 + control={control} 1078 + title={l`Are you sure you want to leave ${groupName}?`} 1079 + description={l`You won’t be able to rejoin unless you’re invited.`} 1080 + confirmButtonCta={l`Leave group chat`} 1081 + confirmButtonColor="negative" 1039 1082 cancelButtonCta={l`Cancel`} 1040 1083 onConfirm={onConfirm} 1041 1084 />