element-web/src/molecules/MessageComposer.js

38 lines
1,018 B
JavaScript
Raw Normal View History

var React = require('react');
var MatrixClientPeg = require("../MatrixClientPeg");
module.exports = React.createClass({
2015-06-16 13:08:27 +03:00
onKeyDown: function (ev) {
if (ev.keyCode == 13) {
var contentText = this.refs.textarea.getDOMNode().value;
2015-06-16 17:29:13 +03: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 13:08:27 +03:00
this.refs.textarea.getDOMNode().value = '';
ev.preventDefault();
}
},
render: function() {
return (
<div className="mx_MessageComposer">
2015-06-16 13:08:27 +03:00
<textarea ref="textarea" onKeyDown={this.onKeyDown} />
</div>
);
},
});