|
|
@@ -73,7 +73,7 @@ import { dismissChatNotifications, isMessageEdited } from '../utils';
|
|
|
import { useMessagesStore } from 'src/stores/unreadMessagesStore';
|
|
|
import FileViewer from 'react-native-file-viewer';
|
|
|
import * as FileSystem from 'expo-file-system/legacy';
|
|
|
-import * as MediaLibrary from 'expo-media-library';
|
|
|
+import Share from 'react-native-share';
|
|
|
|
|
|
import BanIcon from 'assets/icons/messages/ban.svg';
|
|
|
import AttachmentsModal from '../Components/AttachmentsModal';
|
|
|
@@ -556,6 +556,7 @@ const ChatScreen = ({ route }: { route: any }) => {
|
|
|
const fileUrl = currentMessage.video
|
|
|
? currentMessage.video
|
|
|
: API_HOST + currentMessage.attachment?.attachment_full_url;
|
|
|
+
|
|
|
const fileType = currentMessage.attachment?.filetype || 'application/octet-stream';
|
|
|
let fileExt = fileType.split('/').pop() || (currentMessage.video ? 'mp4' : 'jpg');
|
|
|
|
|
|
@@ -567,22 +568,16 @@ const ChatScreen = ({ route }: { route: any }) => {
|
|
|
const fileUri = `${FileSystem.cacheDirectory}${fileName}.${fileExt}`;
|
|
|
|
|
|
try {
|
|
|
- const { status } = await MediaLibrary.requestPermissionsAsync();
|
|
|
- if (status !== 'granted') {
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
const downloadOptions = {
|
|
|
headers: { Nmtoken: token, 'App-Version': APP_VERSION, Platform: Platform.OS }
|
|
|
};
|
|
|
const { uri } = await FileSystem.downloadAsync(fileUrl, fileUri, downloadOptions);
|
|
|
|
|
|
- await MediaLibrary.createAssetAsync(uri);
|
|
|
-
|
|
|
- Alert.alert(
|
|
|
- 'Success',
|
|
|
- `${fileType.startsWith('video') ? 'Video' : 'Image'} saved to gallery.`
|
|
|
- );
|
|
|
+ await Share.open({
|
|
|
+ url: uri,
|
|
|
+ type: fileType,
|
|
|
+ failOnCancel: false
|
|
|
+ });
|
|
|
} catch (error) {
|
|
|
Alert.alert('Error', 'Failed to download the file.');
|
|
|
}
|
|
|
@@ -1295,8 +1290,11 @@ const ChatScreen = ({ route }: { route: any }) => {
|
|
|
setIsModalVisible(false);
|
|
|
break;
|
|
|
case 'download':
|
|
|
- downloadFileToDevice(selectedMessage.currentMessage);
|
|
|
setIsModalVisible(false);
|
|
|
+
|
|
|
+ setTimeout(() => {
|
|
|
+ downloadFileToDevice(selectedMessage.currentMessage);
|
|
|
+ }, 300);
|
|
|
break;
|
|
|
case 'edit':
|
|
|
handleEditMessage(selectedMessage.currentMessage);
|