Factor out common onSendMessageFailed

This commit is contained in:
Richard van der Hoff 2017-01-25 19:06:15 +00:00
parent 5da6ca8fc1
commit 70190be65c
2 changed files with 17 additions and 24 deletions

View file

@ -40,6 +40,7 @@ import * as HtmlUtils from '../../../HtmlUtils';
import Autocomplete from './Autocomplete';
import {Completion} from "../../../autocomplete/Autocompleter";
import Markdown from '../../../Markdown';
import {onSendMessageFailed} from './MessageComposerInputOld';
const TYPING_USER_TIMEOUT = 10000, TYPING_SERVER_TIMEOUT = 30000;
@ -553,21 +554,11 @@ export default class MessageComposerInput extends React.Component {
sendMessagePromise = sendTextFn.call(this.client, this.props.room.roomId, contentText);
}
sendMessagePromise.then((res) => {
sendMessagePromise.done((res) => {
dis.dispatch({
action: 'message_sent',
});
}, (err) => {
if (err.name === "UnknownDeviceError") {
var UnknownDeviceDialog = sdk.getComponent("dialogs.UnknownDeviceDialog");
Modal.createDialog(UnknownDeviceDialog, {
devices: err.devices
});
}
dis.dispatch({
action: 'message_send_failed',
});
});
}, onSendMessageFailed);
this.setState({
editorState: this.createEditorState(),

View file

@ -29,10 +29,22 @@ var TYPING_USER_TIMEOUT = 10000;
var TYPING_SERVER_TIMEOUT = 30000;
var MARKDOWN_ENABLED = true;
export function onSendMessageFailed(err) {
if (err.name === "UnknownDeviceError") {
const UnknownDeviceDialog = sdk.getComponent("dialogs.UnknownDeviceDialog");
Modal.createDialog(UnknownDeviceDialog, {
devices: err.devices,
});
}
dis.dispatch({
action: 'message_send_failed',
});
}
/*
* The textInput part of the MessageComposer
*/
module.exports = React.createClass({
export default React.createClass({
displayName: 'MessageComposerInput',
statics: {
@ -341,18 +353,8 @@ module.exports = React.createClass({
dis.dispatch({
action: 'message_sent'
});
}, function(err) {
if (err.name === "UnknownDeviceError") {
var UnknownDeviceDialog = sdk.getComponent("dialogs.UnknownDeviceDialog");
Modal.createDialog(UnknownDeviceDialog, {
devices: err.devices
});
}
}, onSendMessageFailed);
dis.dispatch({
action: 'message_send_failed'
});
});
this.refs.textarea.value = '';
this.resizeInput();
ev.preventDefault();