element-web/src/organisms/RoomView.js

62 lines
1.7 KiB
JavaScript
Raw Normal View History

var React = require('react');
var MatrixClientPeg = require("../MatrixClientPeg");
var ComponentBroker = require('../ComponentBroker');
var MessageTile = ComponentBroker.get('molecules/MessageTile');
var RoomHeader = ComponentBroker.get('molecules/RoomHeader');
var MessageComposer = ComponentBroker.get('molecules/MessageComposer');
module.exports = React.createClass({
getInitialState: function() {
return {
2015-06-16 13:08:27 +03:00
room: MatrixClientPeg.get().getRoom(this.props.roomId)
}
},
2015-06-12 20:17:54 +03:00
componentWillMount: function() {
MatrixClientPeg.get().on("Room.timeline", this.onRoomTimeline);
},
componentWillUnmount: function() {
2015-06-16 16:37:15 +03:00
if (MatrixClientPeg.get()) {
MatrixClientPeg.get().removeListener("Room.timeline", this.onRoomTimeline);
}
2015-06-12 20:17:54 +03:00
},
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
});
},
getMessageTiles: function() {
return this.state.room.timeline.map(function(mxEv) {
return (
2015-06-16 16:31:35 +03:00
<li key={mxEv.getId()}><MessageTile mxEvent={mxEv} /></li>
);
});
},
render: function() {
return (
<div className="mx_RoomView">
<RoomHeader room={this.state.room} />
<ul>
{this.getMessageTiles()}
</ul>
2015-06-16 13:08:27 +03:00
<MessageComposer roomId={this.props.roomId} />
</div>
);
},
});