2015-06-09 19:40:42 +03:00
|
|
|
var React = require('react');
|
2015-06-12 19:34:17 +03:00
|
|
|
|
|
|
|
var MatrixClientPeg = require("../MatrixClientPeg");
|
2015-06-17 18:43:29 +03: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 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);
|
2015-06-18 13:23:35 +03:00
|
|
|
this.atBottom = true;
|
2015-06-12 20:17:54 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
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-18 13:23:35 +03:00
|
|
|
// MatrixRoom still showing the messages from the old room?
|
|
|
|
// Set the key to the room_id. Sadly you can no longer get at
|
|
|
|
// the key from inside the component, or we'd check this in code.
|
|
|
|
/*componentWillReceiveProps: function(props) {
|
|
|
|
},*/
|
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-18 13:23:35 +03:00
|
|
|
var messageUl = this.refs.messageList.getDOMNode();
|
|
|
|
this.atBottom = messageUl.scrollHeight - messageUl.scrollTop <= messageUl.clientHeight;
|
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 16:31:35 +03:00
|
|
|
<li key={mxEv.getId()}><MessageTile mxEvent={mxEv} /></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} />
|
2015-06-18 13:23:35 +03:00
|
|
|
<ul ref="messageList">
|
2015-06-12 19:34:17 +03:00
|
|
|
{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>
|
|
|
|
);
|
|
|
|
},
|
2015-06-18 13:23:35 +03:00
|
|
|
|
|
|
|
componentDidMount: function() {
|
|
|
|
var messageUl = this.refs.messageList.getDOMNode();
|
|
|
|
messageUl.scrollTop = messageUl.scrollHeight;
|
|
|
|
},
|
|
|
|
|
|
|
|
componentDidUpdate: function() {
|
|
|
|
if (this.atBottom) {
|
|
|
|
var messageUl = this.refs.messageList.getDOMNode();
|
|
|
|
messageUl.scrollTop = messageUl.scrollHeight;
|
|
|
|
}
|
|
|
|
}
|
2015-06-09 19:40:42 +03:00
|
|
|
});
|
|
|
|
|