2015-06-23 18:41:25 +03:00
|
|
|
/*
|
2016-01-07 07:06:39 +03:00
|
|
|
Copyright 2015, 2016 OpenMarket Ltd
|
2015-06-23 18:41:25 +03:00
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
2015-11-30 21:11:04 +03:00
|
|
|
var React = require('react');
|
|
|
|
var Matrix = require("matrix-js-sdk");
|
|
|
|
var url = require('url');
|
2015-12-21 15:55:13 +03:00
|
|
|
var Favico = require('favico.js');
|
2015-06-23 18:41:25 +03:00
|
|
|
|
2015-07-02 15:18:03 +03:00
|
|
|
var MatrixClientPeg = require("../../MatrixClientPeg");
|
2015-11-30 18:04:24 +03:00
|
|
|
var Notifier = require("../../Notifier");
|
2015-11-30 21:11:04 +03:00
|
|
|
var ContextualMenu = require("../../ContextualMenu");
|
2015-07-08 20:18:03 +03:00
|
|
|
var RoomListSorter = require("../../RoomListSorter");
|
2015-10-26 16:54:54 +03:00
|
|
|
var UserActivity = require("../../UserActivity");
|
2015-09-18 20:39:16 +03:00
|
|
|
var Presence = require("../../Presence");
|
2015-06-19 14:53:48 +03:00
|
|
|
var dis = require("../../dispatcher");
|
2015-06-09 19:40:42 +03:00
|
|
|
|
2015-11-30 21:11:04 +03:00
|
|
|
var Login = require("./login/Login");
|
|
|
|
var Registration = require("./login/Registration");
|
|
|
|
var PostRegistration = require("./login/PostRegistration");
|
|
|
|
|
2015-12-13 16:49:28 +03:00
|
|
|
var Modal = require("../../Modal");
|
2016-01-08 06:22:38 +03:00
|
|
|
var Tinter = require("../../Tinter");
|
2015-09-15 15:34:36 +03:00
|
|
|
var sdk = require('../../index');
|
2015-09-18 20:39:16 +03:00
|
|
|
var MatrixTools = require('../../MatrixTools');
|
2015-10-27 12:58:55 +03:00
|
|
|
var linkifyMatrix = require("../../linkify-matrix");
|
2015-07-03 13:12:54 +03:00
|
|
|
|
2015-11-30 21:11:04 +03:00
|
|
|
module.exports = React.createClass({
|
|
|
|
displayName: 'MatrixChat',
|
|
|
|
|
|
|
|
propTypes: {
|
|
|
|
config: React.PropTypes.object.isRequired,
|
|
|
|
ConferenceHandler: React.PropTypes.any,
|
|
|
|
onNewScreen: React.PropTypes.func,
|
2015-12-17 17:56:55 +03:00
|
|
|
registrationUrl: React.PropTypes.string,
|
2016-01-05 14:39:36 +03:00
|
|
|
enableGuest: React.PropTypes.bool,
|
2015-12-17 17:56:55 +03:00
|
|
|
startingQueryParams: React.PropTypes.object
|
2015-11-30 21:11:04 +03:00
|
|
|
},
|
2015-10-12 12:13:01 +03:00
|
|
|
|
2015-09-18 20:39:16 +03:00
|
|
|
PageTypes: {
|
|
|
|
RoomView: "room_view",
|
|
|
|
UserSettings: "user_settings",
|
|
|
|
CreateRoom: "create_room",
|
2015-11-20 17:32:00 +03:00
|
|
|
RoomDirectory: "room_directory",
|
2015-09-18 20:39:16 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
AuxPanel: {
|
|
|
|
RoomSettings: "room_settings",
|
|
|
|
},
|
|
|
|
|
2015-06-11 20:25:29 +03:00
|
|
|
getInitialState: function() {
|
2015-09-18 20:39:16 +03:00
|
|
|
var s = {
|
2015-07-03 13:12:54 +03:00
|
|
|
logged_in: !!(MatrixClientPeg.get() && MatrixClientPeg.get().credentials),
|
2015-10-11 15:49:44 +03:00
|
|
|
collapse_lhs: false,
|
2015-10-11 18:07:01 +03:00
|
|
|
collapse_rhs: false,
|
2015-09-18 20:39:16 +03:00
|
|
|
ready: false,
|
2016-01-17 06:59:31 +03:00
|
|
|
width: 10000,
|
2015-06-11 20:25:29 +03:00
|
|
|
};
|
2015-09-18 20:39:16 +03:00
|
|
|
if (s.logged_in) {
|
|
|
|
if (MatrixClientPeg.get().getRooms().length) {
|
|
|
|
s.page_type = this.PageTypes.RoomView;
|
|
|
|
} else {
|
2015-11-15 06:58:05 +03:00
|
|
|
// we don't need to default to the directoy here
|
|
|
|
// as we'll go there anyway after syncing
|
|
|
|
// s.page_type = this.PageTypes.RoomDirectory;
|
2015-09-18 20:39:16 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return s;
|
2015-06-11 20:25:29 +03:00
|
|
|
},
|
|
|
|
|
2015-12-17 17:56:55 +03:00
|
|
|
getDefaultProps: function() {
|
|
|
|
return {
|
|
|
|
startingQueryParams: {}
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
2015-12-21 15:55:13 +03:00
|
|
|
componentWillMount: function() {
|
|
|
|
this.favicon = new Favico({animation: 'none'});
|
|
|
|
},
|
|
|
|
|
2015-06-12 16:59:33 +03:00
|
|
|
componentDidMount: function() {
|
2015-12-04 14:34:50 +03:00
|
|
|
this._autoRegisterAsGuest = false;
|
|
|
|
if (this.props.enableGuest) {
|
|
|
|
if (!this.props.config || !this.props.config.default_hs_url) {
|
|
|
|
console.error("Cannot enable guest access: No supplied config prop for HS/IS URLs");
|
|
|
|
}
|
2016-01-28 18:42:14 +03:00
|
|
|
else if (this.props.startingQueryParams.client_secret && this.props.startingQueryParams.sid) {
|
|
|
|
console.log("Not registering as guest; registration.");
|
|
|
|
this._autoRegisterAsGuest = false;
|
|
|
|
}
|
2015-12-04 14:34:50 +03:00
|
|
|
else {
|
|
|
|
this._autoRegisterAsGuest = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-12 19:34:17 +03:00
|
|
|
this.dispatcherRef = dis.register(this.onAction);
|
2015-06-12 16:59:33 +03:00
|
|
|
if (this.state.logged_in) {
|
2015-12-04 14:34:50 +03:00
|
|
|
// Don't auto-register as a guest. This applies if you refresh the page on a
|
|
|
|
// logged in client THEN hit the Sign Out button.
|
|
|
|
this._autoRegisterAsGuest = false;
|
2015-06-12 16:59:33 +03:00
|
|
|
this.startMatrixClient();
|
|
|
|
}
|
2015-06-18 17:03:57 +03:00
|
|
|
this.focusComposer = false;
|
2015-12-10 19:26:36 +03:00
|
|
|
// scrollStateMap is a map from room id to the scroll state returned by
|
|
|
|
// RoomView.getScrollState()
|
|
|
|
this.scrollStateMap = {};
|
2015-06-25 19:41:55 +03:00
|
|
|
document.addEventListener("keydown", this.onKeyDown);
|
2015-07-07 15:30:38 +03:00
|
|
|
window.addEventListener("focus", this.onFocus);
|
2015-12-04 14:34:50 +03:00
|
|
|
|
2015-07-15 21:25:36 +03:00
|
|
|
if (this.state.logged_in) {
|
|
|
|
this.notifyNewScreen('');
|
2015-12-04 14:34:50 +03:00
|
|
|
} else if (this._autoRegisterAsGuest) {
|
|
|
|
this._registerAsGuest();
|
2015-07-15 21:25:36 +03:00
|
|
|
} else {
|
|
|
|
this.notifyNewScreen('login');
|
|
|
|
}
|
2015-10-27 12:58:55 +03:00
|
|
|
|
|
|
|
// this can technically be done anywhere but doing this here keeps all
|
|
|
|
// the routing url path logic together.
|
2015-10-27 13:44:41 +03:00
|
|
|
if (this.onAliasClick) {
|
|
|
|
linkifyMatrix.onAliasClick = this.onAliasClick;
|
|
|
|
}
|
|
|
|
if (this.onUserClick) {
|
|
|
|
linkifyMatrix.onUserClick = this.onUserClick;
|
|
|
|
}
|
2015-11-30 21:11:04 +03:00
|
|
|
|
|
|
|
window.addEventListener('resize', this.handleResize);
|
|
|
|
this.handleResize();
|
2015-06-12 16:59:33 +03:00
|
|
|
},
|
|
|
|
|
2015-06-12 19:34:17 +03:00
|
|
|
componentWillUnmount: function() {
|
|
|
|
dis.unregister(this.dispatcherRef);
|
2015-06-25 19:41:55 +03:00
|
|
|
document.removeEventListener("keydown", this.onKeyDown);
|
2015-09-18 20:39:16 +03:00
|
|
|
window.removeEventListener("focus", this.onFocus);
|
2015-11-30 21:11:04 +03:00
|
|
|
window.removeEventListener('resize', this.handleResize);
|
2015-06-12 19:34:17 +03:00
|
|
|
},
|
|
|
|
|
2015-06-18 17:03:57 +03:00
|
|
|
componentDidUpdate: function() {
|
|
|
|
if (this.focusComposer) {
|
|
|
|
dis.dispatch({action: 'focus_composer'});
|
|
|
|
this.focusComposer = false;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2015-12-04 14:34:50 +03:00
|
|
|
_registerAsGuest: function() {
|
|
|
|
var self = this;
|
|
|
|
var config = this.props.config;
|
|
|
|
console.log("Doing guest login on %s", config.default_hs_url);
|
|
|
|
MatrixClientPeg.replaceUsingUrls(
|
|
|
|
config.default_hs_url, config.default_is_url
|
|
|
|
);
|
|
|
|
MatrixClientPeg.get().registerGuest().done(function(creds) {
|
2015-12-04 18:28:35 +03:00
|
|
|
console.log("Registered as guest: %s", creds.user_id);
|
2016-01-11 18:12:55 +03:00
|
|
|
self._setAutoRegisterAsGuest(false);
|
2015-12-04 18:28:35 +03:00
|
|
|
self.onLoggedIn({
|
|
|
|
userId: creds.user_id,
|
|
|
|
accessToken: creds.access_token,
|
|
|
|
homeserverUrl: config.default_hs_url,
|
|
|
|
identityServerUrl: config.default_is_url,
|
|
|
|
guest: true
|
|
|
|
});
|
2015-12-04 14:34:50 +03:00
|
|
|
}, function(err) {
|
2016-02-15 21:44:13 +03:00
|
|
|
console.error("Failed to register as guest: " + err + " " + err.data);
|
2015-12-04 14:34:50 +03:00
|
|
|
self._setAutoRegisterAsGuest(false);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
_setAutoRegisterAsGuest: function(shouldAutoRegister) {
|
|
|
|
this._autoRegisterAsGuest = shouldAutoRegister;
|
|
|
|
this.forceUpdate();
|
|
|
|
},
|
|
|
|
|
2015-06-12 19:34:17 +03:00
|
|
|
onAction: function(payload) {
|
2015-06-25 19:41:55 +03:00
|
|
|
var roomIndexDelta = 1;
|
|
|
|
|
2015-10-05 17:31:08 +03:00
|
|
|
var self = this;
|
2015-06-12 19:34:17 +03:00
|
|
|
switch (payload.action) {
|
|
|
|
case 'logout':
|
2015-07-16 18:12:54 +03:00
|
|
|
if (window.localStorage) {
|
|
|
|
window.localStorage.clear();
|
|
|
|
}
|
2015-07-03 13:12:54 +03:00
|
|
|
Notifier.stop();
|
2015-10-26 16:54:54 +03:00
|
|
|
UserActivity.stop();
|
2015-09-18 20:39:16 +03:00
|
|
|
Presence.stop();
|
|
|
|
MatrixClientPeg.get().stopClient();
|
2015-07-02 15:18:03 +03:00
|
|
|
MatrixClientPeg.get().removeAllListeners();
|
2015-09-18 20:39:16 +03:00
|
|
|
MatrixClientPeg.unset();
|
2015-10-05 17:31:08 +03:00
|
|
|
this.notifyNewScreen('login');
|
2015-10-09 15:48:17 +03:00
|
|
|
this.replaceState({
|
|
|
|
logged_in: false,
|
|
|
|
ready: false
|
|
|
|
});
|
2015-06-12 19:34:17 +03:00
|
|
|
break;
|
2015-07-13 21:14:02 +03:00
|
|
|
case 'start_registration':
|
2015-07-15 22:33:12 +03:00
|
|
|
var newState = payload.params || {};
|
|
|
|
newState.screen = 'register';
|
|
|
|
if (
|
|
|
|
payload.params &&
|
|
|
|
payload.params.client_secret &&
|
|
|
|
payload.params.session_id &&
|
|
|
|
payload.params.hs_url &&
|
|
|
|
payload.params.is_url &&
|
|
|
|
payload.params.sid
|
|
|
|
) {
|
|
|
|
newState.register_client_secret = payload.params.client_secret;
|
|
|
|
newState.register_session_id = payload.params.session_id;
|
|
|
|
newState.register_hs_url = payload.params.hs_url;
|
|
|
|
newState.register_is_url = payload.params.is_url;
|
|
|
|
newState.register_id_sid = payload.params.sid;
|
|
|
|
}
|
|
|
|
this.replaceState(newState);
|
2015-07-15 21:25:36 +03:00
|
|
|
this.notifyNewScreen('register');
|
2015-07-13 21:14:02 +03:00
|
|
|
break;
|
|
|
|
case 'start_login':
|
|
|
|
if (this.state.logged_in) return;
|
2015-07-15 21:25:36 +03:00
|
|
|
this.replaceState({
|
2015-07-13 21:14:02 +03:00
|
|
|
screen: 'login'
|
|
|
|
});
|
2015-07-15 21:25:36 +03:00
|
|
|
this.notifyNewScreen('login');
|
2015-10-09 00:25:33 +03:00
|
|
|
break;
|
2015-11-20 14:57:04 +03:00
|
|
|
case 'start_post_registration':
|
|
|
|
this.setState({ // don't clobber logged_in status
|
|
|
|
screen: 'post_registration'
|
|
|
|
});
|
|
|
|
break;
|
2016-01-07 20:23:32 +03:00
|
|
|
case 'start_upgrade_registration':
|
|
|
|
this.replaceState({
|
|
|
|
screen: "register",
|
|
|
|
upgradeUsername: MatrixClientPeg.get().getUserIdLocalpart(),
|
|
|
|
guestAccessToken: MatrixClientPeg.get().getAccessToken()
|
|
|
|
});
|
|
|
|
this.notifyNewScreen('register');
|
|
|
|
break;
|
2016-01-12 20:20:16 +03:00
|
|
|
case 'start_password_recovery':
|
|
|
|
if (this.state.logged_in) return;
|
|
|
|
this.replaceState({
|
|
|
|
screen: 'forgot_password'
|
|
|
|
});
|
|
|
|
this.notifyNewScreen('forgot_password');
|
|
|
|
break;
|
2015-11-06 14:21:13 +03:00
|
|
|
case 'token_login':
|
2015-10-09 00:25:33 +03:00
|
|
|
if (this.state.logged_in) return;
|
|
|
|
|
|
|
|
var self = this;
|
2015-11-06 14:21:13 +03:00
|
|
|
MatrixClientPeg.replaceUsingUrls(
|
|
|
|
payload.params.homeserver,
|
|
|
|
payload.params.identityServer
|
|
|
|
);
|
2015-10-09 00:25:33 +03:00
|
|
|
|
2015-11-06 14:21:13 +03:00
|
|
|
var client = MatrixClientPeg.get();
|
|
|
|
client.loginWithToken(payload.params.loginToken).done(function(data) {
|
2015-10-09 00:25:33 +03:00
|
|
|
MatrixClientPeg.replaceUsingAccessToken(
|
2015-10-12 12:13:01 +03:00
|
|
|
client.getHomeserverUrl(), client.getIdentityServerUrl(),
|
2015-10-09 00:25:33 +03:00
|
|
|
data.user_id, data.access_token
|
|
|
|
);
|
|
|
|
self.setState({
|
|
|
|
screen: undefined,
|
|
|
|
logged_in: true
|
|
|
|
});
|
2015-11-06 14:42:13 +03:00
|
|
|
|
|
|
|
// We're left with the login token, hs and is url as query params
|
|
|
|
// in the url, a little nasty but let's redirect to clear them
|
|
|
|
var parsedUrl = url.parse(window.location.href);
|
|
|
|
parsedUrl.search = "";
|
|
|
|
window.location.href = url.format(parsedUrl);
|
|
|
|
|
2015-10-09 00:25:33 +03:00
|
|
|
}, function(error) {
|
|
|
|
self.notifyNewScreen('login');
|
|
|
|
self.setState({errorText: 'Login failed.'});
|
|
|
|
});
|
|
|
|
|
2015-12-13 16:49:28 +03:00
|
|
|
break;
|
|
|
|
case 'leave_room':
|
|
|
|
var ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
|
|
|
|
var QuestionDialog = sdk.getComponent("dialogs.QuestionDialog");
|
|
|
|
|
|
|
|
var roomId = payload.room_id;
|
|
|
|
Modal.createDialog(QuestionDialog, {
|
|
|
|
title: "Leave room",
|
|
|
|
description: "Are you sure you want to leave the room?",
|
|
|
|
onFinished: function(should_leave) {
|
|
|
|
if (should_leave) {
|
|
|
|
var d = MatrixClientPeg.get().leave(roomId);
|
|
|
|
|
|
|
|
// FIXME: controller shouldn't be loading a view :(
|
|
|
|
var Loader = sdk.getComponent("elements.Spinner");
|
|
|
|
var modal = Modal.createDialog(Loader);
|
|
|
|
|
|
|
|
d.then(function() {
|
|
|
|
modal.close();
|
|
|
|
dis.dispatch({action: 'view_next_room'});
|
|
|
|
}, function(err) {
|
|
|
|
modal.close();
|
|
|
|
Modal.createDialog(ErrorDialog, {
|
|
|
|
title: "Failed to leave room",
|
|
|
|
description: err.toString()
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2015-07-13 21:14:02 +03:00
|
|
|
break;
|
2015-06-12 20:01:38 +03:00
|
|
|
case 'view_room':
|
2016-03-01 21:23:57 +03:00
|
|
|
this._viewRoom(
|
|
|
|
payload.room_id, payload.show_settings, payload.event_id,
|
|
|
|
payload.invite_sign_url, payload.oob_data
|
|
|
|
);
|
2015-06-12 20:01:38 +03:00
|
|
|
break;
|
2015-06-25 19:41:55 +03:00
|
|
|
case 'view_prev_room':
|
|
|
|
roomIndexDelta = -1;
|
|
|
|
case 'view_next_room':
|
2015-07-08 21:47:58 +03:00
|
|
|
var allRooms = RoomListSorter.mostRecentActivityFirst(
|
|
|
|
MatrixClientPeg.get().getRooms()
|
|
|
|
);
|
2015-06-25 19:41:55 +03:00
|
|
|
var roomIndex = -1;
|
|
|
|
for (var i = 0; i < allRooms.length; ++i) {
|
|
|
|
if (allRooms[i].roomId == this.state.currentRoom) {
|
|
|
|
roomIndex = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
roomIndex = (roomIndex + roomIndexDelta) % allRooms.length;
|
2015-09-18 20:39:16 +03:00
|
|
|
if (roomIndex < 0) roomIndex = allRooms.length - 1;
|
2015-12-10 19:26:36 +03:00
|
|
|
this._viewRoom(allRooms[roomIndex].roomId);
|
2015-09-18 20:39:16 +03:00
|
|
|
break;
|
|
|
|
case 'view_indexed_room':
|
|
|
|
var allRooms = RoomListSorter.mostRecentActivityFirst(
|
|
|
|
MatrixClientPeg.get().getRooms()
|
|
|
|
);
|
|
|
|
var roomIndex = payload.roomIndex;
|
|
|
|
if (allRooms[roomIndex]) {
|
2015-12-10 19:26:36 +03:00
|
|
|
this._viewRoom(allRooms[roomIndex].roomId);
|
2015-09-18 20:39:16 +03:00
|
|
|
}
|
|
|
|
break;
|
2015-10-05 17:31:08 +03:00
|
|
|
case 'view_room_alias':
|
2015-10-27 12:58:55 +03:00
|
|
|
var foundRoom = MatrixTools.getRoomForAlias(
|
|
|
|
MatrixClientPeg.get().getRooms(), payload.room_alias
|
|
|
|
);
|
|
|
|
if (foundRoom) {
|
|
|
|
dis.dispatch({
|
|
|
|
action: 'view_room',
|
2016-02-01 19:31:12 +03:00
|
|
|
room_id: foundRoom.roomId,
|
|
|
|
event_id: payload.event_id,
|
2016-02-23 13:15:07 +03:00
|
|
|
invite_sign_url: payload.invite_sign_url,
|
2016-03-01 21:23:57 +03:00
|
|
|
oob_data: payload.oob_data,
|
2015-10-27 12:58:55 +03:00
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// resolve the alias and *then* view it
|
|
|
|
MatrixClientPeg.get().getRoomIdForAlias(payload.room_alias).done(
|
|
|
|
function(result) {
|
2015-10-05 17:31:08 +03:00
|
|
|
dis.dispatch({
|
|
|
|
action: 'view_room',
|
2016-02-01 19:31:12 +03:00
|
|
|
room_id: result.room_id,
|
|
|
|
event_id: payload.event_id,
|
2016-02-23 13:15:07 +03:00
|
|
|
invite_sign_url: payload.invite_sign_url,
|
2016-03-02 17:31:01 +03:00
|
|
|
oob_data: payload.oob_data,
|
2015-10-05 17:31:08 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
break;
|
2015-09-18 20:39:16 +03:00
|
|
|
case 'view_user_settings':
|
2015-12-11 00:53:14 +03:00
|
|
|
this._setPage(this.PageTypes.UserSettings);
|
2015-11-11 04:01:48 +03:00
|
|
|
this.notifyNewScreen('settings');
|
2015-09-18 20:39:16 +03:00
|
|
|
break;
|
|
|
|
case 'view_create_room':
|
2016-01-17 06:59:31 +03:00
|
|
|
//this._setPage(this.PageTypes.CreateRoom);
|
|
|
|
//this.notifyNewScreen('new');
|
|
|
|
|
|
|
|
var ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
|
|
|
|
var Loader = sdk.getComponent("elements.Spinner");
|
|
|
|
var modal = Modal.createDialog(Loader);
|
|
|
|
|
|
|
|
MatrixClientPeg.get().createRoom({
|
2016-02-23 20:55:45 +03:00
|
|
|
preset: "private_chat",
|
2016-02-23 21:10:48 +03:00
|
|
|
// Allow guests by default since the room is private and they'd
|
|
|
|
// need an invite. This means clicking on a 3pid invite email can
|
|
|
|
// actually drop you right in to a chat.
|
2016-02-23 20:55:45 +03:00
|
|
|
initial_state: [
|
|
|
|
{
|
|
|
|
content: {
|
|
|
|
guest_access: 'can_join'
|
|
|
|
},
|
|
|
|
type: 'm.room.guest_access',
|
|
|
|
state_key: '',
|
|
|
|
}
|
|
|
|
],
|
2016-01-17 06:59:31 +03:00
|
|
|
}).done(function(res) {
|
|
|
|
modal.close();
|
|
|
|
dis.dispatch({
|
|
|
|
action: 'view_room',
|
|
|
|
room_id: res.room_id,
|
2016-01-21 03:16:10 +03:00
|
|
|
// show_settings: true,
|
2016-01-17 06:59:31 +03:00
|
|
|
});
|
|
|
|
}, function(err) {
|
|
|
|
modal.close();
|
|
|
|
Modal.createDialog(ErrorDialog, {
|
|
|
|
title: "Failed to create room",
|
|
|
|
description: err.toString()
|
|
|
|
});
|
|
|
|
});
|
2015-09-18 20:39:16 +03:00
|
|
|
break;
|
|
|
|
case 'view_room_directory':
|
2015-12-11 00:53:14 +03:00
|
|
|
this._setPage(this.PageTypes.RoomDirectory);
|
2015-11-11 04:01:48 +03:00
|
|
|
this.notifyNewScreen('directory');
|
2015-09-18 20:39:16 +03:00
|
|
|
break;
|
|
|
|
case 'notifier_enabled':
|
|
|
|
this.forceUpdate();
|
2015-06-25 19:41:55 +03:00
|
|
|
break;
|
2015-10-11 15:49:44 +03:00
|
|
|
case 'hide_left_panel':
|
|
|
|
this.setState({
|
|
|
|
collapse_lhs: true,
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
case 'show_left_panel':
|
|
|
|
this.setState({
|
|
|
|
collapse_lhs: false,
|
|
|
|
});
|
|
|
|
break;
|
2015-10-11 18:07:01 +03:00
|
|
|
case 'hide_right_panel':
|
|
|
|
this.setState({
|
|
|
|
collapse_rhs: true,
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
case 'show_right_panel':
|
|
|
|
this.setState({
|
|
|
|
collapse_rhs: false,
|
|
|
|
});
|
|
|
|
break;
|
2015-06-12 19:34:17 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2015-12-11 00:53:14 +03:00
|
|
|
_setPage: function(pageType) {
|
|
|
|
// record the scroll state if we're in a room view.
|
|
|
|
this._updateScrollMap();
|
|
|
|
|
|
|
|
this.setState({
|
2015-12-14 14:07:59 +03:00
|
|
|
page_type: pageType,
|
2015-12-11 00:53:14 +03:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2016-02-01 19:31:12 +03:00
|
|
|
// switch view to the given room
|
|
|
|
//
|
|
|
|
// eventId is optional and will cause a switch to the context of that
|
|
|
|
// particular event.
|
2016-03-02 17:01:21 +03:00
|
|
|
// @param {Object} oob_data Object of additional data about the room
|
2016-03-01 21:23:57 +03:00
|
|
|
// that has been passed out-of-band (eg.
|
|
|
|
// room name and avatar from an invite email)
|
|
|
|
_viewRoom: function(roomId, showSettings, eventId, invite_sign_url, oob_data) {
|
2015-12-10 19:26:36 +03:00
|
|
|
// before we switch room, record the scroll state of the current room
|
|
|
|
this._updateScrollMap();
|
|
|
|
|
|
|
|
this.focusComposer = true;
|
2016-02-01 19:31:12 +03:00
|
|
|
|
2015-12-10 19:26:36 +03:00
|
|
|
var newState = {
|
|
|
|
currentRoom: roomId,
|
2016-02-01 19:31:12 +03:00
|
|
|
initialEventId: eventId,
|
|
|
|
highlightedEventId: eventId,
|
|
|
|
initialEventPixelOffset: undefined,
|
2015-12-10 19:26:36 +03:00
|
|
|
page_type: this.PageTypes.RoomView,
|
2016-02-23 13:15:07 +03:00
|
|
|
inviteSignUrl: invite_sign_url,
|
2016-03-01 21:23:57 +03:00
|
|
|
roomOobData: oob_data,
|
2015-12-10 19:26:36 +03:00
|
|
|
};
|
2016-02-01 19:31:12 +03:00
|
|
|
|
|
|
|
// if we aren't given an explicit event id, look for one in the
|
|
|
|
// scrollStateMap.
|
|
|
|
if (!eventId) {
|
|
|
|
var scrollState = this.scrollStateMap[roomId];
|
|
|
|
if (scrollState) {
|
|
|
|
newState.initialEventId = scrollState.focussedEvent;
|
|
|
|
newState.initialEventPixelOffset = scrollState.pixelOffset;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-10 19:26:36 +03:00
|
|
|
if (this.sdkReady) {
|
|
|
|
// if the SDK is not ready yet, remember what room
|
|
|
|
// we're supposed to be on but don't notify about
|
|
|
|
// the new screen yet (we won't be showing it yet)
|
|
|
|
// The normal case where this happens is navigating
|
|
|
|
// to the room in the URL bar on page load.
|
|
|
|
var presentedId = roomId;
|
|
|
|
var room = MatrixClientPeg.get().getRoom(roomId);
|
|
|
|
if (room) {
|
|
|
|
var theAlias = MatrixTools.getCanonicalAliasForRoom(room);
|
|
|
|
if (theAlias) presentedId = theAlias;
|
2016-01-08 06:22:38 +03:00
|
|
|
|
2016-01-13 16:15:13 +03:00
|
|
|
var color_scheme_event = room.getAccountData("org.matrix.room.color_scheme");
|
2016-01-08 06:22:38 +03:00
|
|
|
var color_scheme = {};
|
|
|
|
if (color_scheme_event) {
|
|
|
|
color_scheme = color_scheme_event.getContent();
|
|
|
|
// XXX: we should validate the event
|
|
|
|
}
|
|
|
|
Tinter.tint(color_scheme.primary_color, color_scheme.secondary_color);
|
2015-12-10 19:26:36 +03:00
|
|
|
}
|
2016-01-08 06:22:38 +03:00
|
|
|
|
2016-02-01 19:31:12 +03:00
|
|
|
if (eventId) {
|
|
|
|
presentedId += "/"+eventId;
|
|
|
|
}
|
2015-12-10 19:26:36 +03:00
|
|
|
this.notifyNewScreen('room/'+presentedId);
|
|
|
|
newState.ready = true;
|
|
|
|
}
|
|
|
|
this.setState(newState);
|
2016-02-01 19:31:12 +03:00
|
|
|
|
2016-01-17 06:59:31 +03:00
|
|
|
if (this.refs.roomView && showSettings) {
|
|
|
|
this.refs.roomView.showSettings(true);
|
|
|
|
}
|
2015-12-10 19:26:36 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
// update scrollStateMap according to the current scroll state of the
|
|
|
|
// room view.
|
|
|
|
_updateScrollMap: function() {
|
2015-12-11 00:44:30 +03:00
|
|
|
if (!this.refs.roomView) {
|
2015-12-10 19:26:36 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-12-11 00:44:30 +03:00
|
|
|
var roomview = this.refs.roomView;
|
2015-12-10 19:26:36 +03:00
|
|
|
var state = roomview.getScrollState();
|
|
|
|
this.scrollStateMap[roomview.props.roomId] = state;
|
|
|
|
},
|
|
|
|
|
2015-11-12 18:15:00 +03:00
|
|
|
onLoggedIn: function(credentials) {
|
2015-12-04 18:28:35 +03:00
|
|
|
credentials.guest = Boolean(credentials.guest);
|
|
|
|
console.log("onLoggedIn => %s (guest=%s)", credentials.userId, credentials.guest);
|
2015-11-20 14:57:04 +03:00
|
|
|
MatrixClientPeg.replaceUsingAccessToken(
|
|
|
|
credentials.homeserverUrl, credentials.identityServerUrl,
|
2015-12-04 18:28:35 +03:00
|
|
|
credentials.userId, credentials.accessToken, credentials.guest
|
2015-11-20 14:57:04 +03:00
|
|
|
);
|
2015-07-13 21:14:02 +03:00
|
|
|
this.setState({
|
2015-07-15 21:25:36 +03:00
|
|
|
screen: undefined,
|
2015-07-13 21:14:02 +03:00
|
|
|
logged_in: true
|
|
|
|
});
|
2015-06-12 16:59:33 +03:00
|
|
|
this.startMatrixClient();
|
2015-07-15 21:25:36 +03:00
|
|
|
this.notifyNewScreen('');
|
2015-06-12 16:59:33 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
startMatrixClient: function() {
|
2015-07-02 15:18:03 +03:00
|
|
|
var cli = MatrixClientPeg.get();
|
2015-09-15 15:34:36 +03:00
|
|
|
var self = this;
|
2015-12-15 17:23:58 +03:00
|
|
|
cli.on('sync', function(state, prevState) {
|
2015-12-21 15:55:13 +03:00
|
|
|
self.updateFavicon();
|
2015-12-15 17:23:58 +03:00
|
|
|
if (state === "SYNCING" && prevState === "SYNCING") {
|
|
|
|
return;
|
|
|
|
}
|
2015-11-12 18:15:00 +03:00
|
|
|
console.log("MatrixClient sync state => %s", state);
|
|
|
|
if (state !== "PREPARED") { return; }
|
2015-09-18 20:39:16 +03:00
|
|
|
self.sdkReady = true;
|
2015-09-25 19:22:42 +03:00
|
|
|
|
|
|
|
if (self.starting_room_alias) {
|
2015-10-05 17:31:08 +03:00
|
|
|
dis.dispatch({
|
|
|
|
action: 'view_room_alias',
|
2016-02-01 19:31:12 +03:00
|
|
|
room_alias: self.starting_room_alias,
|
|
|
|
event_id: self.starting_event_id,
|
2016-02-23 13:15:07 +03:00
|
|
|
invite_sign_url: self.starting_room_invite_sign_url,
|
2016-03-02 17:02:36 +03:00
|
|
|
oob_data: self.starting_room_oob_data,
|
2015-09-25 19:22:42 +03:00
|
|
|
});
|
2015-10-05 17:31:08 +03:00
|
|
|
delete self.starting_room_alias;
|
2016-02-01 19:31:12 +03:00
|
|
|
delete self.starting_event_id;
|
2016-02-23 13:15:07 +03:00
|
|
|
delete self.starting_room_invite_sign_url;
|
2016-03-01 21:23:57 +03:00
|
|
|
delete self.starting_room_oob_data;
|
2015-11-11 04:32:16 +03:00
|
|
|
} else if (!self.state.page_type) {
|
2015-09-25 19:22:42 +03:00
|
|
|
if (!self.state.currentRoom) {
|
|
|
|
var firstRoom = null;
|
|
|
|
if (cli.getRooms() && cli.getRooms().length) {
|
|
|
|
firstRoom = RoomListSorter.mostRecentActivityFirst(
|
|
|
|
cli.getRooms()
|
|
|
|
)[0].roomId;
|
|
|
|
self.setState({ready: true, currentRoom: firstRoom, page_type: self.PageTypes.RoomView});
|
|
|
|
} else {
|
|
|
|
self.setState({ready: true, page_type: self.PageTypes.RoomDirectory});
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
self.setState({ready: true, page_type: self.PageTypes.RoomView});
|
|
|
|
}
|
|
|
|
|
|
|
|
// we notifyNewScreen now because now the room will actually be displayed,
|
|
|
|
// and (mostly) now we can get the correct alias.
|
|
|
|
var presentedId = self.state.currentRoom;
|
|
|
|
var room = MatrixClientPeg.get().getRoom(self.state.currentRoom);
|
|
|
|
if (room) {
|
|
|
|
var theAlias = MatrixTools.getCanonicalAliasForRoom(room);
|
|
|
|
if (theAlias) presentedId = theAlias;
|
|
|
|
}
|
2015-11-11 04:32:16 +03:00
|
|
|
self.notifyNewScreen('room/'+presentedId);
|
2015-09-25 19:22:42 +03:00
|
|
|
dis.dispatch({action: 'focus_composer'});
|
2015-11-11 04:32:16 +03:00
|
|
|
} else {
|
|
|
|
self.setState({ready: true});
|
2015-10-05 17:31:08 +03:00
|
|
|
}
|
2015-06-12 16:59:33 +03:00
|
|
|
});
|
2015-09-18 20:39:16 +03:00
|
|
|
cli.on('Call.incoming', function(call) {
|
|
|
|
dis.dispatch({
|
|
|
|
action: 'incoming_call',
|
|
|
|
call: call
|
|
|
|
});
|
|
|
|
});
|
2015-07-03 13:12:54 +03:00
|
|
|
Notifier.start();
|
2015-10-26 16:54:54 +03:00
|
|
|
UserActivity.start();
|
2015-09-18 20:39:16 +03:00
|
|
|
Presence.start();
|
2015-12-07 18:33:58 +03:00
|
|
|
cli.startClient({
|
2016-01-15 16:28:41 +03:00
|
|
|
pendingEventOrdering: "end",
|
2016-02-24 19:42:23 +03:00
|
|
|
initialSyncLimit: this.props.config.sync_timeline_limit || 20,
|
2015-12-07 18:33:58 +03:00
|
|
|
});
|
2015-06-11 20:25:29 +03:00
|
|
|
},
|
2015-06-25 19:41:55 +03:00
|
|
|
|
|
|
|
onKeyDown: function(ev) {
|
|
|
|
if (ev.altKey) {
|
2015-10-31 17:00:23 +03:00
|
|
|
/*
|
|
|
|
// Remove this for now as ctrl+alt = alt-gr so this breaks keyboards which rely on alt-gr for numbers
|
|
|
|
// Will need to find a better meta key if anyone actually cares about using this.
|
2015-09-18 20:39:16 +03:00
|
|
|
if (ev.ctrlKey && ev.keyCode > 48 && ev.keyCode < 58) {
|
|
|
|
dis.dispatch({
|
|
|
|
action: 'view_indexed_room',
|
|
|
|
roomIndex: ev.keyCode - 49,
|
|
|
|
});
|
|
|
|
ev.stopPropagation();
|
|
|
|
ev.preventDefault();
|
|
|
|
return;
|
|
|
|
}
|
2015-10-31 17:00:23 +03:00
|
|
|
*/
|
2015-06-25 19:41:55 +03:00
|
|
|
switch (ev.keyCode) {
|
|
|
|
case 38:
|
|
|
|
dis.dispatch({action: 'view_prev_room'});
|
|
|
|
ev.stopPropagation();
|
2015-09-18 20:39:16 +03:00
|
|
|
ev.preventDefault();
|
2015-06-25 19:41:55 +03:00
|
|
|
break;
|
|
|
|
case 40:
|
|
|
|
dis.dispatch({action: 'view_next_room'});
|
|
|
|
ev.stopPropagation();
|
2015-09-18 20:39:16 +03:00
|
|
|
ev.preventDefault();
|
2015-06-25 19:41:55 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2015-07-07 15:30:38 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
onFocus: function(ev) {
|
|
|
|
dis.dispatch({action: 'focus_composer'});
|
2015-07-15 21:25:36 +03:00
|
|
|
},
|
|
|
|
|
2015-07-16 14:44:04 +03:00
|
|
|
showScreen: function(screen, params) {
|
2015-07-15 22:33:12 +03:00
|
|
|
if (screen == 'register') {
|
|
|
|
dis.dispatch({
|
|
|
|
action: 'start_registration',
|
|
|
|
params: params
|
|
|
|
});
|
|
|
|
} else if (screen == 'login') {
|
|
|
|
dis.dispatch({
|
|
|
|
action: 'start_login',
|
|
|
|
params: params
|
|
|
|
});
|
2015-11-06 14:21:13 +03:00
|
|
|
} else if (screen == 'token_login') {
|
2015-10-09 00:25:33 +03:00
|
|
|
dis.dispatch({
|
2015-11-06 14:21:13 +03:00
|
|
|
action: 'token_login',
|
2015-10-09 00:25:33 +03:00
|
|
|
params: params
|
|
|
|
});
|
2016-01-12 20:20:16 +03:00
|
|
|
} else if (screen == 'forgot_password') {
|
|
|
|
dis.dispatch({
|
|
|
|
action: 'start_password_recovery',
|
|
|
|
params: params
|
|
|
|
});
|
2015-11-11 04:01:48 +03:00
|
|
|
} else if (screen == 'new') {
|
|
|
|
dis.dispatch({
|
|
|
|
action: 'view_create_room',
|
|
|
|
});
|
|
|
|
} else if (screen == 'settings') {
|
|
|
|
dis.dispatch({
|
|
|
|
action: 'view_user_settings',
|
|
|
|
});
|
|
|
|
} else if (screen == 'directory') {
|
|
|
|
dis.dispatch({
|
|
|
|
action: 'view_room_directory',
|
|
|
|
});
|
2015-11-20 14:57:04 +03:00
|
|
|
} else if (screen == 'post_registration') {
|
|
|
|
dis.dispatch({
|
|
|
|
action: 'start_post_registration',
|
|
|
|
});
|
2015-09-18 20:39:16 +03:00
|
|
|
} else if (screen.indexOf('room/') == 0) {
|
2016-02-03 11:03:10 +03:00
|
|
|
var segments = screen.substring(5).split('/');
|
|
|
|
var roomString = segments[0];
|
|
|
|
var eventId = segments[1]; // undefined if no event id given
|
2016-03-01 21:23:57 +03:00
|
|
|
|
|
|
|
var oob_data = {
|
|
|
|
name: params.room_name,
|
|
|
|
avatarUrl: params.room_avatar_url,
|
|
|
|
inviterName: params.inviter_name,
|
|
|
|
};
|
|
|
|
|
2015-09-18 20:39:16 +03:00
|
|
|
if (roomString[0] == '#') {
|
2015-10-05 17:31:08 +03:00
|
|
|
if (this.state.logged_in) {
|
|
|
|
dis.dispatch({
|
|
|
|
action: 'view_room_alias',
|
2016-02-01 19:31:12 +03:00
|
|
|
room_alias: roomString,
|
|
|
|
event_id: eventId,
|
2016-02-23 13:15:07 +03:00
|
|
|
invite_sign_url: params.signurl,
|
2016-03-01 21:23:57 +03:00
|
|
|
oob_data: oob_data,
|
2015-10-05 17:31:08 +03:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
// Okay, we'll take you here soon...
|
2016-03-01 21:23:57 +03:00
|
|
|
// XXX: There are way too many of these:
|
|
|
|
// It would probably be better to handle whether the SDK is
|
|
|
|
// ready or not in the view_room_alias handler instead.
|
2015-10-05 17:31:08 +03:00
|
|
|
this.starting_room_alias = roomString;
|
2016-02-23 13:15:07 +03:00
|
|
|
this.starting_room_invite_sign_url = params.signurl;
|
2016-03-01 21:23:57 +03:00
|
|
|
this.starting_room_oob_data = oob_data;
|
2016-02-01 19:31:12 +03:00
|
|
|
this.starting_event_id = eventId;
|
2015-10-05 17:31:08 +03:00
|
|
|
// ...but you're still going to have to log in.
|
|
|
|
this.notifyNewScreen('login');
|
|
|
|
}
|
2015-09-18 20:39:16 +03:00
|
|
|
} else {
|
|
|
|
dis.dispatch({
|
|
|
|
action: 'view_room',
|
2016-02-01 19:31:12 +03:00
|
|
|
room_id: roomString,
|
|
|
|
event_id: eventId,
|
2016-02-23 13:15:07 +03:00
|
|
|
invite_sign_url: params.signurl,
|
2016-03-01 21:23:57 +03:00
|
|
|
oob_data: oob_data,
|
2015-09-18 20:39:16 +03:00
|
|
|
});
|
2015-09-25 19:22:42 +03:00
|
|
|
}
|
2015-07-15 22:33:12 +03:00
|
|
|
}
|
2015-11-20 17:26:49 +03:00
|
|
|
else {
|
2016-01-27 13:47:54 +03:00
|
|
|
console.error("Unknown screen : %s", screen);
|
2015-11-20 17:26:49 +03:00
|
|
|
}
|
2015-07-15 21:25:36 +03:00
|
|
|
},
|
|
|
|
|
2015-12-17 18:12:09 +03:00
|
|
|
notifyNewScreen: function(screen) {
|
2015-07-15 21:25:36 +03:00
|
|
|
if (this.props.onNewScreen) {
|
2015-12-17 18:12:09 +03:00
|
|
|
this.props.onNewScreen(screen);
|
2015-07-15 21:25:36 +03:00
|
|
|
}
|
2015-11-30 21:11:04 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
onAliasClick: function(event, alias) {
|
|
|
|
event.preventDefault();
|
|
|
|
dis.dispatch({action: 'view_room_alias', room_alias: alias});
|
|
|
|
},
|
|
|
|
|
|
|
|
onUserClick: function(event, userId) {
|
|
|
|
event.preventDefault();
|
2016-01-18 04:26:15 +03:00
|
|
|
|
|
|
|
/*
|
2015-11-30 21:11:04 +03:00
|
|
|
var MemberInfo = sdk.getComponent('rooms.MemberInfo');
|
|
|
|
var member = new Matrix.RoomMember(null, userId);
|
|
|
|
ContextualMenu.createMenu(MemberInfo, {
|
|
|
|
member: member,
|
|
|
|
right: window.innerWidth - event.pageX,
|
|
|
|
top: event.pageY
|
|
|
|
});
|
2016-01-18 04:26:15 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
var member = new Matrix.RoomMember(null, userId);
|
|
|
|
if (!member) { return; }
|
|
|
|
dis.dispatch({
|
|
|
|
action: 'view_user',
|
|
|
|
member: member,
|
|
|
|
});
|
2015-11-30 21:11:04 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
onLogoutClick: function(event) {
|
|
|
|
dis.dispatch({
|
|
|
|
action: 'logout'
|
|
|
|
});
|
|
|
|
event.stopPropagation();
|
|
|
|
event.preventDefault();
|
|
|
|
},
|
|
|
|
|
|
|
|
handleResize: function(e) {
|
|
|
|
var hideLhsThreshold = 1000;
|
|
|
|
var showLhsThreshold = 1000;
|
|
|
|
var hideRhsThreshold = 820;
|
|
|
|
var showRhsThreshold = 820;
|
|
|
|
|
|
|
|
if (this.state.width > hideLhsThreshold && window.innerWidth <= hideLhsThreshold) {
|
|
|
|
dis.dispatch({ action: 'hide_left_panel' });
|
|
|
|
}
|
|
|
|
if (this.state.width <= showLhsThreshold && window.innerWidth > showLhsThreshold) {
|
|
|
|
dis.dispatch({ action: 'show_left_panel' });
|
|
|
|
}
|
|
|
|
if (this.state.width > hideRhsThreshold && window.innerWidth <= hideRhsThreshold) {
|
|
|
|
dis.dispatch({ action: 'hide_right_panel' });
|
|
|
|
}
|
|
|
|
if (this.state.width <= showRhsThreshold && window.innerWidth > showRhsThreshold) {
|
|
|
|
dis.dispatch({ action: 'show_right_panel' });
|
|
|
|
}
|
|
|
|
|
|
|
|
this.setState({width: window.innerWidth});
|
|
|
|
},
|
|
|
|
|
|
|
|
onRoomCreated: function(room_id) {
|
|
|
|
dis.dispatch({
|
|
|
|
action: "view_room",
|
|
|
|
room_id: room_id,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
onRegisterClick: function() {
|
|
|
|
this.showScreen("register");
|
|
|
|
},
|
|
|
|
|
|
|
|
onLoginClick: function() {
|
|
|
|
this.showScreen("login");
|
|
|
|
},
|
|
|
|
|
2016-01-12 20:20:16 +03:00
|
|
|
onForgotPasswordClick: function() {
|
|
|
|
this.showScreen("forgot_password");
|
|
|
|
},
|
|
|
|
|
2015-11-30 21:11:04 +03:00
|
|
|
onRegistered: function(credentials) {
|
|
|
|
this.onLoggedIn(credentials);
|
|
|
|
// do post-registration stuff
|
2016-01-15 21:58:18 +03:00
|
|
|
// This now goes straight to user settings
|
|
|
|
// We use _setPage since if we wait for
|
|
|
|
// showScreen to do the dispatch loop,
|
2016-01-18 17:23:31 +03:00
|
|
|
// the showScreen dispatch will race with the
|
|
|
|
// sdk sync finishing and we'll probably see
|
|
|
|
// the page type still unset when the MatrixClient
|
|
|
|
// is started and show the Room Directory instead.
|
2016-01-15 21:58:18 +03:00
|
|
|
//this.showScreen("view_user_settings");
|
|
|
|
this._setPage(this.PageTypes.UserSettings);
|
2015-11-30 21:11:04 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
onFinishPostRegistration: function() {
|
|
|
|
// Don't confuse this with "PageType" which is the middle window to show
|
|
|
|
this.setState({
|
|
|
|
screen: undefined
|
|
|
|
});
|
|
|
|
this.showScreen("settings");
|
|
|
|
},
|
|
|
|
|
2016-02-03 19:51:53 +03:00
|
|
|
onVersion: function(current, latest) {
|
2016-02-03 19:16:52 +03:00
|
|
|
this.setState({
|
2016-02-03 19:51:53 +03:00
|
|
|
version: current,
|
|
|
|
hasNewVersion: current !== latest
|
2016-02-03 19:16:52 +03:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2015-12-21 15:55:13 +03:00
|
|
|
updateFavicon: function() {
|
|
|
|
var notifCount = 0;
|
|
|
|
|
|
|
|
var rooms = MatrixClientPeg.get().getRooms();
|
|
|
|
for (var i = 0; i < rooms.length; ++i) {
|
2016-01-13 16:00:03 +03:00
|
|
|
if (rooms[i].hasMembershipState(MatrixClientPeg.get().credentials.userId, 'invite')) {
|
|
|
|
++notifCount;
|
2016-01-21 13:23:18 +03:00
|
|
|
} else if (rooms[i].getUnreadNotificationCount()) {
|
|
|
|
notifCount += rooms[i].getUnreadNotificationCount();
|
2016-01-07 13:38:44 +03:00
|
|
|
}
|
2015-12-21 15:55:13 +03:00
|
|
|
}
|
2016-01-27 18:19:25 +03:00
|
|
|
try {
|
|
|
|
// This needs to be in in a try block as it will throw
|
|
|
|
// if there are more than 100 badge count changes in
|
|
|
|
// its internal queue
|
|
|
|
this.favicon.badge(notifCount);
|
|
|
|
} catch (e) {
|
|
|
|
console.warn("Failed to set badge count: "+e.message);
|
|
|
|
}
|
2016-01-27 21:02:15 +03:00
|
|
|
document.title = "Vector"+(notifCount > 0 ? " ["+notifCount+"]" : "");
|
2015-12-21 15:55:13 +03:00
|
|
|
},
|
|
|
|
|
2015-12-23 14:47:56 +03:00
|
|
|
onUserSettingsClose: function() {
|
|
|
|
// XXX: use browser history instead to find the previous room?
|
|
|
|
if (this.state.currentRoom) {
|
|
|
|
dis.dispatch({
|
|
|
|
action: 'view_room',
|
|
|
|
room_id: this.state.currentRoom,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
dis.dispatch({
|
|
|
|
action: 'view_indexed_room',
|
|
|
|
roomIndex: 0,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2015-11-30 21:11:04 +03:00
|
|
|
render: function() {
|
2015-12-01 18:45:11 +03:00
|
|
|
var LeftPanel = sdk.getComponent('structures.LeftPanel');
|
2015-11-30 21:11:04 +03:00
|
|
|
var RoomView = sdk.getComponent('structures.RoomView');
|
2015-12-01 18:45:11 +03:00
|
|
|
var RightPanel = sdk.getComponent('structures.RightPanel');
|
2015-11-30 21:11:04 +03:00
|
|
|
var UserSettings = sdk.getComponent('structures.UserSettings');
|
|
|
|
var CreateRoom = sdk.getComponent('structures.CreateRoom');
|
2015-12-01 18:45:11 +03:00
|
|
|
var RoomDirectory = sdk.getComponent('structures.RoomDirectory');
|
2015-12-01 14:19:25 +03:00
|
|
|
var MatrixToolbar = sdk.getComponent('globals.MatrixToolbar');
|
2016-01-28 15:59:51 +03:00
|
|
|
var GuestWarningBar = sdk.getComponent('globals.GuestWarningBar');
|
2016-02-03 19:16:52 +03:00
|
|
|
var NewVersionBar = sdk.getComponent('globals.NewVersionBar');
|
2016-01-12 20:20:16 +03:00
|
|
|
var ForgotPassword = sdk.getComponent('structures.login.ForgotPassword');
|
2015-11-30 21:11:04 +03:00
|
|
|
|
|
|
|
// needs to be before normal PageTypes as you are logged in technically
|
|
|
|
if (this.state.screen == 'post_registration') {
|
|
|
|
return (
|
|
|
|
<PostRegistration
|
|
|
|
onComplete={this.onFinishPostRegistration} />
|
|
|
|
);
|
|
|
|
}
|
|
|
|
else if (this.state.logged_in && this.state.ready) {
|
|
|
|
var page_element;
|
|
|
|
var right_panel = "";
|
|
|
|
|
|
|
|
switch (this.state.page_type) {
|
|
|
|
case this.PageTypes.RoomView:
|
|
|
|
page_element = (
|
|
|
|
<RoomView
|
2015-12-11 00:44:30 +03:00
|
|
|
ref="roomView"
|
2015-11-30 21:11:04 +03:00
|
|
|
roomId={this.state.currentRoom}
|
2016-02-01 19:31:12 +03:00
|
|
|
eventId={this.state.initialEventId}
|
2016-02-23 13:15:07 +03:00
|
|
|
inviteSignUrl={this.state.inviteSignUrl}
|
2016-03-01 21:23:57 +03:00
|
|
|
oobData={this.state.roomOobData}
|
2016-02-01 19:31:12 +03:00
|
|
|
highlightedEventId={this.state.highlightedEventId}
|
|
|
|
eventPixelOffset={this.state.initialEventPixelOffset}
|
2015-11-30 21:11:04 +03:00
|
|
|
key={this.state.currentRoom}
|
|
|
|
ConferenceHandler={this.props.ConferenceHandler} />
|
|
|
|
);
|
|
|
|
right_panel = <RightPanel roomId={this.state.currentRoom} collapsed={this.state.collapse_rhs} />
|
|
|
|
break;
|
|
|
|
case this.PageTypes.UserSettings:
|
2016-02-03 19:51:53 +03:00
|
|
|
page_element = <UserSettings onClose={this.onUserSettingsClose} version={this.state.version} />
|
2015-11-30 21:11:04 +03:00
|
|
|
right_panel = <RightPanel collapsed={this.state.collapse_rhs}/>
|
|
|
|
break;
|
|
|
|
case this.PageTypes.CreateRoom:
|
|
|
|
page_element = <CreateRoom onRoomCreated={this.onRoomCreated}/>
|
|
|
|
right_panel = <RightPanel collapsed={this.state.collapse_rhs}/>
|
|
|
|
break;
|
|
|
|
case this.PageTypes.RoomDirectory:
|
|
|
|
page_element = <RoomDirectory />
|
|
|
|
right_panel = <RightPanel collapsed={this.state.collapse_rhs}/>
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-02-08 20:20:52 +03:00
|
|
|
var topBar;
|
2016-01-28 15:59:51 +03:00
|
|
|
if (MatrixClientPeg.get().isGuest()) {
|
2016-02-08 20:20:52 +03:00
|
|
|
topBar = <GuestWarningBar />;
|
2015-11-30 21:11:04 +03:00
|
|
|
}
|
2016-02-08 20:20:52 +03:00
|
|
|
else if (Notifier.supportsDesktopNotifications() && !Notifier.isEnabled() && !Notifier.isToolbarHidden()) {
|
|
|
|
topBar = <MatrixToolbar />;
|
|
|
|
}
|
|
|
|
else if (this.state.hasNewVersion) {
|
|
|
|
topBar = <NewVersionBar />;
|
2015-11-30 21:11:04 +03:00
|
|
|
}
|
2016-02-08 20:20:52 +03:00
|
|
|
|
|
|
|
var bodyClasses = "mx_MatrixChat";
|
|
|
|
if (topBar) {
|
|
|
|
bodyClasses += " mx_MatrixChat_toolbarShowing";
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="mx_MatrixChat_wrapper">
|
|
|
|
{topBar}
|
|
|
|
<div className={bodyClasses}>
|
|
|
|
<LeftPanel selectedRoom={this.state.currentRoom} collapsed={this.state.collapse_lhs} />
|
|
|
|
<main className="mx_MatrixChat_middlePanel">
|
|
|
|
{page_element}
|
|
|
|
</main>
|
|
|
|
{right_panel}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
2015-12-04 14:34:50 +03:00
|
|
|
} else if (this.state.logged_in || (!this.state.logged_in && this._autoRegisterAsGuest)) {
|
2015-11-30 21:11:04 +03:00
|
|
|
var Spinner = sdk.getComponent('elements.Spinner');
|
2015-12-04 14:34:50 +03:00
|
|
|
var logoutLink;
|
|
|
|
if (this.state.logged_in) {
|
|
|
|
logoutLink = (
|
|
|
|
<a href="#" className="mx_MatrixChat_splashButtons" onClick={ this.onLogoutClick }>
|
|
|
|
Logout
|
|
|
|
</a>
|
|
|
|
);
|
|
|
|
}
|
2015-11-30 21:11:04 +03:00
|
|
|
return (
|
|
|
|
<div className="mx_MatrixChat_splash">
|
|
|
|
<Spinner />
|
2015-12-04 14:34:50 +03:00
|
|
|
{logoutLink}
|
2015-11-30 21:11:04 +03:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
} else if (this.state.screen == 'register') {
|
|
|
|
return (
|
|
|
|
<Registration
|
|
|
|
clientSecret={this.state.register_client_secret}
|
|
|
|
sessionId={this.state.register_session_id}
|
|
|
|
idSid={this.state.register_id_sid}
|
2015-12-17 17:56:55 +03:00
|
|
|
email={this.props.startingQueryParams.email}
|
2016-01-07 20:23:32 +03:00
|
|
|
username={this.state.upgradeUsername}
|
|
|
|
disableUsernameChanges={Boolean(this.state.upgradeUsername)}
|
|
|
|
guestAccessToken={this.state.guestAccessToken}
|
2015-12-01 18:36:40 +03:00
|
|
|
hsUrl={this.props.config.default_hs_url}
|
|
|
|
isUrl={this.props.config.default_is_url}
|
2015-11-30 21:11:04 +03:00
|
|
|
registrationUrl={this.props.registrationUrl}
|
|
|
|
onLoggedIn={this.onRegistered}
|
|
|
|
onLoginClick={this.onLoginClick} />
|
|
|
|
);
|
2016-01-12 20:20:16 +03:00
|
|
|
} else if (this.state.screen == 'forgot_password') {
|
|
|
|
return (
|
|
|
|
<ForgotPassword
|
|
|
|
homeserverUrl={this.props.config.default_hs_url}
|
|
|
|
identityServerUrl={this.props.config.default_is_url}
|
|
|
|
onComplete={this.onLoginClick} />
|
|
|
|
);
|
2015-11-30 21:11:04 +03:00
|
|
|
} else {
|
|
|
|
return (
|
|
|
|
<Login
|
|
|
|
onLoggedIn={this.onLoggedIn}
|
|
|
|
onRegisterClick={this.onRegisterClick}
|
2015-12-01 18:36:40 +03:00
|
|
|
homeserverUrl={this.props.config.default_hs_url}
|
2016-01-12 20:20:16 +03:00
|
|
|
identityServerUrl={this.props.config.default_is_url}
|
2016-02-15 21:44:13 +03:00
|
|
|
onForgotPasswordClick={this.onForgotPasswordClick}
|
|
|
|
onLoginAsGuestClick={this.props.enableGuest && this.props.config && this.props.config.default_hs_url ? this._registerAsGuest: undefined}
|
|
|
|
/>
|
2015-11-30 21:11:04 +03:00
|
|
|
);
|
|
|
|
}
|
2015-06-25 19:41:55 +03:00
|
|
|
}
|
2015-11-30 21:11:04 +03:00
|
|
|
});
|