|
@@ -12,7 +12,9 @@ import {
|
|
|
usePostDeleteChatMutation,
|
|
|
usePostReportConversationMutation,
|
|
|
usePostSetBlockMutation,
|
|
|
- usePostSetMuteMutation
|
|
|
+ usePostSetMuteMutation,
|
|
|
+ usePostSetMuteForGroupMutation,
|
|
|
+ usePostLeaveGroupMutation
|
|
|
} from '@api/chat';
|
|
|
import { useChatStore } from 'src/stores/chatStore';
|
|
|
import TrashIcon from 'assets/icons/travels-screens/trash-solid.svg';
|
|
@@ -20,6 +22,8 @@ import BanIcon from 'assets/icons/messages/ban.svg';
|
|
|
import BellSlashIcon from 'assets/icons/messages/bell-slash.svg';
|
|
|
import { AvatarWithInitials } from 'src/components';
|
|
|
import MegaphoneIcon from 'assets/icons/messages/megaphone.svg';
|
|
|
+import ExitIcon from 'assets/icons/messages/exit.svg';
|
|
|
+import GroupIcon from 'assets/icons/messages/group-chat.svg';
|
|
|
|
|
|
const MoreModal = () => {
|
|
|
const insets = useSafeAreaInsets();
|
|
@@ -39,6 +43,8 @@ const MoreModal = () => {
|
|
|
const { mutateAsync: blockUser } = usePostSetBlockMutation();
|
|
|
const { mutateAsync: deleteChat } = usePostDeleteChatMutation();
|
|
|
const { mutateAsync: reportUser } = usePostReportConversationMutation();
|
|
|
+ const { mutateAsync: muteGroup } = usePostSetMuteForGroupMutation();
|
|
|
+ const { mutateAsync: leaveGroup } = usePostLeaveGroupMutation();
|
|
|
|
|
|
const [shouldOpenWarningModal, setShouldOpenWarningModal] = useState<WarningProps | null>(null);
|
|
|
|
|
@@ -64,19 +70,32 @@ const MoreModal = () => {
|
|
|
const handleMute = async () => {
|
|
|
if (!chatData) return;
|
|
|
|
|
|
- chatData.uid &&
|
|
|
- (await muteUser(
|
|
|
- {
|
|
|
- token: chatData.token,
|
|
|
- value: chatData.muted === 1 ? 0 : 1,
|
|
|
- conversation_with_user: chatData.uid
|
|
|
- },
|
|
|
- {
|
|
|
- onSuccess: () => {
|
|
|
- setChatData({ ...chatData, muted: chatData.muted === 1 ? 0 : 1 });
|
|
|
+ chatData.uid
|
|
|
+ ? await muteUser(
|
|
|
+ {
|
|
|
+ token: chatData.token,
|
|
|
+ value: chatData.muted === 1 ? 0 : 1,
|
|
|
+ conversation_with_user: chatData.uid
|
|
|
+ },
|
|
|
+ {
|
|
|
+ onSuccess: () => {
|
|
|
+ setChatData({ ...chatData, muted: chatData.muted === 1 ? 0 : 1 });
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
- ));
|
|
|
+ )
|
|
|
+ : await muteGroup(
|
|
|
+ {
|
|
|
+ token: chatData.token,
|
|
|
+ value: chatData.muted === 1 ? 0 : 1,
|
|
|
+ group_token: chatData.groupToken as string
|
|
|
+ },
|
|
|
+ {
|
|
|
+ onSuccess: () => {
|
|
|
+ setChatData({ ...chatData, muted: chatData.muted === 1 ? 0 : 1 });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ );
|
|
|
+
|
|
|
chatData.refetch();
|
|
|
};
|
|
|
|
|
@@ -151,6 +170,37 @@ const MoreModal = () => {
|
|
|
}, 300);
|
|
|
};
|
|
|
|
|
|
+ const handleLeaveGroup = async () => {
|
|
|
+ if (!chatData) return;
|
|
|
+
|
|
|
+ setShouldOpenWarningModal({
|
|
|
+ title: `Leave group ${name}`,
|
|
|
+ buttonTitle: 'Leave',
|
|
|
+ message: `Are you sure you want to leave ${name}?`,
|
|
|
+ action: async () => {
|
|
|
+ chatData.groupToken &&
|
|
|
+ (await leaveGroup(
|
|
|
+ {
|
|
|
+ token: chatData.token,
|
|
|
+ group_token: chatData.groupToken
|
|
|
+ },
|
|
|
+ {
|
|
|
+ onSuccess: (res) => {
|
|
|
+ console.log(res);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ));
|
|
|
+
|
|
|
+ chatData.refetch();
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ setTimeout(() => {
|
|
|
+ SheetManager.hide('more-modal');
|
|
|
+ setShouldOpenWarningModal(null);
|
|
|
+ }, 300);
|
|
|
+ };
|
|
|
+
|
|
|
return (
|
|
|
<ActionSheet
|
|
|
id="more-modal"
|
|
@@ -182,9 +232,9 @@ const MoreModal = () => {
|
|
|
}}
|
|
|
disabled={chatData?.userType !== 'normal'}
|
|
|
>
|
|
|
- {chatData?.avatar && chatData?.userType === 'normal' ? (
|
|
|
+ {chatData?.avatar && (chatData.userType === 'normal' || !chatData.userType) ? (
|
|
|
<Image source={{ uri: API_HOST + chatData.avatar }} style={styles.avatar} />
|
|
|
- ) : chatData?.userType === 'normal' ? (
|
|
|
+ ) : chatData.uid && (chatData.userType === 'normal' || !chatData.userType) ? (
|
|
|
<AvatarWithInitials
|
|
|
text={
|
|
|
chatData.name
|
|
@@ -196,6 +246,8 @@ const MoreModal = () => {
|
|
|
size={32}
|
|
|
fontSize={12}
|
|
|
/>
|
|
|
+ ) : chatData.userType === 'normal' || !chatData.userType ? (
|
|
|
+ <GroupIcon fill={Colors.DARK_BLUE} width={32} height={32} />
|
|
|
) : (
|
|
|
<BanIcon fill={Colors.RED} width={32} height={32} />
|
|
|
)}
|
|
@@ -218,6 +270,16 @@ const MoreModal = () => {
|
|
|
<View style={[styles.optionsContainer, { paddingVertical: 0, gap: 0 }]}>
|
|
|
{chatData?.userType === 'normal' && (
|
|
|
<>
|
|
|
+ {chatData?.groupToken && (
|
|
|
+ <TouchableOpacity
|
|
|
+ style={[styles.option, styles.dangerOption]}
|
|
|
+ onPress={handleLeaveGroup}
|
|
|
+ >
|
|
|
+ <Text style={[styles.optionText, styles.dangerText]}>Leave group</Text>
|
|
|
+ <ExitIcon fill={Colors.RED} width={16} />
|
|
|
+ </TouchableOpacity>
|
|
|
+ )}
|
|
|
+
|
|
|
<TouchableOpacity
|
|
|
style={[styles.option, styles.dangerOption]}
|
|
|
onPress={handleReport}
|