2015-06-09 16:40:42 +00:00
|
|
|
var React = require('react');
|
2015-06-16 17:18:55 +00:00
|
|
|
var ComponentBroker = require('../ComponentBroker');
|
2015-06-09 16:40:42 +00:00
|
|
|
|
2015-06-17 15:43:29 +00:00
|
|
|
var RoomList = ComponentBroker.get('organisms/RoomList');
|
|
|
|
var RoomView = ComponentBroker.get('organisms/RoomView');
|
|
|
|
var MatrixToolbar = ComponentBroker.get('molecules/MatrixToolbar');
|
|
|
|
var Login = ComponentBroker.get('templates/Login');
|
2015-06-16 17:18:55 +00:00
|
|
|
|
|
|
|
// should be atomised
|
2015-06-12 13:59:33 +00:00
|
|
|
var Loader = require("react-loader");
|
2015-06-09 16:40:42 +00:00
|
|
|
|
|
|
|
|
2015-06-11 17:25:29 +00:00
|
|
|
var mxCliPeg = require("../MatrixClientPeg");
|
|
|
|
|
2015-06-12 16:34:17 +00:00
|
|
|
var dis = require("../dispatcher");
|
2015-06-09 16:40:42 +00:00
|
|
|
|
|
|
|
module.exports = React.createClass({
|
2015-06-11 17:25:29 +00:00
|
|
|
getInitialState: function() {
|
|
|
|
return {
|
2015-06-12 13:59:33 +00:00
|
|
|
logged_in: !!(mxCliPeg.get() && mxCliPeg.get().credentials),
|
|
|
|
ready: false
|
2015-06-11 17:25:29 +00:00
|
|
|
};
|
|
|
|
},
|
|
|
|
|
2015-06-12 13:59:33 +00:00
|
|
|
componentDidMount: function() {
|
2015-06-12 16:34:17 +00:00
|
|
|
this.dispatcherRef = dis.register(this.onAction);
|
2015-06-12 13:59:33 +00:00
|
|
|
if (this.state.logged_in) {
|
|
|
|
this.startMatrixClient();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2015-06-12 16:34:17 +00:00
|
|
|
componentWillUnmount: function() {
|
|
|
|
dis.unregister(this.dispatcherRef);
|
|
|
|
},
|
|
|
|
|
|
|
|
onAction: function(payload) {
|
|
|
|
switch (payload.action) {
|
|
|
|
case 'logout':
|
|
|
|
this.setState({
|
|
|
|
logged_in: false,
|
|
|
|
ready: false
|
|
|
|
});
|
2015-06-16 13:37:15 +00:00
|
|
|
mxCliPeg.get().removeAllListeners();
|
|
|
|
mxCliPeg.replace(null);
|
2015-06-12 16:34:17 +00:00
|
|
|
break;
|
2015-06-12 17:01:38 +00:00
|
|
|
case 'view_room':
|
|
|
|
this.setState({
|
|
|
|
currentRoom: payload.room_id
|
|
|
|
});
|
|
|
|
break;
|
2015-06-12 16:34:17 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2015-06-12 12:45:22 +00:00
|
|
|
onLoggedIn: function() {
|
|
|
|
this.setState({logged_in: true});
|
2015-06-12 13:59:33 +00:00
|
|
|
this.startMatrixClient();
|
|
|
|
},
|
|
|
|
|
|
|
|
startMatrixClient: function() {
|
|
|
|
var cli = mxCliPeg.get();
|
|
|
|
var that = this;
|
|
|
|
cli.on('syncComplete', function() {
|
2015-06-12 16:34:17 +00:00
|
|
|
var firstRoom = null;
|
|
|
|
if (cli.getRooms() && cli.getRooms().length) {
|
|
|
|
firstRoom = cli.getRooms()[0].roomId;
|
|
|
|
}
|
|
|
|
that.setState({ready: true, currentRoom: firstRoom});
|
2015-06-12 13:59:33 +00:00
|
|
|
});
|
|
|
|
cli.startClient();
|
2015-06-11 17:25:29 +00:00
|
|
|
},
|
|
|
|
|
2015-06-09 16:40:42 +00:00
|
|
|
render: function() {
|
2015-06-12 13:59:33 +00:00
|
|
|
if (this.state.logged_in && this.state.ready) {
|
2015-06-09 16:40:42 +00:00
|
|
|
return (
|
2015-06-15 14:50:24 +00:00
|
|
|
<div className="mx_MatrixChat">
|
2015-06-12 16:34:17 +00:00
|
|
|
<div className="mx_MatrixChat_leftPanel">
|
|
|
|
<MatrixToolbar />
|
|
|
|
<RoomList selectedRoom={this.state.currentRoom} />
|
|
|
|
</div>
|
2015-06-18 10:23:35 +00:00
|
|
|
<RoomView roomId={this.state.currentRoom} key={this.state.currentRoom} />
|
2015-06-09 16:40:42 +00:00
|
|
|
</div>
|
|
|
|
);
|
2015-06-12 13:59:33 +00:00
|
|
|
} else if (this.state.logged_in) {
|
|
|
|
return (
|
|
|
|
<Loader />
|
|
|
|
);
|
2015-06-09 16:40:42 +00:00
|
|
|
} else {
|
|
|
|
return (
|
2015-06-12 12:45:22 +00:00
|
|
|
<Login onLoggedIn={this.onLoggedIn} />
|
2015-06-09 16:40:42 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|