diff --git a/app/containers/MessageBox/Recording.js b/app/containers/MessageBox/Recording.js index 96f45c9b7..d5fed549a 100644 --- a/app/containers/MessageBox/Recording.js +++ b/app/containers/MessageBox/Recording.js @@ -5,6 +5,7 @@ import { } from 'react-native'; import { AudioRecorder, AudioUtils } from 'react-native-audio'; import { BorderlessButton } from 'react-native-gesture-handler'; +import FileSystem from 'expo-file-system'; import styles from './styles'; import I18n from '../../i18n'; @@ -68,7 +69,7 @@ export default class extends React.PureComponent { // AudioRecorder.onFinished = (data) => { if (!this.recordingCanceled && isIOS) { - this.finishRecording(data.status === 'OK', data.audioFileURL); + this.finishRecording(data.status === 'OK', data.audioFileURL, data.audioFileSize); } }; AudioRecorder.startRecording(); @@ -80,7 +81,7 @@ export default class extends React.PureComponent { } } - finishRecording = (didSucceed, filePath) => { + finishRecording = (didSucceed, filePath, size) => { const { onFinish } = this.props; if (!didSucceed) { return onFinish && onFinish(didSucceed); @@ -90,9 +91,11 @@ export default class extends React.PureComponent { } const fileInfo = { name: this.name, + mime: 'audio/aac', type: 'audio/aac', store: 'Uploads', - path: filePath + path: filePath, + size }; return onFinish && onFinish(fileInfo); } @@ -102,7 +105,8 @@ export default class extends React.PureComponent { this.recording = false; const filePath = await AudioRecorder.stopRecording(); if (isAndroid) { - this.finishRecording(true, filePath); + const data = await FileSystem.getInfoAsync(decodeURIComponent(filePath)); + this.finishRecording(true, filePath, data.size); } } catch (err) { this.finishRecording(false); diff --git a/app/containers/MessageBox/UploadModal.js b/app/containers/MessageBox/UploadModal.js index 596934ebf..3773391b7 100644 --- a/app/containers/MessageBox/UploadModal.js +++ b/app/containers/MessageBox/UploadModal.js @@ -2,7 +2,6 @@ import React, { Component } from 'react'; import { View, Text, StyleSheet, Image, ScrollView, TouchableHighlight } from 'react-native'; -import { connect } from 'react-redux'; import PropTypes from 'prop-types'; import Modal from 'react-native-modal'; import { responsive } from 'react-native-responsive-ui'; @@ -13,9 +12,8 @@ import Button from '../Button'; import I18n from '../../i18n'; import sharedStyles from '../../views/Styles'; import { isIOS } from '../../utils/deviceInfo'; -import { canUploadFile } from '../../utils/media'; import { - COLOR_PRIMARY, COLOR_BACKGROUND_CONTAINER, COLOR_WHITE, COLOR_DANGER + COLOR_PRIMARY, COLOR_BACKGROUND_CONTAINER, COLOR_WHITE } from '../../constants/colors'; import { CustomIcon } from '../../lib/Icons'; @@ -75,23 +73,6 @@ const styles = StyleSheet.create({ flex: 1, textAlign: 'center' }, - errorIcon: { - color: COLOR_DANGER - }, - fileMime: { - ...sharedStyles.textColorTitle, - ...sharedStyles.textBold, - textAlign: 'center', - fontSize: 20, - marginBottom: 20 - }, - errorContainer: { - margin: 20, - flex: 1, - textAlign: 'center', - justifyContent: 'center', - alignItems: 'center' - }, video: { flex: 1, borderRadius: 4, @@ -110,9 +91,7 @@ class UploadModal extends Component { file: PropTypes.object, close: PropTypes.func, submit: PropTypes.func, - window: PropTypes.object, - FileUpload_MediaTypeWhiteList: PropTypes.string, - FileUpload_MaxFileSize: PropTypes.number + window: PropTypes.object } state = { @@ -154,79 +133,12 @@ class UploadModal extends Component { return false; } - canUploadFile = () => { - const { FileUpload_MediaTypeWhiteList, FileUpload_MaxFileSize, file } = this.props; - if (!(file && file.path)) { - return true; - } - if (file.size > FileUpload_MaxFileSize) { - return false; - } - // if white list is empty, all media types are enabled - if (!FileUpload_MediaTypeWhiteList) { - return true; - } - const allowedMime = FileUpload_MediaTypeWhiteList.split(','); - if (allowedMime.includes(file.mime)) { - return true; - } - const wildCardGlob = '/*'; - const wildCards = allowedMime.filter(item => item.indexOf(wildCardGlob) > 0); - if (wildCards.includes(file.mime.replace(/(\/.*)$/, wildCardGlob))) { - return true; - } - return false; - } - submit = () => { const { file, submit } = this.props; const { name, description } = this.state; submit({ ...file, name, description }); } - renderError = () => { - const { file, FileUpload_MaxFileSize, close } = this.props; - const { window: { width } } = this.props; - const errorMessage = (FileUpload_MaxFileSize < file.size) - ? 'error-file-too-large' - : 'error-invalid-file-type'; - return ( - - - {I18n.t(errorMessage)} - - - - - { file.mime } - - { - (isIOS) - ? ( -