2015-06-09 19:40:42 +03:00
|
|
|
var React = require('react');
|
2015-06-12 19:34:17 +03:00
|
|
|
var MessageTile = require('../molecules/MessageTile');
|
|
|
|
var RoomHeader = require('../molecules/RoomHeader');
|
2015-06-16 12:41:05 +03:00
|
|
|
var MessageComposer = require('../molecules/MessageComposer');
|
2015-06-12 19:34:17 +03:00
|
|
|
|
|
|
|
var MatrixClientPeg = require("../MatrixClientPeg");
|
2015-06-09 19:40:42 +03:00
|
|
|
|
|
|
|
module.exports = React.createClass({
|
|
|
|
getInitialState: function() {
|
|
|
|
return {
|
2015-06-16 13:08:27 +03:00
|
|
|
room: MatrixClientPeg.get().getRoom(this.props.roomId)
|
2015-06-09 19:40:42 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2015-06-12 20:17:54 +03:00
|
|
|
componentWillMount: function() {
|
|
|
|
MatrixClientPeg.get().on("Room.timeline", this.onRoomTimeline);
|
|
|
|
},
|
|
|
|
|
|
|
|
componentWillUnmount: function() {
|
|
|
|
MatrixClientPeg.get().removeListener("Room.timeline", this.onRoomTimeline);
|
|
|
|
},
|
|
|
|
|
2015-06-12 20:01:38 +03:00
|
|
|
componentWillReceiveProps: function(props) {
|
|
|
|
this.setState({
|
2015-06-16 13:08:27 +03:00
|
|
|
room: MatrixClientPeg.get().getRoom(props.roomId)
|
2015-06-12 20:01:38 +03:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2015-06-12 20:17:54 +03:00
|
|
|
onRoomTimeline: function(ev, room, toStartOfTimeline) {
|
2015-06-16 13:08:27 +03:00
|
|
|
if (room.roomId != this.props.roomId) return;
|
2015-06-12 20:17:54 +03:00
|
|
|
this.setState({
|
2015-06-16 13:08:27 +03:00
|
|
|
room: MatrixClientPeg.get().getRoom(this.props.roomId)
|
2015-06-12 20:17:54 +03:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2015-06-12 19:34:17 +03:00
|
|
|
getMessageTiles: function() {
|
|
|
|
return this.state.room.timeline.map(function(mxEv) {
|
2015-06-09 19:40:42 +03:00
|
|
|
return (
|
2015-06-16 12:41:05 +03:00
|
|
|
<li><MessageTile mxEvent={mxEv} key={mxEv.getId()} /></li>
|
2015-06-09 19:40:42 +03:00
|
|
|
);
|
2015-06-12 19:34:17 +03:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
render: function() {
|
2015-06-09 19:40:42 +03:00
|
|
|
return (
|
2015-06-12 19:34:17 +03:00
|
|
|
<div className="mx_RoomView">
|
|
|
|
<RoomHeader room={this.state.room} />
|
|
|
|
<ul>
|
|
|
|
{this.getMessageTiles()}
|
2015-06-09 19:40:42 +03:00
|
|
|
</ul>
|
2015-06-16 13:08:27 +03:00
|
|
|
<MessageComposer roomId={this.props.roomId} />
|
2015-06-09 19:40:42 +03:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|