From 33780433b6a3f2e1c1ef05eec4798a3321a67cb9 Mon Sep 17 00:00:00 2001 From: prateek93a Date: Sat, 25 Apr 2020 13:27:03 +0530 Subject: [PATCH 1/2] added-feature-save-video --- app/i18n/locales/en.js | 1 + app/views/AttachmentView.js | 17 ++++++++++------- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/app/i18n/locales/en.js b/app/i18n/locales/en.js index 6b485ea7235..e89b9df7bb1 100644 --- a/app/i18n/locales/en.js +++ b/app/i18n/locales/en.js @@ -18,6 +18,7 @@ export default { 'error-email-domain-blacklisted': 'The email domain is blacklisted', 'error-email-send-failed': 'Error trying to send email: {{message}}', 'error-save-image': 'Error while saving image', + 'error-save-video': 'Error while saving video', 'error-field-unavailable': '{{field}} is already in use :(', 'error-file-too-large': 'File is too large', 'error-importer-not-defined': 'The importer was not defined correctly, it is missing the Import class.', diff --git a/app/views/AttachmentView.js b/app/views/AttachmentView.js index 51646896e27..e79bf9b6ffe 100644 --- a/app/views/AttachmentView.js +++ b/app/views/AttachmentView.js @@ -33,11 +33,11 @@ class AttachmentView extends React.Component { const attachment = navigation.getParam('attachment'); const from = navigation.getParam('from'); const handleSave = navigation.getParam('handleSave', () => {}); - const { title, video_url } = attachment; + const { title } = attachment; const options = { title, ...themedHeader(theme), - headerRight: !video_url ? : null + headerRight: }; if (from !== 'MessagesView') { options.gesturesEnabled = false; @@ -84,8 +84,11 @@ class AttachmentView extends React.Component { handleSave = async() => { const { attachment } = this.state; const { user, baseUrl } = this.props; - const { image_url, image_type } = attachment; - const img = formatAttachmentUrl(image_url, user.id, user.token, baseUrl); + const { + image_url, image_type, video_url, video_type + } = attachment; + const url = image_url || video_url; + const mediaAttachment = formatAttachmentUrl(url, user.id, user.token, baseUrl); if (isAndroid) { const rationale = { @@ -100,13 +103,13 @@ class AttachmentView extends React.Component { this.setState({ loading: true }); try { - const extension = `.${ mime.extension(image_type) || 'jpg' }`; + const extension = image_url ? `.${ mime.extension(image_type) || 'jpg' }` : `.${ mime.extension(video_type) || 'mp4' }`; const file = `${ FileSystem.documentDirectory + SHA256(image_url) + extension }`; - const { uri } = await FileSystem.downloadAsync(img, file); + const { uri } = await FileSystem.downloadAsync(mediaAttachment, file); await CameraRoll.save(uri, { album: 'Rocket.Chat' }); EventEmitter.emit(LISTENER, { message: I18n.t('saved_to_gallery') }); } catch (e) { - EventEmitter.emit(LISTENER, { message: I18n.t('error-save-image') }); + EventEmitter.emit(LISTENER, { message: I18n.t(image_url ? 'error-save-image' : 'error-save-video') }); } this.setState({ loading: false }); }; From c9d2ad8e48837b7b212b66c4c4e564f93003f882 Mon Sep 17 00:00:00 2001 From: Djorkaeff Alexandre Date: Mon, 27 Apr 2020 12:06:34 -0300 Subject: [PATCH 2/2] fix sha256 --- app/views/AttachmentView.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/AttachmentView.js b/app/views/AttachmentView.js index e79bf9b6ffe..c94a8e84b9f 100644 --- a/app/views/AttachmentView.js +++ b/app/views/AttachmentView.js @@ -104,7 +104,7 @@ class AttachmentView extends React.Component { this.setState({ loading: true }); try { const extension = image_url ? `.${ mime.extension(image_type) || 'jpg' }` : `.${ mime.extension(video_type) || 'mp4' }`; - const file = `${ FileSystem.documentDirectory + SHA256(image_url) + extension }`; + const file = `${ FileSystem.documentDirectory + SHA256(url) + extension }`; const { uri } = await FileSystem.downloadAsync(mediaAttachment, file); await CameraRoll.save(uri, { album: 'Rocket.Chat' }); EventEmitter.emit(LISTENER, { message: I18n.t('saved_to_gallery') });