2015-06-19 07:53:48 -04:00
|
|
|
var MatrixClientPeg = require("../../MatrixClientPeg");
|
2015-06-15 13:35:28 -04:00
|
|
|
|
2015-06-19 07:53:48 -04:00
|
|
|
var dis = require("../../dispatcher");
|
2015-06-15 13:35:28 -04:00
|
|
|
|
2015-06-19 07:53:48 -04:00
|
|
|
module.exports = {
|
2015-06-18 10:03:57 -04:00
|
|
|
componentDidMount: function() {
|
|
|
|
this.dispatcherRef = dis.register(this.onAction);
|
|
|
|
},
|
|
|
|
|
|
|
|
componentWillUnmount: function() {
|
|
|
|
dis.unregister(this.dispatcherRef);
|
|
|
|
},
|
|
|
|
|
|
|
|
onAction: function(payload) {
|
|
|
|
switch (payload.action) {
|
|
|
|
case 'focus_composer':
|
|
|
|
this.refs.textarea.getDOMNode().focus();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2015-06-16 06:08:27 -04:00
|
|
|
onKeyDown: function (ev) {
|
|
|
|
if (ev.keyCode == 13) {
|
|
|
|
var contentText = this.refs.textarea.getDOMNode().value;
|
2015-06-16 10:29:13 -04:00
|
|
|
|
|
|
|
var content = null;
|
|
|
|
if (/^\/me /i.test(contentText)) {
|
|
|
|
content = {
|
|
|
|
msgtype: 'm.emote',
|
|
|
|
body: contentText.substring(4)
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
content = {
|
|
|
|
msgtype: 'm.text',
|
|
|
|
body: contentText
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
MatrixClientPeg.get().sendMessage(this.props.roomId, content);
|
2015-06-16 06:08:27 -04:00
|
|
|
this.refs.textarea.getDOMNode().value = '';
|
|
|
|
ev.preventDefault();
|
|
|
|
}
|
|
|
|
},
|
2015-06-19 07:53:48 -04:00
|
|
|
};
|
2015-06-15 13:35:28 -04:00
|
|
|
|