Kaynağa Gözat

types for attachments

Viktoriia 5 ay önce
ebeveyn
işleme
17d6204848

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

@@ -34,6 +34,17 @@ export interface PostGetChatsListReturn extends ResponseType {
   }[];
 }
 
+interface Attachement {
+  id: number;
+  filename: string;
+  filetype: string;
+  attachment_small_url?: string;
+  attachment_full_url?: string;
+  lat?: number;
+  lng?: number;
+  attachment_link?: string;
+}
+
 interface Message {
   id: number;
   sender: number;
@@ -46,7 +57,7 @@ interface Message {
   reply_to_id: number;
   reactions: string;
   edits: string;
-  attachement: any;
+  attachement: -1 | Attachement;
   encrypted: 0 | 1;
 }
 

+ 13 - 4
src/screens/InAppScreens/MessagesScreen/ChatScreen/index.tsx

@@ -50,7 +50,7 @@ import {
   usePostReactToMessageMutation,
   usePostSendMessageMutation
 } from '@api/chat';
-import { CustomMessage, Message, Reaction } from '../types';
+import { CustomMessage, Message, Reaction, Attachement } from '../types';
 import { API_HOST, WEBSOCKET_URL } from 'src/constants';
 import ReactionBar from '../Components/ReactionBar';
 import OptionsMenu from '../Components/OptionsMenu';
@@ -448,7 +448,7 @@ const ChatScreen = ({ route }: { route: any }) => {
       <View style={{ width: 200, height: 200, backgroundColor: Colors.DARK_BLUE }}>
         <Video
           ref={videoRef}
-          source={{ uri: currentMessage.video }}
+          source={{ uri: currentMessage.video, headers: { Nmtoken: token } }}
           style={{ flex: 1 }}
           useNativeControls
           resizeMode={ResizeMode.CONTAIN}
@@ -815,7 +815,15 @@ const ChatScreen = ({ route }: { route: any }) => {
       pending: message.status === 1,
       sent: message.status === 2,
       received: message.status === 3,
-      deleted: message.status === 4
+      deleted: message.status === 4,
+      video:
+        message.attachement !== -1 && message.attachement?.filetype.startsWith('video')
+          ? API_HOST + message.attachement?.attachment_link
+          : null,
+      image:
+        message.attachement !== -1 && message.attachement?.filetype.startsWith('image')
+          ? API_HOST + message.attachement?.attachment_small_url
+          : null
     };
   };
 
@@ -829,6 +837,7 @@ const ChatScreen = ({ route }: { route: any }) => {
     useCallback(() => {
       if (chatData?.messages) {
         const mappedMessages = chatData.messages.map(mapApiMessageToGiftedMessage);
+        console.log('mappedMessages', mappedMessages[0]);
 
         if (unreadMessageIndex === null && !isFetching) {
           const firstUnreadIndex = mappedMessages.findLastIndex(
@@ -1389,7 +1398,7 @@ const ChatScreen = ({ route }: { route: any }) => {
     const { currentMessage } = props;
     return (
       <TouchableOpacity
-        onPress={() => setSelectedMedia(currentMessage.image)}
+        onPress={() => setSelectedMedia(API_HOST + currentMessage.attachment.attachment_full_url)}
         onLongPress={() => handleLongPress(currentMessage, props)}
         style={styles.imageContainer}
       >

+ 3 - 1
src/screens/InAppScreens/MessagesScreen/Components/AttachmentsModal.tsx

@@ -17,11 +17,13 @@ const AttachmentsModal = () => {
   const insets = useSafeAreaInsets();
   const [shouldOpenWarningModal, setShouldOpenWarningModal] = useState<WarningProps | null>(null);
   const { mutateAsync: reportUser } = usePostReportConversationMutation();
+  const [data, setData] = useState<any | null>(null);
 
   const chatDataRef = useRef<any>(null);
 
   const handleSheetOpen = (payload: any) => {
     chatDataRef.current = payload;
+    setData(payload);
   };
 
   const handleReport = async () => {
@@ -206,7 +208,7 @@ const AttachmentsModal = () => {
     {
       name: 'route-b',
       component: RouteB,
-      params: { onSendLocation: chatDataRef.current?.onSendLocation, insetsBottom: insets.bottom }
+      params: { onSendLocation: data?.onSendLocation, insetsBottom: insets.bottom }
     }
   ];
 

+ 16 - 5
src/screens/InAppScreens/MessagesScreen/types.ts

@@ -37,6 +37,17 @@ export type ChatProps = {
   userType: 'normal' | 'not_exist' | 'blocked';
 };
 
+export interface Attachement {
+  id: number;
+  filename: string;
+  filetype: string;
+  attachment_small_url?: string;
+  attachment_full_url?: string;
+  lat?: number;
+  lng?: number;
+  attachment_link?: string;
+}
+
 export type MessageSimple = {
   id: number;
   sender: number;
@@ -46,10 +57,10 @@ export type MessageSimple = {
   sent_datetime: Date;
   received_datetime: Date | null;
   read_datetime: Date | null;
-  reply_to_id: number; // -1 if not a reply
-  reactions: string; // JSON object '{}'
-  edits: string; // JSON object '{}'
-  attachement: any; // -1 if no attachment
+  reply_to_id: number;
+  reactions: string;
+  edits: string;
+  attachement: -1 | Attachement;
   encrypted: 0 | 1;
 };
 
@@ -65,7 +76,7 @@ export interface CustomMessage extends IMessage {
     name: string;
   } | null;
   deleted: boolean;
-  attachment: string | null;
+  attachment: Attachement | null;
   reactions: Reaction[] | {};
 }