update camera-roll and save the file from local url
This commit is contained in:
parent
3e75699b0b
commit
3ada875384
|
@ -22,7 +22,7 @@ import EventEmitter from '../lib/methods/helpers/events';
|
||||||
import { getUserSelector } from '../selectors/login';
|
import { getUserSelector } from '../selectors/login';
|
||||||
import { TNavigation } from '../stacks/stackType';
|
import { TNavigation } from '../stacks/stackType';
|
||||||
import { useTheme } from '../theme';
|
import { useTheme } from '../theme';
|
||||||
import { getFilename } from '../lib/methods/handleMediaDownload';
|
import { LOCAL_DOCUMENT_DIRECTORY, getFilename } from '../lib/methods/handleMediaDownload';
|
||||||
|
|
||||||
const RenderContent = ({
|
const RenderContent = ({
|
||||||
setLoading,
|
setLoading,
|
||||||
|
@ -144,13 +144,13 @@ const AttachmentView = (): React.ReactElement => {
|
||||||
|
|
||||||
const handleSave = async () => {
|
const handleSave = async () => {
|
||||||
const { title_link, image_url, image_type, video_url, video_type } = attachment;
|
const { title_link, image_url, image_type, video_url, video_type } = attachment;
|
||||||
const url = title_link || image_url || video_url;
|
// When the attachment is a video, the video_url refers to local file and the title_link to the link
|
||||||
|
const url = video_url || title_link || image_url;
|
||||||
|
|
||||||
if (!url) {
|
if (!url) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const mediaAttachment = formatAttachmentUrl(url, user.id, user.token, baseUrl);
|
|
||||||
if (isAndroid) {
|
if (isAndroid) {
|
||||||
const rationale = {
|
const rationale = {
|
||||||
title: I18n.t('Write_External_Permission'),
|
title: I18n.t('Write_External_Permission'),
|
||||||
|
@ -165,17 +165,22 @@ const AttachmentView = (): React.ReactElement => {
|
||||||
|
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
try {
|
try {
|
||||||
let filename = '';
|
if (LOCAL_DOCUMENT_DIRECTORY && url.startsWith(LOCAL_DOCUMENT_DIRECTORY)) {
|
||||||
if (image_url) {
|
await CameraRoll.save(url, { album: 'Rocket.Chat' });
|
||||||
filename = getFilename({ title: attachment.title, type: 'image', mimeType: image_type, url });
|
|
||||||
} else {
|
} else {
|
||||||
filename = getFilename({ title: attachment.title, type: 'video', mimeType: video_type, url });
|
const mediaAttachment = formatAttachmentUrl(url, user.id, user.token, baseUrl);
|
||||||
|
let filename = '';
|
||||||
|
if (image_url) {
|
||||||
|
filename = getFilename({ title: attachment.title, type: 'image', mimeType: image_type, url });
|
||||||
|
} else {
|
||||||
|
filename = getFilename({ title: attachment.title, type: 'video', mimeType: video_type, url });
|
||||||
|
}
|
||||||
|
const documentDir = `${RNFetchBlob.fs.dirs.DocumentDir}/`;
|
||||||
|
const path = `${documentDir + filename}`;
|
||||||
|
const file = await RNFetchBlob.config({ path }).fetch('GET', mediaAttachment);
|
||||||
|
await CameraRoll.save(path, { album: 'Rocket.Chat' });
|
||||||
|
file.flush();
|
||||||
}
|
}
|
||||||
const documentDir = `${RNFetchBlob.fs.dirs.DocumentDir}/`;
|
|
||||||
const path = `${documentDir + filename}`;
|
|
||||||
const file = await RNFetchBlob.config({ path }).fetch('GET', mediaAttachment);
|
|
||||||
await CameraRoll.save(path, { album: 'Rocket.Chat' });
|
|
||||||
file.flush();
|
|
||||||
EventEmitter.emit(LISTENER, { message: I18n.t('saved_to_gallery') });
|
EventEmitter.emit(LISTENER, { message: I18n.t('saved_to_gallery') });
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
EventEmitter.emit(LISTENER, { message: I18n.t(image_url ? 'error-save-image' : 'error-save-video') });
|
EventEmitter.emit(LISTENER, { message: I18n.t(image_url ? 'error-save-image' : 'error-save-video') });
|
||||||
|
|
|
@ -385,7 +385,7 @@ PODS:
|
||||||
- React-Core
|
- React-Core
|
||||||
- react-native-blur (4.1.0):
|
- react-native-blur (4.1.0):
|
||||||
- React-Core
|
- React-Core
|
||||||
- react-native-cameraroll (5.6.0):
|
- react-native-cameraroll (5.7.2):
|
||||||
- React-Core
|
- React-Core
|
||||||
- react-native-cookies (6.2.1):
|
- react-native-cookies (6.2.1):
|
||||||
- React-Core
|
- React-Core
|
||||||
|
@ -944,7 +944,7 @@ SPEC CHECKSUMS:
|
||||||
React-logger: 3f8ebad1be1bf3299d1ab6d7f971802d7395c7ef
|
React-logger: 3f8ebad1be1bf3299d1ab6d7f971802d7395c7ef
|
||||||
react-native-background-timer: 17ea5e06803401a379ebf1f20505b793ac44d0fe
|
react-native-background-timer: 17ea5e06803401a379ebf1f20505b793ac44d0fe
|
||||||
react-native-blur: ba2f37268542f8a26d809f48c5162705a3261fc6
|
react-native-blur: ba2f37268542f8a26d809f48c5162705a3261fc6
|
||||||
react-native-cameraroll: 755bcc628148a90a7c9cf3f817a252be3a601bc5
|
react-native-cameraroll: 134805127580aed23403b8c2cb1548920dd77b3a
|
||||||
react-native-cookies: f54fcded06bb0cda05c11d86788020b43528a26c
|
react-native-cookies: f54fcded06bb0cda05c11d86788020b43528a26c
|
||||||
react-native-document-picker: f5ec1a712ca2a975c233117f044817bb8393cad4
|
react-native-document-picker: f5ec1a712ca2a975c233117f044817bb8393cad4
|
||||||
react-native-mmkv-storage: cfb6854594cfdc5f7383a9e464bb025417d1721c
|
react-native-mmkv-storage: cfb6854594cfdc5f7383a9e464bb025417d1721c
|
||||||
|
@ -1003,4 +1003,4 @@ SPEC CHECKSUMS:
|
||||||
|
|
||||||
PODFILE CHECKSUM: da36ddb728f8698fcf3e8b17d853ccedc4f8a24c
|
PODFILE CHECKSUM: da36ddb728f8698fcf3e8b17d853ccedc4f8a24c
|
||||||
|
|
||||||
COCOAPODS: 1.12.1
|
COCOAPODS: 1.11.3
|
||||||
|
|
|
@ -43,7 +43,7 @@
|
||||||
"@hookform/resolvers": "^2.9.10",
|
"@hookform/resolvers": "^2.9.10",
|
||||||
"@nozbe/watermelondb": "^0.25.5",
|
"@nozbe/watermelondb": "^0.25.5",
|
||||||
"@react-native-async-storage/async-storage": "^1.17.11",
|
"@react-native-async-storage/async-storage": "^1.17.11",
|
||||||
"@react-native-camera-roll/camera-roll": "^5.6.0",
|
"@react-native-camera-roll/camera-roll": "^5.7.2",
|
||||||
"@react-native-clipboard/clipboard": "^1.8.5",
|
"@react-native-clipboard/clipboard": "^1.8.5",
|
||||||
"@react-native-community/art": "^1.2.0",
|
"@react-native-community/art": "^1.2.0",
|
||||||
"@react-native-community/blur": "^4.1.0",
|
"@react-native-community/blur": "^4.1.0",
|
||||||
|
|
|
@ -4628,10 +4628,10 @@
|
||||||
dependencies:
|
dependencies:
|
||||||
merge-options "^3.0.4"
|
merge-options "^3.0.4"
|
||||||
|
|
||||||
"@react-native-camera-roll/camera-roll@^5.6.0":
|
"@react-native-camera-roll/camera-roll@^5.7.2":
|
||||||
version "5.6.0"
|
version "5.7.2"
|
||||||
resolved "https://registry.yarnpkg.com/@react-native-camera-roll/camera-roll/-/camera-roll-5.6.0.tgz#385082d57d694f3fd5ae386f8b8ce24b0969c5f9"
|
resolved "https://registry.yarnpkg.com/@react-native-camera-roll/camera-roll/-/camera-roll-5.7.2.tgz#db11525ae26c8a61630c424aebd323a7c784a921"
|
||||||
integrity sha512-a/GYwnBTxj1yKWB9m/qy8GzjowSocML8NbLT81wdMh0JzZYXCLze51BR2cb8JNDgRPzA9xe7KpD3j9qQOSOjag==
|
integrity sha512-s8VAUG1Kvi+tEJkLHObmOJdXAL/uclnXJ/IdnJtx2fCKiWA3Ho0ln9gDQqCYHHHHu+sXk7wovsH/I2/AYy0brg==
|
||||||
|
|
||||||
"@react-native-clipboard/clipboard@^1.8.5":
|
"@react-native-clipboard/clipboard@^1.8.5":
|
||||||
version "1.8.5"
|
version "1.8.5"
|
||||||
|
|
Loading…
Reference in New Issue