Viktoriia hai 8 meses
pai
achega
03030945df

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

@@ -29,6 +29,7 @@ export interface PostGetChatsListReturn extends ResponseType {
     archive_order: number;
     attachement_name: string;
     encrypted: 0 | 1;
+    muted: 0 | 1;
   }[];
 }
 

+ 40 - 9
src/screens/InAppScreens/MessagesScreen/Components/MoreModal.tsx

@@ -9,34 +9,65 @@ import { useSafeAreaInsets } from 'react-native-safe-area-context';
 import { ChatProps } from '../types';
 import { useNavigation } from '@react-navigation/native';
 import { NAVIGATION_PAGES } from 'src/types';
-import { usePostSetBlockMutation, usePostSetMuteMutation } from '@api/chat';
+import {
+  usePostDeleteChatMutation,
+  usePostSetBlockMutation,
+  usePostSetMuteMutation
+} from '@api/chat';
 
 const MoreModal = () => {
   const insets = useSafeAreaInsets();
   const navigation = useNavigation();
 
-  const [chatData, setChatData] = useState<ChatProps | null>(null);
+  const [chatData, setChatData] = useState<
+    (ChatProps & { token: string; refetch: () => void }) | null
+  >(null);
   const { mutateAsync: muteUser } = usePostSetMuteMutation();
   const { mutateAsync: blockUser } = usePostSetBlockMutation();
+  const { mutateAsync: deleteChat } = usePostDeleteChatMutation();
 
-  const handleSheetOpen = (payload: ChatProps | null) => {
+  const handleSheetOpen = (
+    payload: (ChatProps & { token: string; refetch: () => void }) | null
+  ) => {
     setChatData(payload);
   };
 
   const handleMute = async () => {
-    // await muteUser({
-    //   value: chatData.muted === 1 ? 0 : 1,
-    //   conversation_with_user: chatData.id
-    // });
+    if (!chatData) return;
+
+    await muteUser(
+      {
+        token: chatData.token,
+        value: chatData.muted === 1 ? 0 : 1,
+        conversation_with_user: chatData.id
+      },
+      {
+        onSuccess: () => {
+          setChatData({ ...chatData, muted: chatData.muted === 1 ? 0 : 1 });
+        }
+      }
+    );
+    chatData.refetch();
   };
 
   const handleBlock = async () => {
+    // if (!chatData) return;
+    
     // await blockUser({
     //   value: chatData.blocked === 1 ? 0 : 1,
     //   conversation_with_user: chatData.id
     // });
   };
 
+  const handleDelete = async () => {
+    if (!chatData) return;
+
+    await deleteChat({
+      token: chatData.token,
+      conversation_with_user: chatData.id
+    });
+  };
+
   return (
     <ActionSheet
       id="more-modal"
@@ -64,8 +95,8 @@ const MoreModal = () => {
           </TouchableOpacity>
 
           <View style={styles.optionsContainer}>
-            <TouchableOpacity style={styles.option}>
-              <Text style={styles.optionText}>Mute</Text>
+            <TouchableOpacity style={styles.option} onPress={handleMute}>
+              <Text style={styles.optionText}>{chatData.muted === 1 ? 'Unmute' : 'Mute'}</Text>
               <Ionicons name="notifications-off-outline" size={18} color={Colors.DARK_BLUE} />
             </TouchableOpacity>
           </View>

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

@@ -53,7 +53,10 @@ const SwipeableRow: React.FC<AppleStyleSwipeableRowProps> = ({
           payload: {
             id: chat.id,
             name: chat.name,
-            avatar: chat.avatar
+            avatar: chat.avatar,
+            mute: chat.muted,
+            token: token,
+            refetch
           } as any
         });
       } else {

+ 5 - 2
src/screens/InAppScreens/MessagesScreen/index.tsx

@@ -93,7 +93,9 @@ const MessagesScreen = () => {
           .sort((a: Chat, b: Chat) => b.pin - a.pin || b.pin_order - a.pin_order)
       );
     } else if (index === 2) {
-      setFilteredChats(chats.sort((a: Chat, b: Chat) => b.pin - a.pin || b.pin_order - a.pin_order));
+      setFilteredChats(
+        chats.sort((a: Chat, b: Chat) => b.pin - a.pin || b.pin_order - a.pin_order)
+      );
     } else {
       setFilteredChats(
         chats.sort((a: Chat, b: Chat) => b.pin - a.pin || b.pin_order - a.pin_order)
@@ -155,7 +157,8 @@ const MessagesScreen = () => {
           name: item.name,
           avatar: item.avatar,
           pin: item.pin,
-          archive: item.archive
+          archive: item.archive,
+          muted: item.muted
         }}
         token={token}
         onRowOpen={handleRowOpen}

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

@@ -16,6 +16,7 @@ export type Chat = {
   archive_order: number;
   attachement_name: string;
   encrypted: 0 | 1;
+  muted: 0 | 1;
 };
 
 export type ChatProps = {
@@ -24,6 +25,7 @@ export type ChatProps = {
   avatar: string | null;
   pin: 0 | 1;
   archive: 0 | 1;
+  muted: 0 | 1;
 };
 
 export type MessageSimple = {