diff --git a/app/containers/MessageBox/Recording.js b/app/containers/MessageBox/Recording.js
index a89dab11..713564a1 100644
--- a/app/containers/MessageBox/Recording.js
+++ b/app/containers/MessageBox/Recording.js
@@ -36,6 +36,7 @@ export default class extends React.PureComponent {
super();
this.recordingCanceled = false;
+ this.recording = true;
this.state = {
currentTime: '00:00'
};
@@ -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);
@@ -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);
@@ -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);
@@ -113,7 +122,7 @@ export default class extends React.PureComponent {
accessibilityTraits='button'
onPress={this.cancelAudioMessage}
/>
- {this.state.currentTime}
+ {this.state.currentTime}
{
- 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() {
diff --git a/app/lib/rocketchat.js b/app/lib/rocketchat.js
index e27dc77a..2cd1705c 100644
--- a/app/lib/rocketchat.js
+++ b/app/lib/rocketchat.js
@@ -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);
@@ -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'
@@ -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);
}