Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,6 @@ workflows:
- ios-build:
requires:
- lint-testunit
- e2e-test
- ios-testflight:
requires:
- ios-build
Expand All @@ -285,4 +284,3 @@ workflows:
- android-build:
requires:
- lint-testunit
- e2e-test
11 changes: 10 additions & 1 deletion app/containers/MessageBox/Recording.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export default class extends React.PureComponent {
super();

this.recordingCanceled = false;
this.recording = true;
this.state = {
currentTime: '00:00'
};
Expand Down Expand Up @@ -65,6 +66,12 @@ export default class extends React.PureComponent {
AudioRecorder.startRecording();
}

componentWillUnmount() {
if (this.recording) {
this.cancelAudioMessage();
}
}

_finishRecording(didSucceed, filePath) {
if (!didSucceed) {
return this.props.onFinish && this.props.onFinish(didSucceed);
Expand All @@ -81,6 +88,7 @@ export default class extends React.PureComponent {

finishAudioMessage = async() => {
try {
this.recording = false;
const filePath = await AudioRecorder.stopRecording();
if (Platform.OS === 'android') {
this._finishRecording(true, filePath);
Expand All @@ -92,6 +100,7 @@ export default class extends React.PureComponent {
}

cancelAudioMessage = async() => {
this.recording = false;
this.recordingCanceled = true;
await AudioRecorder.stopRecording();
return this._finishRecording(false);
Expand All @@ -113,7 +122,7 @@ export default class extends React.PureComponent {
accessibilityTraits='button'
onPress={this.cancelAudioMessage}
/>
<Text key='currentTime' style={[styles.textBoxInput, { width: 50, height: 60 }]}>{this.state.currentTime}</Text>
<Text key='currentTime' style={styles.textBoxInput}>{this.state.currentTime}</Text>
<Icon
style={[styles.actionButtons, { color: 'green' }]}
name='check'
Expand Down
15 changes: 11 additions & 4 deletions app/containers/MessageBox/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import PropTypes from 'prop-types';
import { View, TextInput, FlatList, Text, TouchableOpacity } from 'react-native';
import { View, TextInput, FlatList, Text, TouchableOpacity, Alert } from 'react-native';
import Icon from 'react-native-vector-icons/MaterialIcons';
import ImagePicker from 'react-native-image-picker';
import { connect } from 'react-redux';
Expand Down Expand Up @@ -209,12 +209,19 @@ export default class MessageBox extends React.PureComponent {
}

finishAudioMessage = async(fileInfo) => {
if (fileInfo) {
RocketChat.sendFileMessage(this.props.rid, fileInfo);
}
this.setState({
recording: false
});
if (fileInfo) {
try {
await RocketChat.sendFileMessage(this.props.rid, fileInfo);
} catch (e) {
if (e && e.error === 'error-file-too-large') {
return Alert.alert('File is too large!');
}
log('finishAudioMessage', e);
}
}
}

closeEmoji() {
Expand Down
21 changes: 16 additions & 5 deletions app/lib/rocketchat.js
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@ const RocketChat = {
return call('sendFileMessage', rid, null, data, msg);
},
async sendFileMessage(rid, fileInfo, data) {
const placeholder = RocketChat.getMessage(rid, 'Sending a file');
let placeholder;
try {
if (!data) {
data = await RNFetchBlob.wrap(fileInfo.path);
Expand All @@ -624,6 +624,15 @@ const RocketChat = {
fileInfo.name = fileStat.filename;
}

const { FileUpload_MaxFileSize } = reduxStore.getState().settings;

// -1 maxFileSize means there is no limit
if (FileUpload_MaxFileSize > -1 && fileInfo.size > FileUpload_MaxFileSize) {
return Promise.reject({ error: 'error-file-too-large' }); // eslint-disable-line
}

placeholder = RocketChat.getMessage(rid, 'Sending a file');

const result = await RocketChat._ufsCreate({ ...fileInfo, rid });
await RNFetchBlob.fetch('POST', result.url, {
'Content-Type': 'application/octet-stream'
Expand All @@ -643,10 +652,12 @@ const RocketChat = {
} finally {
// TODO: fix that
try {
database.write(() => {
const msg = database.objects('messages').filtered('_id = $0', placeholder._id);
database.delete(msg);
});
if (placeholder) {
database.write(() => {
const msg = database.objects('messages').filtered('_id = $0', placeholder._id);
database.delete(msg);
});
}
} catch (e) {
console.error(e);
}
Expand Down