Jelajahi Sumber

android chat images fix

Viktoriia 1 bulan lalu
induk
melakukan
51d2c7145d

+ 2 - 1
app.config.ts

@@ -140,7 +140,8 @@ export default ({ config }: ConfigContext): ExpoConfig => ({
       'INTERNET',
       'CAMERA',
       'MODIFY_AUDIO_SETTINGS',
-      'FOREGROUND_SERVICE'
+      'FOREGROUND_SERVICE',
+      'READ_MEDIA_VIDEO'
     ],
     versionCode: 87 // 2.0.33, last version sent to Google is 86 (2.0.32)
   },

+ 11 - 5
src/screens/InAppScreens/MessagesScreen/ChatScreen/index.tsx

@@ -543,8 +543,13 @@ const ChatScreen = ({ route }: { route: any }) => {
     const fileUrl = currentMessage.video
       ? currentMessage.video
       : API_HOST + currentMessage.attachment?.attachment_full_url;
-    const fileType = currentMessage.attachment?.filetype || '';
-    const fileExt = fileType.split('/').pop() || '';
+    const fileType = currentMessage.attachment?.filetype || 'application/octet-stream';
+    let fileExt = fileType.split('/').pop() || (currentMessage.video ? 'mp4' : 'jpg');
+
+    if (Platform.OS === 'android' && fileType === 'video/quicktime') {
+      fileExt = 'mp4';
+    }
+
     const fileName = currentMessage.attachment?.filename?.split('.')[0] || 'file';
     const fileUri = `${FileSystem.cacheDirectory}${fileName}.${fileExt}`;
 
@@ -554,9 +559,9 @@ const ChatScreen = ({ route }: { route: any }) => {
         return;
       }
 
-      const downloadOptions = currentMessage.video
-        ? { headers: { Nmtoken: token, 'App-Version': APP_VERSION, Platform: Platform.OS } }
-        : undefined;
+      const downloadOptions = {
+        headers: { Nmtoken: token, 'App-Version': APP_VERSION, Platform: Platform.OS }
+      };
       const { uri } = await FileSystem.downloadAsync(fileUrl, fileUri, downloadOptions);
 
       await MediaLibrary.createAssetAsync(uri);
@@ -569,6 +574,7 @@ const ChatScreen = ({ route }: { route: any }) => {
       Alert.alert('Error', 'Failed to download the file.');
     }
   }
+
   const renderMessageFile = (props: BubbleProps<CustomMessage>) => {
     const { currentMessage } = props;
     const leftMessage = currentMessage?.user?._id !== +currentUserId;

+ 11 - 5
src/screens/InAppScreens/MessagesScreen/GroupChatScreen/index.tsx

@@ -558,8 +558,13 @@ const GroupChatScreen = ({ route }: { route: any }) => {
     const fileUrl = currentMessage.video
       ? currentMessage.video
       : API_HOST + currentMessage.attachment?.attachment_full_url;
-    const fileType = currentMessage.attachment?.filetype || '';
-    const fileExt = fileType.split('/').pop() || '';
+    const fileType = currentMessage.attachment?.filetype || 'application/octet-stream';
+    let fileExt = fileType.split('/').pop() || (currentMessage.video ? 'mp4' : 'jpg');
+
+    if (Platform.OS === 'android' && fileType === 'video/quicktime') {
+      fileExt = 'mp4';
+    }
+
     const fileName = currentMessage.attachment?.filename?.split('.')[0] || 'file';
     const fileUri = `${FileSystem.cacheDirectory}${fileName}.${fileExt}`;
 
@@ -569,9 +574,10 @@ const GroupChatScreen = ({ route }: { route: any }) => {
         return;
       }
 
-      const downloadOptions = currentMessage.video
-        ? { headers: { Nmtoken: token, 'App-Version': APP_VERSION, Platform: Platform.OS } }
-        : undefined;
+      const downloadOptions = {
+        headers: { Nmtoken: token, 'App-Version': APP_VERSION, Platform: Platform.OS }
+      };
+
       const { uri } = await FileSystem.downloadAsync(fileUrl, fileUri, downloadOptions);
 
       await MediaLibrary.createAssetAsync(uri);