2015-06-23 18:41:25 +03:00
|
|
|
/*
|
|
|
|
Copyright 2015 OpenMarket Ltd
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
2015-06-19 14:53:48 +03:00
|
|
|
var MatrixClientPeg = require("../../MatrixClientPeg");
|
2015-06-15 20:35:28 +03:00
|
|
|
|
2015-06-19 14:53:48 +03:00
|
|
|
var dis = require("../../dispatcher");
|
2015-06-15 20:35:28 +03:00
|
|
|
|
2015-06-19 14:53:48 +03:00
|
|
|
module.exports = {
|
2015-06-18 17:03:57 +03: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 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();
|
|
|
|
}
|
|
|
|
},
|
2015-06-19 14:53:48 +03:00
|
|
|
};
|
2015-06-15 20:35:28 +03:00
|
|
|
|