[FEATURE] Save video (#2063)

* added-feature-save-video

* fix sha256

Co-authored-by: Djorkaeff Alexandre <djorkaeff.unb@gmail.com>
Co-authored-by: Diego Mello <diegolmello@gmail.com>
This commit is contained in:
Prateek Jain 2020-04-30 23:38:48 +05:30 committed by GitHub
parent 3f79ab7953
commit 25b5c95775
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 8 deletions

View File

@ -18,6 +18,7 @@ export default {
'error-email-domain-blacklisted': 'The email domain is blacklisted', 'error-email-domain-blacklisted': 'The email domain is blacklisted',
'error-email-send-failed': 'Error trying to send email: {{message}}', 'error-email-send-failed': 'Error trying to send email: {{message}}',
'error-save-image': 'Error while saving image', 'error-save-image': 'Error while saving image',
'error-save-video': 'Error while saving video',
'error-field-unavailable': '{{field}} is already in use :(', 'error-field-unavailable': '{{field}} is already in use :(',
'error-file-too-large': 'File is too large', 'error-file-too-large': 'File is too large',
'error-importer-not-defined': 'The importer was not defined correctly, it is missing the Import class.', 'error-importer-not-defined': 'The importer was not defined correctly, it is missing the Import class.',

View File

@ -33,11 +33,11 @@ class AttachmentView extends React.Component {
const attachment = navigation.getParam('attachment'); const attachment = navigation.getParam('attachment');
const from = navigation.getParam('from'); const from = navigation.getParam('from');
const handleSave = navigation.getParam('handleSave', () => {}); const handleSave = navigation.getParam('handleSave', () => {});
const { title, video_url } = attachment; const { title } = attachment;
const options = { const options = {
title, title,
...themedHeader(theme), ...themedHeader(theme),
headerRight: !video_url ? <SaveButton testID='save-image' onPress={handleSave} /> : null headerRight: <SaveButton testID='save-image' onPress={handleSave} />
}; };
if (from !== 'MessagesView') { if (from !== 'MessagesView') {
options.gesturesEnabled = false; options.gesturesEnabled = false;
@ -84,8 +84,11 @@ class AttachmentView extends React.Component {
handleSave = async() => { handleSave = async() => {
const { attachment } = this.state; const { attachment } = this.state;
const { user, baseUrl } = this.props; const { user, baseUrl } = this.props;
const { image_url, image_type } = attachment; const {
const img = formatAttachmentUrl(image_url, user.id, user.token, baseUrl); 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) { if (isAndroid) {
const rationale = { const rationale = {
@ -100,13 +103,13 @@ class AttachmentView extends React.Component {
this.setState({ loading: true }); this.setState({ loading: true });
try { 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 file = `${ FileSystem.documentDirectory + SHA256(url) + extension }`;
const { uri } = await FileSystem.downloadAsync(img, file); const { uri } = await FileSystem.downloadAsync(mediaAttachment, file);
await CameraRoll.save(uri, { album: 'Rocket.Chat' }); await CameraRoll.save(uri, { album: 'Rocket.Chat' });
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('error-save-image') }); EventEmitter.emit(LISTENER, { message: I18n.t(image_url ? 'error-save-image' : 'error-save-video') });
} }
this.setState({ loading: false }); this.setState({ loading: false });
}; };