element-web/src/organisms/RoomView.js

55 lines
1.4 KiB
JavaScript
Raw Normal View History

var React = require('react');
var MessageTile = require('../molecules/MessageTile');
var RoomHeader = require('../molecules/RoomHeader');
var MatrixClientPeg = require("../MatrixClientPeg");
module.exports = React.createClass({
getInitialState: function() {
return {
room: MatrixClientPeg.get().getRoom(this.props.room_id)
}
},
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({
room: MatrixClientPeg.get().getRoom(props.room_id)
});
},
2015-06-12 20:17:54 +03:00
onRoomTimeline: function(ev, room, toStartOfTimeline) {
if (room.roomId != this.props.room_id) return;
this.setState({
room: MatrixClientPeg.get().getRoom(this.props.room_id)
});
},
getMessageTiles: function() {
return this.state.room.timeline.map(function(mxEv) {
return (
<MessageTile mxEvent={mxEv} key={mxEv.getId()} />
);
});
},
render: function() {
return (
<div className="mx_RoomView">
<RoomHeader room={this.state.room} />
<ul>
{this.getMessageTiles()}
</ul>
</div>
);
},
});