2015-06-23 18:41:25 +03:00
|
|
|
/*
|
|
|
|
Copyright 2015 OpenMarket Ltd
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
2015-06-19 14:53:48 +03:00
|
|
|
var MatrixClientPeg = require("../../MatrixClientPeg");
|
2015-06-12 19:34:17 +03:00
|
|
|
|
2015-06-19 14:53:48 +03:00
|
|
|
module.exports = {
|
2015-06-09 19:40:42 +03:00
|
|
|
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-23 13:36:19 +03:00
|
|
|
// no point handling anything while we're waiting for the join to finish:
|
|
|
|
// we'll only be showing a spinner.
|
|
|
|
if (this.state.joining) return;
|
2015-06-16 13:08:27 +03:00
|
|
|
if (room.roomId != this.props.roomId) return;
|
2015-06-22 16:48:58 +03:00
|
|
|
|
|
|
|
if (this.refs.messageList) {
|
|
|
|
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-18 13:23:35 +03:00
|
|
|
componentDidMount: function() {
|
2015-06-22 16:48:58 +03:00
|
|
|
if (this.refs.messageList) {
|
|
|
|
var messageUl = this.refs.messageList.getDOMNode();
|
|
|
|
messageUl.scrollTop = messageUl.scrollHeight;
|
|
|
|
}
|
2015-06-18 13:23:35 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
componentDidUpdate: function() {
|
2015-06-22 16:48:58 +03:00
|
|
|
if (this.refs.messageList && this.atBottom) {
|
2015-06-18 13:23:35 +03:00
|
|
|
var messageUl = this.refs.messageList.getDOMNode();
|
|
|
|
messageUl.scrollTop = messageUl.scrollHeight;
|
|
|
|
}
|
2015-06-22 16:48:58 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
onJoinButtonClicked: function(ev) {
|
2015-06-23 13:36:19 +03:00
|
|
|
var that = this;
|
2015-06-22 16:48:58 +03:00
|
|
|
MatrixClientPeg.get().joinRoom(this.props.roomId).then(function() {
|
2015-06-23 13:36:19 +03:00
|
|
|
that.setState({
|
|
|
|
joining: false,
|
|
|
|
room: MatrixClientPeg.get().getRoom(that.props.roomId)
|
2015-06-22 16:48:58 +03:00
|
|
|
});
|
|
|
|
}, function(error) {
|
2015-06-23 13:36:19 +03:00
|
|
|
that.setState({
|
|
|
|
joining: false,
|
2015-06-22 16:48:58 +03:00
|
|
|
joinError: error
|
|
|
|
});
|
|
|
|
});
|
|
|
|
this.setState({
|
|
|
|
joining: true
|
|
|
|
});
|
2015-06-18 13:23:35 +03:00
|
|
|
}
|
2015-06-19 14:53:48 +03:00
|
|
|
};
|
2015-06-09 19:40:42 +03:00
|
|
|
|