Jelajahi Sumber

zoom to user locstion, deleted users on the Chat list

Viktoriia 6 bulan lalu
induk
melakukan
700547f67b

+ 1 - 0
src/modules/api/chat/chat-api.ts

@@ -30,6 +30,7 @@ export interface PostGetChatsListReturn extends ResponseType {
     attachement_name: string;
     encrypted: 0 | 1;
     muted: 0 | 1;
+    user_type: 'normal' | 'not_exist' | 'blocked';
   }[];
 }
 

+ 29 - 8
src/screens/InAppScreens/MessagesScreen/ChatScreen/index.tsx

@@ -62,6 +62,8 @@ import ReactionsListModal from '../Components/ReactionsListModal';
 import { dismissChatNotifications } from '../utils';
 import { useMessagesStore } from 'src/stores/unreadMessagesStore';
 
+import BanIcon from 'assets/icons/messages/ban.svg';
+
 const options = {
   enableVibrateFallback: true,
   ignoreAndroidSystemSettings: false
@@ -71,7 +73,23 @@ const reactionEmojis = ['👍', '❤️', '😂', '😮', '😭'];
 
 const ChatScreen = ({ route }: { route: any }) => {
   const token = storage.get('token', StoreType.STRING) as string;
-  const { id, name, avatar }: { id: number; name: string; avatar: string | null } = route.params;
+  const {
+    id,
+    name,
+    avatar,
+    userType
+  }: {
+    id: number;
+    name: string;
+    avatar: string | null;
+    userType: 'normal' | 'not_exist' | 'blocked';
+  } = route.params;
+  const userName =
+    userType === 'blocked'
+      ? 'Account is blocked'
+      : userType === 'not_exist'
+        ? 'Account does not exist'
+        : name;
 
   const currentUserId = storage.get('uid', StoreType.STRING) as number;
   const insets = useSafeAreaInsets();
@@ -411,14 +429,14 @@ const ChatScreen = ({ route }: { route: any }) => {
       createdAt: new Date(message.sent_datetime + 'Z'),
       user: {
         _id: message.sender,
-        name: message.sender === id ? name : 'Me'
+        name: message.sender === id ? userName : 'Me'
       },
       replyMessage:
         message.reply_to_id !== -1
           ? {
               text: message.reply_to.text,
               id: message.reply_to.id,
-              name: message.reply_to.sender === id ? name : 'Me'
+              name: message.reply_to.sender === id ? userName : 'Me'
             }
           : null,
       reactions: JSON.parse(message.reactions || '{}'),
@@ -729,7 +747,7 @@ const ChatScreen = ({ route }: { route: any }) => {
               openReactionList(
                 time.currentMessage.reactions.map((reaction) => ({
                   ...reaction,
-                  name: reaction.uid === id ? name : 'Me'
+                  name: reaction.uid === id ? userName : 'Me'
                 })),
                 time.currentMessage._id
               )
@@ -820,7 +838,7 @@ const ChatScreen = ({ route }: { route: any }) => {
         newMessages[0].replyMessage = {
           text: replyMessage.text,
           id: replyMessage._id,
-          name: replyMessage.user._id === id ? name : 'Me'
+          name: replyMessage.user._id === id ? userName : 'Me'
         };
       }
       const message = { ...newMessages[0], pending: true };
@@ -1158,7 +1176,7 @@ const ChatScreen = ({ route }: { route: any }) => {
     >
       <View style={{ paddingHorizontal: '5%' }}>
         <Header
-          label={name}
+          label={userName}
           rightElement={
             <TouchableOpacity
               onPress={() =>
@@ -1166,10 +1184,11 @@ const ChatScreen = ({ route }: { route: any }) => {
                   ...([NAVIGATION_PAGES.PUBLIC_PROFILE_VIEW, { userId: id }] as never)
                 )
               }
+              disabled={userType !== 'normal'}
             >
-              {avatar ? (
+              {avatar && userType === 'normal' ? (
                 <Image source={{ uri: API_HOST + avatar }} style={styles.avatar} />
-              ) : (
+              ) : userType === 'normal' ? (
                 <AvatarWithInitials
                   text={
                     name
@@ -1181,6 +1200,8 @@ const ChatScreen = ({ route }: { route: any }) => {
                   size={30}
                   fontSize={12}
                 />
+              ) : (
+                <BanIcon fill={Colors.RED} width={30} height={30} />
               )}
             </TouchableOpacity>
           }

+ 21 - 6
src/screens/InAppScreens/MessagesScreen/Components/MoreModal.tsx

@@ -32,6 +32,7 @@ const MoreModal = () => {
       })
     | null
   >(null);
+  const [name, setName] = useState<string | null>(null);
   const { mutateAsync: muteUser } = usePostSetMuteMutation();
   const { mutateAsync: blockUser } = usePostSetBlockMutation();
   const { mutateAsync: deleteChat } = usePostDeleteChatMutation();
@@ -48,6 +49,13 @@ const MoreModal = () => {
       | null
   ) => {
     setChatData(payload);
+    setName(
+      payload?.userType === 'blocked'
+        ? 'Account is blocked'
+        : payload?.userType === 'not_exist'
+          ? 'Account does not exist'
+          : (payload?.name ?? null)
+    );
   };
 
   const handleMute = async () => {
@@ -74,7 +82,7 @@ const MoreModal = () => {
     setShouldOpenWarningModal({
       title: 'Block user',
       buttonTitle: 'Block',
-      message: `Are you sure you want to block ${chatData?.name}?\nThis user will be blocked and you will not be able to send or receive messages from him/her.`,
+      message: `Are you sure you want to block ${name}?\nThis user will be blocked and you will not be able to send or receive messages from him/her.`,
       action: async () => {
         await blockUser({
           token: chatData.token,
@@ -98,7 +106,7 @@ const MoreModal = () => {
 
     setShouldOpenWarningModal({
       title: 'Delete conversation',
-      message: `Are you sure you want to delete conversation with ${chatData?.name}?\nThis conversation will be deleted for both sides.`,
+      message: `Are you sure you want to delete conversation with ${name}?\nThis conversation will be deleted for both sides.`,
       action: async () => {
         await deleteChat({
           token: chatData.token,
@@ -142,10 +150,11 @@ const MoreModal = () => {
                 ...([NAVIGATION_PAGES.PUBLIC_PROFILE_VIEW, { userId: chatData.uid }] as never)
               );
             }}
+            disabled={chatData?.userType !== 'normal'}
           >
-            {chatData?.avatar ? (
+            {chatData?.avatar && chatData?.userType === 'normal' ? (
               <Image source={{ uri: API_HOST + chatData.avatar }} style={styles.avatar} />
-            ) : (
+            ) : chatData?.userType === 'normal' ? (
               <AvatarWithInitials
                 text={
                   chatData.name
@@ -157,8 +166,14 @@ const MoreModal = () => {
                 size={32}
                 fontSize={12}
               />
+            ) : (
+              <BanIcon fill={Colors.RED} width={32} height={32} />
             )}
-            <Text style={styles.name}>{chatData.name}</Text>
+            <Text
+              style={[styles.name, chatData?.userType !== 'normal' ? { color: Colors.RED } : {}]}
+            >
+              {name}
+            </Text>
           </TouchableOpacity>
 
           <View style={styles.optionsContainer}>
@@ -170,7 +185,7 @@ const MoreModal = () => {
 
           <View style={[styles.optionsContainer, { paddingVertical: 0, gap: 0 }]}>
             <TouchableOpacity style={[styles.option, styles.dangerOption]} onPress={handleBlock}>
-              <Text style={[styles.optionText, styles.dangerText]}>Block {chatData.name}</Text>
+              <Text style={[styles.optionText, styles.dangerText]}>Block {name}</Text>
               <BanIcon fill={Colors.RED} />
             </TouchableOpacity>
 

+ 1 - 0
src/screens/InAppScreens/MessagesScreen/Components/SwipeableRow.tsx

@@ -61,6 +61,7 @@ const SwipeableRow: React.FC<AppleStyleSwipeableRowProps> = ({
             avatar: chat.avatar,
             muted: chat.muted,
             token: token,
+            userType: chat.userType,
             refetch,
             refetchBlocked
           } as any

+ 24 - 11
src/screens/InAppScreens/MessagesScreen/index.tsx

@@ -9,12 +9,7 @@ import {
   AppState,
   AppStateStatus
 } from 'react-native';
-import {
-  AvatarWithInitials,
-  HorizontalTabView,
-  Input,
-  WarningModal
-} from 'src/components';
+import { AvatarWithInitials, HorizontalTabView, Input, WarningModal } from 'src/components';
 import { NAVIGATION_PAGES } from 'src/types';
 import { useFocusEffect, useNavigation } from '@react-navigation/native';
 
@@ -279,6 +274,13 @@ const MessagesScreen = () => {
   };
 
   const renderChatItem = ({ item }: { item: Chat }) => {
+    const name =
+      item.user_type === 'blocked'
+        ? 'Account is blocked'
+        : item.user_type === 'not_exist'
+          ? 'Account does not exist'
+          : item.name;
+
     return (
       <SwipeableRow
         chat={{
@@ -287,7 +289,8 @@ const MessagesScreen = () => {
           avatar: item.avatar,
           pin: item.pin,
           archive: item.archive,
-          muted: item.muted
+          muted: item.muted,
+          userType: item.user_type
         }}
         token={token}
         onRowOpen={handleRowOpen}
@@ -304,7 +307,8 @@ const MessagesScreen = () => {
                 {
                   id: item.uid,
                   name: item.name,
-                  avatar: item.avatar
+                  avatar: item.avatar,
+                  userType: item.user_type
                 }
               ] as never)
             )
@@ -312,9 +316,9 @@ const MessagesScreen = () => {
           underlayColor={Colors.FILL_LIGHT}
         >
           <View style={styles.chatItem}>
-            {item.avatar ? (
+            {item.avatar && item.user_type === 'normal' ? (
               <Image source={{ uri: API_HOST + item.avatar }} style={styles.avatar} />
-            ) : (
+            ) : item.user_type === 'normal' ? (
               <AvatarWithInitials
                 text={
                   item.name
@@ -325,11 +329,20 @@ const MessagesScreen = () => {
                 flag={API_HOST + item?.flag}
                 size={54}
               />
+            ) : (
+              <BanIcon fill={Colors.RED} width={54} height={54} />
             )}
 
             <View style={{ flex: 1, gap: 6 }}>
               <View style={[styles.rowContainer, { alignItems: 'center' }]}>
-                <Text style={styles.chatName}>{item.name}</Text>
+                <Text
+                  style={[
+                    styles.chatName,
+                    item.user_type !== 'normal' ? { color: Colors.RED } : {}
+                  ]}
+                >
+                  {name}
+                </Text>
 
                 <View style={{ flexDirection: 'row', alignItems: 'center', gap: 6 }}>
                   {item.pin === 1 ? <PinIcon height={12} fill={Colors.DARK_BLUE} /> : null}

+ 2 - 0
src/screens/InAppScreens/MessagesScreen/types.ts

@@ -17,6 +17,7 @@ export type Chat = {
   attachement_name: string;
   encrypted: 0 | 1;
   muted: 0 | 1;
+  user_type: 'normal' | 'not_exist' | 'blocked';
 };
 
 export type Blocked = {
@@ -33,6 +34,7 @@ export type ChatProps = {
   pin: 0 | 1;
   archive: 0 | 1;
   muted: 0 | 1;
+  userType: 'normal' | 'not_exist' | 'blocked';
 };
 
 export type MessageSimple = {

+ 14 - 0
src/screens/InAppScreens/ProfileScreen/UsersMap/index.tsx

@@ -227,6 +227,20 @@ const UsersMapScreen: FC<Props> = ({ navigation, route }) => {
     }
   }, [visitedDareIds]);
 
+  useEffect(() => {
+    if (
+      data.location_sharing &&
+      data.location_last_seen_location?.lng &&
+      data.location_last_seen_location?.lat &&
+      cameraRef.current
+    ) {
+      cameraRef.current.flyTo(
+        [data.location_last_seen_location.lng, data.location_last_seen_location.lat],
+        1000
+      );
+    }
+  }, [data, cameraRef.current]);
+
   const handleMapChange = async () => {
     if (!mapRef.current) return;
     if (hideTimer.current) clearTimeout(hideTimer.current);