switch RoomView:uploadFile to async to clean up then/catch handling

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
pull/21833/head
Michael Telatynski 2018-05-02 13:14:47 +01:00
parent f2102e283c
commit 4c3f811050
No known key found for this signature in database
GPG Key ID: 3F879DA5AD802A5E
1 changed files with 12 additions and 7 deletions

View File

@ -908,18 +908,15 @@ module.exports = React.createClass({
this.setState({ draggingFile: false }); this.setState({ draggingFile: false });
}, },
uploadFile: function(file) { uploadFile: async function(file) {
if (MatrixClientPeg.get().isGuest()) { if (MatrixClientPeg.get().isGuest()) {
dis.dispatch({action: 'view_set_mxid'}); dis.dispatch({action: 'view_set_mxid'});
return; return;
} }
ContentMessages.sendContentToRoom(file, this.state.room.roomId, MatrixClientPeg.get()).then(() => { try {
// Send message_sent callback, for things like _checkIfAlone because after all a file is still a message. await ContentMessages.sendContentToRoom(file, this.state.room.roomId, MatrixClientPeg.get());
dis.dispatch({ } catch (error) {
action: 'message_sent',
});
}).catch((error) => {
if (error.name === "UnknownDeviceError") { if (error.name === "UnknownDeviceError") {
// Let the status bar handle this // Let the status bar handle this
return; return;
@ -931,6 +928,14 @@ module.exports = React.createClass({
description: ((error && error.message) description: ((error && error.message)
? error.message : _t("Server may be unavailable, overloaded, or the file too big")), ? error.message : _t("Server may be unavailable, overloaded, or the file too big")),
}); });
// bail early to avoid calling the dispatch below
return;
}
// Send message_sent callback, for things like _checkIfAlone because after all a file is still a message.
dis.dispatch({
action: 'message_sent',
}); });
}, },