Yay, message sending.

This commit is contained in:
David Baker 2015-06-16 11:08:27 +01:00
parent b2843b09bc
commit 88e9ab02f9
3 changed files with 19 additions and 9 deletions

View file

@ -3,12 +3,22 @@ var React = require('react');
var MatrixClientPeg = require("../MatrixClientPeg"); var MatrixClientPeg = require("../MatrixClientPeg");
module.exports = React.createClass({ module.exports = React.createClass({
onKeyDown: function (ev) {
if (ev.keyCode == 13) {
var contentText = this.refs.textarea.getDOMNode().value;
MatrixClientPeg.get().sendMessage(this.props.roomId, {
msgtype: 'm.text',
body: contentText
});
this.refs.textarea.getDOMNode().value = '';
ev.preventDefault();
}
},
render: function() { render: function() {
return ( return (
<div className="mx_MessageComposer"> <div className="mx_MessageComposer">
<form> <textarea ref="textarea" onKeyDown={this.onKeyDown} />
<textarea />
</form>
</div> </div>
); );
}, },

View file

@ -8,7 +8,7 @@ var MatrixClientPeg = require("../MatrixClientPeg");
module.exports = React.createClass({ module.exports = React.createClass({
getInitialState: function() { getInitialState: function() {
return { return {
room: MatrixClientPeg.get().getRoom(this.props.room_id) room: MatrixClientPeg.get().getRoom(this.props.roomId)
} }
}, },
@ -22,14 +22,14 @@ module.exports = React.createClass({
componentWillReceiveProps: function(props) { componentWillReceiveProps: function(props) {
this.setState({ this.setState({
room: MatrixClientPeg.get().getRoom(props.room_id) room: MatrixClientPeg.get().getRoom(props.roomId)
}); });
}, },
onRoomTimeline: function(ev, room, toStartOfTimeline) { onRoomTimeline: function(ev, room, toStartOfTimeline) {
if (room.roomId != this.props.room_id) return; if (room.roomId != this.props.roomId) return;
this.setState({ this.setState({
room: MatrixClientPeg.get().getRoom(this.props.room_id) room: MatrixClientPeg.get().getRoom(this.props.roomId)
}); });
}, },
@ -48,7 +48,7 @@ module.exports = React.createClass({
<ul> <ul>
{this.getMessageTiles()} {this.getMessageTiles()}
</ul> </ul>
<MessageComposer room={this.state.room} /> <MessageComposer roomId={this.props.roomId} />
</div> </div>
); );
}, },

View file

@ -73,7 +73,7 @@ module.exports = React.createClass({
<MatrixToolbar /> <MatrixToolbar />
<RoomList selectedRoom={this.state.currentRoom} /> <RoomList selectedRoom={this.state.currentRoom} />
</div> </div>
<RoomView room_id={this.state.currentRoom} /> <RoomView roomId={this.state.currentRoom} />
</div> </div>
); );
} else if (this.state.logged_in) { } else if (this.state.logged_in) {