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