2015-06-23 15:41:25 +00:00
|
|
|
/*
|
2016-01-07 04:06:39 +00:00
|
|
|
Copyright 2015, 2016 OpenMarket Ltd
|
2015-06-23 15:41:25 +00: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.
|
|
|
|
*/
|
2016-09-01 10:08:40 +00:00
|
|
|
|
|
|
|
import q from 'q';
|
|
|
|
|
2015-11-30 18:11:04 +00:00
|
|
|
var React = require('react');
|
|
|
|
var Matrix = require("matrix-js-sdk");
|
2015-06-23 15:41:25 +00:00
|
|
|
|
2015-07-02 12:18:03 +00:00
|
|
|
var MatrixClientPeg = require("../../MatrixClientPeg");
|
2016-11-02 15:10:21 +00:00
|
|
|
var PlatformPeg = require("../../PlatformPeg");
|
2016-05-06 13:19:56 +00:00
|
|
|
var SdkConfig = require("../../SdkConfig");
|
2016-07-27 13:49:10 +00:00
|
|
|
var ContextualMenu = require("./ContextualMenu");
|
2015-07-08 17:18:03 +00:00
|
|
|
var RoomListSorter = require("../../RoomListSorter");
|
2015-10-26 13:54:54 +00:00
|
|
|
var UserActivity = require("../../UserActivity");
|
2015-09-18 17:39:16 +00:00
|
|
|
var Presence = require("../../Presence");
|
2015-06-19 11:53:48 +00:00
|
|
|
var dis = require("../../dispatcher");
|
2015-06-09 16:40:42 +00:00
|
|
|
|
2015-11-30 18:11:04 +00:00
|
|
|
var Login = require("./login/Login");
|
|
|
|
var Registration = require("./login/Registration");
|
|
|
|
var PostRegistration = require("./login/PostRegistration");
|
|
|
|
|
2015-12-13 13:49:28 +00:00
|
|
|
var Modal = require("../../Modal");
|
2016-01-08 03:22:38 +00:00
|
|
|
var Tinter = require("../../Tinter");
|
2015-09-15 12:34:36 +00:00
|
|
|
var sdk = require('../../index');
|
2016-09-07 10:33:58 +00:00
|
|
|
var Rooms = require('../../Rooms');
|
2015-10-27 09:58:55 +00:00
|
|
|
var linkifyMatrix = require("../../linkify-matrix");
|
2016-08-02 13:04:20 +00:00
|
|
|
var Lifecycle = require('../../Lifecycle');
|
2016-11-03 18:42:26 +00:00
|
|
|
var PageTypes = require('../../PageTypes');
|
2015-07-03 10:12:54 +00:00
|
|
|
|
2016-06-08 22:03:46 +00:00
|
|
|
var createRoom = require("../../createRoom");
|
|
|
|
|
2015-11-30 18:11:04 +00:00
|
|
|
module.exports = React.createClass({
|
|
|
|
displayName: 'MatrixChat',
|
|
|
|
|
|
|
|
propTypes: {
|
2016-06-08 17:45:46 +00:00
|
|
|
config: React.PropTypes.object,
|
2015-11-30 18:11:04 +00:00
|
|
|
ConferenceHandler: React.PropTypes.any,
|
|
|
|
onNewScreen: React.PropTypes.func,
|
2015-12-17 14:56:55 +00:00
|
|
|
registrationUrl: React.PropTypes.string,
|
2016-01-05 11:39:36 +00:00
|
|
|
enableGuest: React.PropTypes.bool,
|
2016-08-11 10:00:15 +00:00
|
|
|
|
|
|
|
// the queryParams extracted from the [real] query-string of the URI
|
|
|
|
realQueryParams: React.PropTypes.object,
|
|
|
|
|
|
|
|
// the initial queryParams extracted from the hash-fragment of the URI
|
|
|
|
startingFragmentQueryParams: React.PropTypes.object,
|
|
|
|
|
|
|
|
// called when the session load completes
|
|
|
|
onLoadCompleted: React.PropTypes.func,
|
2016-08-12 10:41:06 +00:00
|
|
|
|
|
|
|
// displayname, if any, to set on the device when logging
|
|
|
|
// in/registering.
|
|
|
|
defaultDeviceDisplayName: React.PropTypes.string,
|
2015-11-30 18:11:04 +00:00
|
|
|
},
|
2015-10-12 09:13:01 +00:00
|
|
|
|
2016-12-02 14:21:07 +00:00
|
|
|
childContextTypes: {
|
|
|
|
appConfig: React.PropTypes.object,
|
|
|
|
},
|
|
|
|
|
2015-09-18 17:39:16 +00:00
|
|
|
AuxPanel: {
|
|
|
|
RoomSettings: "room_settings",
|
|
|
|
},
|
|
|
|
|
2016-12-02 14:21:07 +00:00
|
|
|
getChildContext: function() {
|
|
|
|
return {
|
|
|
|
appConfig: this.props.config,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2015-06-11 17:25:29 +00:00
|
|
|
getInitialState: function() {
|
2015-09-18 17:39:16 +00:00
|
|
|
var s = {
|
2016-08-09 23:03:29 +00:00
|
|
|
loading: true,
|
|
|
|
screen: undefined,
|
|
|
|
|
2016-11-24 12:33:31 +00:00
|
|
|
// What the LoggedInView would be showing if visible
|
2016-11-24 16:39:48 +00:00
|
|
|
page_type: null,
|
2016-11-24 12:33:31 +00:00
|
|
|
|
2016-06-14 13:10:49 +00:00
|
|
|
// If we are viewing a room by alias, this contains the alias
|
|
|
|
currentRoomAlias: null,
|
|
|
|
|
|
|
|
// The ID of the room we're viewing. This is either populated directly
|
|
|
|
// in the case where we view a room by ID or by RoomView when it resolves
|
|
|
|
// what ID an alias points at.
|
|
|
|
currentRoomId: null,
|
2016-08-28 13:04:02 +00:00
|
|
|
|
|
|
|
// If we're trying to just view a user ID (i.e. /user URL), this is it
|
|
|
|
viewUserId: null,
|
|
|
|
|
2016-08-09 23:03:29 +00:00
|
|
|
logged_in: false,
|
2015-10-11 12:49:44 +00:00
|
|
|
collapse_lhs: false,
|
2015-10-11 15:07:01 +00:00
|
|
|
collapse_rhs: false,
|
2015-09-18 17:39:16 +00:00
|
|
|
ready: false,
|
2016-01-17 03:59:31 +00:00
|
|
|
width: 10000,
|
2016-04-12 16:18:32 +00:00
|
|
|
sideOpacity: 1.0,
|
|
|
|
middleOpacity: 1.0,
|
2016-08-15 22:01:02 +00:00
|
|
|
|
|
|
|
version: null,
|
|
|
|
newVersion: null,
|
2016-11-02 15:58:17 +00:00
|
|
|
hasNewVersion: false,
|
|
|
|
newVersionReleaseNotes: null,
|
2016-09-29 16:23:07 +00:00
|
|
|
|
2016-09-30 10:37:50 +00:00
|
|
|
// The username to default to when upgrading an account from a guest
|
2016-09-29 16:23:07 +00:00
|
|
|
upgradeUsername: null,
|
2016-09-30 10:37:50 +00:00
|
|
|
// The access token we had for our guest account, used when upgrading to a normal account
|
2016-09-29 16:23:07 +00:00
|
|
|
guestAccessToken: null,
|
2016-09-30 10:40:27 +00:00
|
|
|
|
|
|
|
// Parameters used in the registration dance with the IS
|
|
|
|
register_client_secret: null,
|
|
|
|
register_session_id: null,
|
|
|
|
register_hs_url: null,
|
|
|
|
register_is_url: null,
|
|
|
|
register_id_sid: null,
|
2015-06-11 17:25:29 +00:00
|
|
|
};
|
2015-09-18 17:39:16 +00:00
|
|
|
return s;
|
2015-06-11 17:25:29 +00:00
|
|
|
},
|
|
|
|
|
2015-12-17 14:56:55 +00:00
|
|
|
getDefaultProps: function() {
|
|
|
|
return {
|
2016-08-11 10:00:15 +00:00
|
|
|
realQueryParams: {},
|
|
|
|
startingFragmentQueryParams: {},
|
2016-06-08 17:45:46 +00:00
|
|
|
config: {},
|
2016-08-11 10:00:15 +00:00
|
|
|
onLoadCompleted: () => {},
|
2015-12-17 14:56:55 +00:00
|
|
|
};
|
|
|
|
},
|
|
|
|
|
2016-03-06 19:33:36 +00:00
|
|
|
getCurrentHsUrl: function() {
|
2016-03-17 11:33:25 +00:00
|
|
|
if (this.state.register_hs_url) {
|
|
|
|
return this.state.register_hs_url;
|
|
|
|
} else if (MatrixClientPeg.get()) {
|
2016-03-06 19:33:36 +00:00
|
|
|
return MatrixClientPeg.get().getHomeserverUrl();
|
|
|
|
}
|
|
|
|
else if (window.localStorage && window.localStorage.getItem("mx_hs_url")) {
|
|
|
|
return window.localStorage.getItem("mx_hs_url");
|
|
|
|
}
|
2016-06-09 08:53:37 +00:00
|
|
|
else {
|
2016-06-21 10:05:37 +00:00
|
|
|
return this.getDefaultHsUrl();
|
2016-03-06 19:33:36 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-06-21 10:05:37 +00:00
|
|
|
getDefaultHsUrl() {
|
|
|
|
return this.props.config.default_hs_url || "https://matrix.org";
|
|
|
|
},
|
|
|
|
|
2016-05-27 13:57:43 +00:00
|
|
|
getFallbackHsUrl: function() {
|
|
|
|
return this.props.config.fallback_hs_url;
|
|
|
|
},
|
|
|
|
|
2016-03-06 19:33:36 +00:00
|
|
|
getCurrentIsUrl: function() {
|
2016-03-17 11:33:25 +00:00
|
|
|
if (this.state.register_is_url) {
|
|
|
|
return this.state.register_is_url;
|
|
|
|
} else if (MatrixClientPeg.get()) {
|
2016-03-06 19:33:36 +00:00
|
|
|
return MatrixClientPeg.get().getIdentityServerUrl();
|
|
|
|
}
|
|
|
|
else if (window.localStorage && window.localStorage.getItem("mx_is_url")) {
|
|
|
|
return window.localStorage.getItem("mx_is_url");
|
|
|
|
}
|
2016-06-09 08:53:37 +00:00
|
|
|
else {
|
2016-06-21 10:05:37 +00:00
|
|
|
return this.getDefaultIsUrl();
|
2016-03-06 19:33:36 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-06-21 10:05:37 +00:00
|
|
|
getDefaultIsUrl() {
|
|
|
|
return this.props.config.default_is_url || "https://vector.im";
|
|
|
|
},
|
|
|
|
|
2015-12-21 12:55:13 +00:00
|
|
|
componentWillMount: function() {
|
2016-05-06 13:19:56 +00:00
|
|
|
SdkConfig.put(this.props.config);
|
2016-08-02 17:46:43 +00:00
|
|
|
|
|
|
|
// Stashed guest credentials if the user logs out
|
|
|
|
// whilst logged in as a guest user (so they can change
|
|
|
|
// their mind & log back in)
|
2016-08-02 13:04:20 +00:00
|
|
|
this.guestCreds = null;
|
2016-08-03 08:53:02 +00:00
|
|
|
|
2016-09-01 10:08:40 +00:00
|
|
|
// if the automatic session load failed, the error
|
|
|
|
this.sessionLoadError = null;
|
|
|
|
|
2016-08-03 08:53:02 +00:00
|
|
|
if (this.props.config.sync_timeline_limit) {
|
|
|
|
MatrixClientPeg.opts.initialSyncLimit = this.props.config.sync_timeline_limit;
|
|
|
|
}
|
2015-12-21 12:55:13 +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);
|
2016-08-10 10:33:58 +00:00
|
|
|
|
2015-06-18 14:03:57 +00:00
|
|
|
this.focusComposer = false;
|
2015-07-07 12:30:38 +00:00
|
|
|
window.addEventListener("focus", this.onFocus);
|
2015-12-04 11:34:50 +00:00
|
|
|
|
2015-10-27 09:58:55 +00:00
|
|
|
// this can technically be done anywhere but doing this here keeps all
|
|
|
|
// the routing url path logic together.
|
2016-08-28 01:05:23 +00:00
|
|
|
if (this.onAliasClick) {
|
|
|
|
linkifyMatrix.onAliasClick = this.onAliasClick;
|
|
|
|
}
|
|
|
|
if (this.onUserClick) {
|
|
|
|
linkifyMatrix.onUserClick = this.onUserClick;
|
|
|
|
}
|
2015-11-30 18:11:04 +00:00
|
|
|
|
|
|
|
window.addEventListener('resize', this.handleResize);
|
|
|
|
this.handleResize();
|
2016-08-10 10:33:58 +00:00
|
|
|
|
2016-09-01 21:45:09 +00:00
|
|
|
// the extra q() ensures that synchronous exceptions hit the same codepath as
|
|
|
|
// asynchronous ones.
|
2016-09-01 10:08:40 +00:00
|
|
|
q().then(() => {
|
|
|
|
return Lifecycle.loadSession({
|
|
|
|
realQueryParams: this.props.realQueryParams,
|
|
|
|
fragmentQueryParams: this.props.startingFragmentQueryParams,
|
|
|
|
enableGuest: this.props.enableGuest,
|
|
|
|
guestHsUrl: this.getCurrentHsUrl(),
|
|
|
|
guestIsUrl: this.getCurrentIsUrl(),
|
|
|
|
defaultDeviceDisplayName: this.props.defaultDeviceDisplayName,
|
|
|
|
});
|
|
|
|
}).catch((e) => {
|
|
|
|
console.error("Unable to load session", e);
|
|
|
|
this.sessionLoadError = e.message;
|
2016-08-10 10:33:58 +00:00
|
|
|
}).done(()=>{
|
|
|
|
// stuff this through the dispatcher so that it happens
|
|
|
|
// after the on_logged_in action.
|
|
|
|
dis.dispatch({action: 'load_completed'});
|
|
|
|
});
|
2015-06-12 13:59:33 +00:00
|
|
|
},
|
|
|
|
|
2015-06-12 16:34:17 +00:00
|
|
|
componentWillUnmount: function() {
|
2016-08-11 12:50:38 +00:00
|
|
|
Lifecycle.stopMatrixClient();
|
2015-06-12 16:34:17 +00:00
|
|
|
dis.unregister(this.dispatcherRef);
|
2015-09-18 17:39:16 +00:00
|
|
|
window.removeEventListener("focus", this.onFocus);
|
2015-11-30 18:11:04 +00:00
|
|
|
window.removeEventListener('resize', this.handleResize);
|
2015-06-12 16:34:17 +00:00
|
|
|
},
|
|
|
|
|
2015-06-18 14:03:57 +00:00
|
|
|
componentDidUpdate: function() {
|
|
|
|
if (this.focusComposer) {
|
|
|
|
dis.dispatch({action: 'focus_composer'});
|
|
|
|
this.focusComposer = false;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-09-30 10:56:32 +00:00
|
|
|
setStateForNewScreen: function(state) {
|
|
|
|
const newState = {
|
|
|
|
screen: undefined,
|
|
|
|
viewUserId: null,
|
|
|
|
logged_in: false,
|
|
|
|
ready: false,
|
|
|
|
upgradeUsername: null,
|
|
|
|
guestAccessToken: null,
|
|
|
|
};
|
2016-10-01 09:34:21 +00:00
|
|
|
Object.assign(newState, state);
|
2016-09-30 13:05:01 +00:00
|
|
|
this.setState(newState);
|
2016-09-30 10:56:32 +00:00
|
|
|
},
|
|
|
|
|
2015-06-12 16:34:17 +00:00
|
|
|
onAction: function(payload) {
|
2015-06-25 16:41:55 +00:00
|
|
|
var roomIndexDelta = 1;
|
|
|
|
|
2015-10-05 14:31:08 +00:00
|
|
|
var self = this;
|
2015-06-12 16:34:17 +00:00
|
|
|
switch (payload.action) {
|
|
|
|
case 'logout':
|
2016-03-17 02:09:49 +00:00
|
|
|
if (MatrixClientPeg.get().isGuest()) {
|
2016-08-02 13:04:20 +00:00
|
|
|
this.guestCreds = MatrixClientPeg.getCredentials();
|
2015-07-16 15:12:54 +00:00
|
|
|
}
|
2016-08-02 13:04:20 +00:00
|
|
|
Lifecycle.logout();
|
2015-06-12 16:34:17 +00:00
|
|
|
break;
|
2015-07-13 18:14:02 +00:00
|
|
|
case 'start_registration':
|
2015-07-15 19:33:12 +00: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;
|
|
|
|
}
|
2016-09-30 10:56:32 +00:00
|
|
|
this.setStateForNewScreen(newState);
|
2015-07-15 18:25:36 +00:00
|
|
|
this.notifyNewScreen('register');
|
2015-07-13 18:14:02 +00:00
|
|
|
break;
|
|
|
|
case 'start_login':
|
|
|
|
if (this.state.logged_in) return;
|
2016-09-30 10:56:32 +00:00
|
|
|
this.setStateForNewScreen({
|
2016-03-17 02:09:49 +00:00
|
|
|
screen: 'login',
|
2015-07-13 18:14:02 +00:00
|
|
|
});
|
2015-07-15 18:25:36 +00:00
|
|
|
this.notifyNewScreen('login');
|
2015-10-08 21:25:33 +00:00
|
|
|
break;
|
2015-11-20 11:57:04 +00:00
|
|
|
case 'start_post_registration':
|
|
|
|
this.setState({ // don't clobber logged_in status
|
|
|
|
screen: 'post_registration'
|
|
|
|
});
|
|
|
|
break;
|
2016-01-07 17:23:32 +00:00
|
|
|
case 'start_upgrade_registration':
|
2016-08-02 13:04:20 +00:00
|
|
|
// stash our guest creds so we can backout if needed
|
2016-08-02 17:59:09 +00:00
|
|
|
this.guestCreds = MatrixClientPeg.getCredentials();
|
2016-09-30 10:56:32 +00:00
|
|
|
this.setStateForNewScreen({
|
2016-01-07 17:23:32 +00:00
|
|
|
screen: "register",
|
|
|
|
upgradeUsername: MatrixClientPeg.get().getUserIdLocalpart(),
|
2016-03-15 21:04:11 +00:00
|
|
|
guestAccessToken: MatrixClientPeg.get().getAccessToken(),
|
2016-01-07 17:23:32 +00:00
|
|
|
});
|
|
|
|
this.notifyNewScreen('register');
|
|
|
|
break;
|
2016-01-12 17:20:16 +00:00
|
|
|
case 'start_password_recovery':
|
|
|
|
if (this.state.logged_in) return;
|
2016-09-30 10:56:32 +00:00
|
|
|
this.setStateForNewScreen({
|
2016-09-29 16:23:07 +00:00
|
|
|
screen: 'forgot_password',
|
2016-01-12 17:20:16 +00:00
|
|
|
});
|
|
|
|
this.notifyNewScreen('forgot_password');
|
2015-12-13 13:49:28 +00: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);
|
2016-04-12 16:18:32 +00:00
|
|
|
|
2015-12-13 13:49:28 +00:00
|
|
|
// FIXME: controller shouldn't be loading a view :(
|
|
|
|
var Loader = sdk.getComponent("elements.Spinner");
|
2016-07-17 20:23:52 +00:00
|
|
|
var modal = Modal.createDialog(Loader, null, 'mx_Dialog_spinner');
|
2015-12-13 13:49:28 +00:00
|
|
|
|
|
|
|
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 18:14:02 +00:00
|
|
|
break;
|
2016-09-16 01:37:06 +00:00
|
|
|
case 'view_user':
|
|
|
|
// FIXME: ugly hack to expand the RightPanel and then re-dispatch.
|
|
|
|
if (this.state.collapse_rhs) {
|
|
|
|
setTimeout(()=>{
|
|
|
|
dis.dispatch({
|
|
|
|
action: 'show_right_panel',
|
|
|
|
});
|
|
|
|
dis.dispatch({
|
|
|
|
action: 'view_user',
|
|
|
|
member: payload.member,
|
|
|
|
});
|
|
|
|
}, 0);
|
|
|
|
}
|
|
|
|
break;
|
2015-06-12 17:01:38 +00:00
|
|
|
case 'view_room':
|
2016-06-14 11:56:37 +00:00
|
|
|
// Takes either a room ID or room alias: if switching to a room the client is already
|
|
|
|
// known to be in (eg. user clicks on a room in the recents panel), supply the ID
|
|
|
|
// If the user is clicking on a room in the context of the alias being presented
|
|
|
|
// to them, supply the room alias. If both are supplied, the room ID will be ignored.
|
2016-06-20 15:30:51 +00:00
|
|
|
this._viewRoom(payload);
|
2015-06-12 17:01:38 +00:00
|
|
|
break;
|
2015-06-25 16:41:55 +00:00
|
|
|
case 'view_prev_room':
|
|
|
|
roomIndexDelta = -1;
|
|
|
|
case 'view_next_room':
|
2015-07-08 18:47:58 +00:00
|
|
|
var allRooms = RoomListSorter.mostRecentActivityFirst(
|
|
|
|
MatrixClientPeg.get().getRooms()
|
|
|
|
);
|
2015-06-25 16:41:55 +00:00
|
|
|
var roomIndex = -1;
|
|
|
|
for (var i = 0; i < allRooms.length; ++i) {
|
2016-06-14 10:37:04 +00:00
|
|
|
if (allRooms[i].roomId == this.state.currentRoomId) {
|
2015-06-25 16:41:55 +00:00
|
|
|
roomIndex = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
roomIndex = (roomIndex + roomIndexDelta) % allRooms.length;
|
2015-09-18 17:39:16 +00:00
|
|
|
if (roomIndex < 0) roomIndex = allRooms.length - 1;
|
2016-06-20 17:43:56 +00:00
|
|
|
this._viewRoom({ room_id: allRooms[roomIndex].roomId });
|
2015-09-18 17:39:16 +00:00
|
|
|
break;
|
|
|
|
case 'view_indexed_room':
|
|
|
|
var allRooms = RoomListSorter.mostRecentActivityFirst(
|
|
|
|
MatrixClientPeg.get().getRooms()
|
|
|
|
);
|
|
|
|
var roomIndex = payload.roomIndex;
|
|
|
|
if (allRooms[roomIndex]) {
|
2016-06-20 15:30:51 +00:00
|
|
|
this._viewRoom({ room_id: allRooms[roomIndex].roomId });
|
2015-09-18 17:39:16 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'view_user_settings':
|
2016-11-03 18:42:26 +00:00
|
|
|
this._setPage(PageTypes.UserSettings);
|
2015-11-11 01:01:48 +00:00
|
|
|
this.notifyNewScreen('settings');
|
2015-09-18 17:39:16 +00:00
|
|
|
break;
|
|
|
|
case 'view_create_room':
|
2016-11-03 18:42:26 +00:00
|
|
|
//this._setPage(PageTypes.CreateRoom);
|
2016-01-17 03:59:31 +00:00
|
|
|
//this.notifyNewScreen('new');
|
|
|
|
|
2016-09-13 15:40:15 +00:00
|
|
|
var TextInputDialog = sdk.getComponent("dialogs.TextInputDialog");
|
|
|
|
Modal.createDialog(TextInputDialog, {
|
|
|
|
title: "Create Room",
|
2016-09-13 15:56:53 +00:00
|
|
|
description: "Room name (optional)",
|
2016-09-13 15:40:15 +00:00
|
|
|
button: "Create Room",
|
|
|
|
onFinished: (should_create, name) => {
|
|
|
|
if (should_create) {
|
|
|
|
const createOpts = {};
|
|
|
|
if (name) createOpts.name = name;
|
|
|
|
createRoom({createOpts}).done();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2015-09-18 17:39:16 +00:00
|
|
|
break;
|
|
|
|
case 'view_room_directory':
|
2016-11-03 18:42:26 +00:00
|
|
|
this._setPage(PageTypes.RoomDirectory);
|
2015-11-11 01:01:48 +00:00
|
|
|
this.notifyNewScreen('directory');
|
2015-09-18 17:39:16 +00:00
|
|
|
break;
|
2016-09-05 09:29:03 +00:00
|
|
|
case 'view_create_chat':
|
|
|
|
this._createChat();
|
2016-09-01 15:45:24 +00:00
|
|
|
break;
|
2016-09-13 13:28:03 +00:00
|
|
|
case 'view_invite':
|
|
|
|
this._invite(payload.roomId);
|
|
|
|
break;
|
2015-09-18 17:39:16 +00:00
|
|
|
case 'notifier_enabled':
|
|
|
|
this.forceUpdate();
|
2015-06-25 16:41:55 +00:00
|
|
|
break;
|
2015-10-11 12:49:44 +00:00
|
|
|
case 'hide_left_panel':
|
|
|
|
this.setState({
|
|
|
|
collapse_lhs: true,
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
case 'show_left_panel':
|
|
|
|
this.setState({
|
|
|
|
collapse_lhs: false,
|
|
|
|
});
|
|
|
|
break;
|
2015-10-11 15:07:01 +00:00
|
|
|
case 'hide_right_panel':
|
|
|
|
this.setState({
|
|
|
|
collapse_rhs: true,
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
case 'show_right_panel':
|
|
|
|
this.setState({
|
|
|
|
collapse_rhs: false,
|
|
|
|
});
|
|
|
|
break;
|
2016-04-12 16:18:32 +00:00
|
|
|
case 'ui_opacity':
|
|
|
|
this.setState({
|
|
|
|
sideOpacity: payload.sideOpacity,
|
|
|
|
middleOpacity: payload.middleOpacity,
|
|
|
|
});
|
|
|
|
break;
|
2016-08-02 13:04:20 +00:00
|
|
|
case 'on_logged_in':
|
|
|
|
this._onLoggedIn();
|
|
|
|
break;
|
|
|
|
case 'on_logged_out':
|
|
|
|
this._onLoggedOut();
|
|
|
|
break;
|
|
|
|
case 'will_start_client':
|
|
|
|
this._onWillStartClient();
|
|
|
|
break;
|
2016-08-09 23:03:29 +00:00
|
|
|
case 'load_completed':
|
|
|
|
this._onLoadCompleted();
|
|
|
|
break;
|
2016-11-02 15:58:17 +00:00
|
|
|
case 'new_version':
|
|
|
|
this.onVersion(
|
|
|
|
payload.currentVersion, payload.newVersion,
|
|
|
|
payload.releaseNotes
|
|
|
|
);
|
|
|
|
break;
|
2015-06-12 16:34:17 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2015-12-10 21:53:14 +00:00
|
|
|
_setPage: function(pageType) {
|
|
|
|
this.setState({
|
2015-12-14 11:07:59 +00:00
|
|
|
page_type: pageType,
|
2015-12-10 21:53:14 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2016-02-01 16:31:12 +00:00
|
|
|
// switch view to the given room
|
|
|
|
//
|
2016-06-20 15:30:51 +00:00
|
|
|
// @param {Object} room_info Object containing data about the room to be joined
|
2016-06-20 17:05:58 +00:00
|
|
|
// @param {string=} room_info.room_id ID of the room to join. One of room_id or room_alias must be given.
|
|
|
|
// @param {string=} room_info.room_alias Alias of the room to join. One of room_id or room_alias must be given.
|
|
|
|
// @param {boolean=} room_info.auto_join If true, automatically attempt to join the room if not already a member.
|
|
|
|
// @param {boolean=} room_info.show_settings Makes RoomView show the room settings dialog.
|
|
|
|
// @param {string=} room_info.event_id ID of the event in this room to show: this will cause a switch to the
|
|
|
|
// context of that particular event.
|
|
|
|
// @param {Object=} room_info.third_party_invite Object containing data about the third party
|
2016-03-17 18:38:25 +00:00
|
|
|
// we received to join the room, if any.
|
2016-06-20 17:05:58 +00:00
|
|
|
// @param {string=} room_info.third_party_invite.inviteSignUrl 3pid invite sign URL
|
|
|
|
// @param {string=} room_info.third_party_invite.invitedEmail The email address the invite was sent to
|
|
|
|
// @param {Object=} room_info.oob_data Object of additional data about the room
|
2016-03-01 18:23:57 +00:00
|
|
|
// that has been passed out-of-band (eg.
|
|
|
|
// room name and avatar from an invite email)
|
2016-06-20 15:30:51 +00:00
|
|
|
_viewRoom: function(room_info) {
|
2015-12-10 16:26:36 +00:00
|
|
|
this.focusComposer = true;
|
2016-02-01 16:31:12 +00:00
|
|
|
|
2015-12-10 16:26:36 +00:00
|
|
|
var newState = {
|
2016-06-20 15:30:51 +00:00
|
|
|
initialEventId: room_info.event_id,
|
|
|
|
highlightedEventId: room_info.event_id,
|
2016-02-01 16:31:12 +00:00
|
|
|
initialEventPixelOffset: undefined,
|
2016-11-03 18:42:26 +00:00
|
|
|
page_type: PageTypes.RoomView,
|
2016-06-20 15:30:51 +00:00
|
|
|
thirdPartyInvite: room_info.third_party_invite,
|
|
|
|
roomOobData: room_info.oob_data,
|
|
|
|
currentRoomAlias: room_info.room_alias,
|
|
|
|
autoJoin: room_info.auto_join,
|
2015-12-10 16:26:36 +00:00
|
|
|
};
|
2016-02-01 16:31:12 +00:00
|
|
|
|
2016-06-20 15:30:51 +00:00
|
|
|
if (!room_info.room_alias) {
|
|
|
|
newState.currentRoomId = room_info.room_id;
|
2016-06-14 11:56:37 +00:00
|
|
|
}
|
|
|
|
|
2016-02-01 16:31:12 +00:00
|
|
|
// if we aren't given an explicit event id, look for one in the
|
|
|
|
// scrollStateMap.
|
2016-11-04 09:28:35 +00:00
|
|
|
//
|
|
|
|
// TODO: do this in RoomView rather than here
|
2016-11-03 18:42:26 +00:00
|
|
|
if (!room_info.event_id && this.refs.loggedInView) {
|
|
|
|
var scrollState = this.refs.loggedInView.getScrollStateForRoom(room_info.room_id);
|
2016-02-01 16:31:12 +00:00
|
|
|
if (scrollState) {
|
|
|
|
newState.initialEventId = scrollState.focussedEvent;
|
|
|
|
newState.initialEventPixelOffset = scrollState.pixelOffset;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-10 16:26:36 +00: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.
|
2016-06-20 15:30:51 +00:00
|
|
|
var presentedId = room_info.room_alias || room_info.room_id;
|
|
|
|
var room = MatrixClientPeg.get().getRoom(room_info.room_id);
|
2015-12-10 16:26:36 +00:00
|
|
|
if (room) {
|
2016-09-07 10:33:58 +00:00
|
|
|
var theAlias = Rooms.getDisplayAliasForRoom(room);
|
2015-12-10 16:26:36 +00:00
|
|
|
if (theAlias) presentedId = theAlias;
|
2016-01-08 03:22:38 +00:00
|
|
|
|
2016-04-16 00:00:10 +00:00
|
|
|
// No need to do this given RoomView triggers it itself...
|
|
|
|
// var color_scheme_event = room.getAccountData("org.matrix.room.color_scheme");
|
|
|
|
// var color_scheme = {};
|
|
|
|
// if (color_scheme_event) {
|
|
|
|
// color_scheme = color_scheme_event.getContent();
|
|
|
|
// // XXX: we should validate the event
|
|
|
|
// }
|
|
|
|
// console.log("Tinter.tint from _viewRoom");
|
|
|
|
// Tinter.tint(color_scheme.primary_color, color_scheme.secondary_color);
|
2015-12-10 16:26:36 +00:00
|
|
|
}
|
2016-01-08 03:22:38 +00:00
|
|
|
|
2016-06-20 15:30:51 +00:00
|
|
|
if (room_info.event_id) {
|
2016-06-20 17:05:58 +00:00
|
|
|
presentedId += "/"+room_info.event_id;
|
2016-02-01 16:31:12 +00:00
|
|
|
}
|
2015-12-10 16:26:36 +00:00
|
|
|
this.notifyNewScreen('room/'+presentedId);
|
|
|
|
newState.ready = true;
|
|
|
|
}
|
|
|
|
this.setState(newState);
|
|
|
|
},
|
|
|
|
|
2016-09-05 09:29:03 +00:00
|
|
|
_createChat: function() {
|
2016-09-05 11:03:16 +00:00
|
|
|
var ChatInviteDialog = sdk.getComponent("dialogs.ChatInviteDialog");
|
|
|
|
Modal.createDialog(ChatInviteDialog, {
|
2016-09-13 09:33:15 +00:00
|
|
|
title: "Start a new chat",
|
2016-09-01 15:45:24 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2016-09-13 13:30:37 +00:00
|
|
|
_invite: function(roomId) {
|
2016-09-13 13:28:03 +00:00
|
|
|
var ChatInviteDialog = sdk.getComponent("dialogs.ChatInviteDialog");
|
|
|
|
Modal.createDialog(ChatInviteDialog, {
|
|
|
|
title: "Invite new room members",
|
|
|
|
button: "Send Invites",
|
2016-09-13 13:30:37 +00:00
|
|
|
description: "Who would you like to add to this room?",
|
|
|
|
roomId: roomId,
|
2016-09-01 15:45:24 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2016-08-09 23:03:29 +00:00
|
|
|
/**
|
|
|
|
* Called when the sessionloader has finished
|
|
|
|
*/
|
|
|
|
_onLoadCompleted: function() {
|
2016-08-11 10:00:15 +00:00
|
|
|
this.props.onLoadCompleted();
|
2016-08-09 23:03:29 +00:00
|
|
|
this.setState({loading: false});
|
|
|
|
},
|
|
|
|
|
2016-08-02 18:05:05 +00:00
|
|
|
/**
|
|
|
|
* Called when a new logged in session has started
|
|
|
|
*/
|
2016-08-02 13:04:20 +00:00
|
|
|
_onLoggedIn: function(credentials) {
|
|
|
|
this.guestCreds = null;
|
2016-08-03 08:57:12 +00:00
|
|
|
this.notifyNewScreen('');
|
2015-07-13 18:14:02 +00:00
|
|
|
this.setState({
|
2015-07-15 18:25:36 +00:00
|
|
|
screen: undefined,
|
2016-08-02 13:04:20 +00:00
|
|
|
logged_in: true,
|
2015-07-13 18:14:02 +00:00
|
|
|
});
|
2015-06-12 13:59:33 +00:00
|
|
|
},
|
|
|
|
|
2016-08-02 18:05:05 +00:00
|
|
|
/**
|
|
|
|
* Called when the session is logged out
|
|
|
|
*/
|
2016-08-02 13:04:20 +00:00
|
|
|
_onLoggedOut: function() {
|
|
|
|
this.notifyNewScreen('login');
|
2016-09-30 10:56:32 +00:00
|
|
|
this.setStateForNewScreen({
|
2016-08-02 13:04:20 +00:00
|
|
|
logged_in: false,
|
|
|
|
ready: false,
|
2016-09-29 16:23:07 +00:00
|
|
|
collapse_lhs: false,
|
|
|
|
collapse_rhs: false,
|
2016-11-24 14:58:37 +00:00
|
|
|
currentRoomAlias: null,
|
|
|
|
currentRoomId: null,
|
|
|
|
page_type: PageTypes.RoomDirectory,
|
2016-08-02 13:04:20 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2016-08-02 18:05:05 +00:00
|
|
|
/**
|
|
|
|
* Called just before the matrix client is started
|
2016-08-03 08:53:02 +00:00
|
|
|
* (useful for setting listeners)
|
2016-08-02 18:05:05 +00:00
|
|
|
*/
|
2016-08-02 13:04:20 +00:00
|
|
|
_onWillStartClient() {
|
2015-07-02 12:18:03 +00:00
|
|
|
var cli = MatrixClientPeg.get();
|
2016-08-02 13:04:20 +00:00
|
|
|
|
2015-09-15 12:34:36 +00:00
|
|
|
var self = this;
|
2015-12-15 14:23:58 +00:00
|
|
|
cli.on('sync', function(state, prevState) {
|
2016-11-02 15:10:21 +00:00
|
|
|
self.updateStatusIndicator(state, prevState);
|
2015-12-15 14:23:58 +00:00
|
|
|
if (state === "SYNCING" && prevState === "SYNCING") {
|
|
|
|
return;
|
|
|
|
}
|
2015-11-12 15:15:00 +00:00
|
|
|
console.log("MatrixClient sync state => %s", state);
|
|
|
|
if (state !== "PREPARED") { return; }
|
2015-09-18 17:39:16 +00:00
|
|
|
self.sdkReady = true;
|
2015-09-25 16:22:42 +00:00
|
|
|
|
2016-03-04 17:37:06 +00:00
|
|
|
if (self.starting_room_alias_payload) {
|
|
|
|
dis.dispatch(self.starting_room_alias_payload);
|
|
|
|
delete self.starting_room_alias_payload;
|
2015-11-11 01:32:16 +00:00
|
|
|
} else if (!self.state.page_type) {
|
2016-06-14 10:37:04 +00:00
|
|
|
if (!self.state.currentRoomId) {
|
2015-09-25 16:22:42 +00:00
|
|
|
var firstRoom = null;
|
|
|
|
if (cli.getRooms() && cli.getRooms().length) {
|
|
|
|
firstRoom = RoomListSorter.mostRecentActivityFirst(
|
|
|
|
cli.getRooms()
|
|
|
|
)[0].roomId;
|
2016-11-03 18:42:26 +00:00
|
|
|
self.setState({ready: true, currentRoomId: firstRoom, page_type: PageTypes.RoomView});
|
2015-09-25 16:22:42 +00:00
|
|
|
} else {
|
2016-11-03 18:42:26 +00:00
|
|
|
self.setState({ready: true, page_type: PageTypes.RoomDirectory});
|
2015-09-25 16:22:42 +00:00
|
|
|
}
|
|
|
|
} else {
|
2016-11-03 18:42:26 +00:00
|
|
|
self.setState({ready: true, page_type: PageTypes.RoomView});
|
2015-09-25 16:22:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// we notifyNewScreen now because now the room will actually be displayed,
|
|
|
|
// and (mostly) now we can get the correct alias.
|
2016-06-14 10:37:04 +00:00
|
|
|
var presentedId = self.state.currentRoomId;
|
|
|
|
var room = MatrixClientPeg.get().getRoom(self.state.currentRoomId);
|
2015-09-25 16:22:42 +00:00
|
|
|
if (room) {
|
2016-09-07 10:33:58 +00:00
|
|
|
var theAlias = Rooms.getDisplayAliasForRoom(room);
|
2015-09-25 16:22:42 +00:00
|
|
|
if (theAlias) presentedId = theAlias;
|
|
|
|
}
|
2016-03-05 18:06:24 +00:00
|
|
|
|
2016-03-07 15:46:35 +00:00
|
|
|
if (presentedId != undefined) {
|
2016-03-05 18:06:24 +00:00
|
|
|
self.notifyNewScreen('room/'+presentedId);
|
|
|
|
} else {
|
|
|
|
// There is no information on presentedId
|
|
|
|
// so point user to fallback like /directory
|
|
|
|
self.notifyNewScreen('directory');
|
|
|
|
}
|
|
|
|
|
2015-09-25 16:22:42 +00:00
|
|
|
dis.dispatch({action: 'focus_composer'});
|
2015-11-11 01:32:16 +00:00
|
|
|
} else {
|
|
|
|
self.setState({ready: true});
|
2015-10-05 14:31:08 +00:00
|
|
|
}
|
2015-06-12 13:59:33 +00:00
|
|
|
});
|
2015-09-18 17:39:16 +00:00
|
|
|
cli.on('Call.incoming', function(call) {
|
|
|
|
dis.dispatch({
|
|
|
|
action: 'incoming_call',
|
|
|
|
call: call
|
|
|
|
});
|
|
|
|
});
|
2016-03-15 10:48:16 +00:00
|
|
|
cli.on('Session.logged_out', function(call) {
|
|
|
|
var ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
|
|
|
|
Modal.createDialog(ErrorDialog, {
|
2016-09-29 16:38:52 +00:00
|
|
|
title: "Signed Out",
|
|
|
|
description: "For security, this session has been signed out. Please sign in again."
|
2016-03-15 10:48:16 +00:00
|
|
|
});
|
|
|
|
dis.dispatch({
|
|
|
|
action: 'logout'
|
|
|
|
});
|
|
|
|
});
|
2015-06-11 17:25:29 +00:00
|
|
|
},
|
2015-06-25 16:41:55 +00:00
|
|
|
|
2015-07-07 12:30:38 +00:00
|
|
|
onFocus: function(ev) {
|
|
|
|
dis.dispatch({action: 'focus_composer'});
|
2015-07-15 18:25:36 +00:00
|
|
|
},
|
|
|
|
|
2015-07-16 11:44:04 +00:00
|
|
|
showScreen: function(screen, params) {
|
2015-07-15 19:33:12 +00:00
|
|
|
if (screen == 'register') {
|
|
|
|
dis.dispatch({
|
|
|
|
action: 'start_registration',
|
|
|
|
params: params
|
|
|
|
});
|
|
|
|
} else if (screen == 'login') {
|
|
|
|
dis.dispatch({
|
|
|
|
action: 'start_login',
|
|
|
|
params: params
|
|
|
|
});
|
2016-01-12 17:20:16 +00:00
|
|
|
} else if (screen == 'forgot_password') {
|
|
|
|
dis.dispatch({
|
|
|
|
action: 'start_password_recovery',
|
|
|
|
params: params
|
|
|
|
});
|
2015-11-11 01:01:48 +00: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 11:57:04 +00:00
|
|
|
} else if (screen == 'post_registration') {
|
|
|
|
dis.dispatch({
|
|
|
|
action: 'start_post_registration',
|
|
|
|
});
|
2015-09-18 17:39:16 +00:00
|
|
|
} else if (screen.indexOf('room/') == 0) {
|
2016-02-03 08:03:10 +00:00
|
|
|
var segments = screen.substring(5).split('/');
|
|
|
|
var roomString = segments[0];
|
|
|
|
var eventId = segments[1]; // undefined if no event id given
|
2016-03-01 18:23:57 +00:00
|
|
|
|
2016-03-17 18:38:25 +00:00
|
|
|
// FIXME: sort_out caseConsistency
|
|
|
|
var third_party_invite = {
|
|
|
|
inviteSignUrl: params.signurl,
|
|
|
|
invitedEmail: params.email,
|
|
|
|
};
|
2016-03-01 18:23:57 +00:00
|
|
|
var oob_data = {
|
|
|
|
name: params.room_name,
|
|
|
|
avatarUrl: params.room_avatar_url,
|
|
|
|
inviterName: params.inviter_name,
|
|
|
|
};
|
|
|
|
|
2016-06-10 14:12:42 +00:00
|
|
|
var payload = {
|
|
|
|
action: 'view_room',
|
|
|
|
event_id: eventId,
|
|
|
|
third_party_invite: third_party_invite,
|
|
|
|
oob_data: oob_data,
|
|
|
|
};
|
2015-09-18 17:39:16 +00:00
|
|
|
if (roomString[0] == '#') {
|
2016-06-10 14:12:42 +00:00
|
|
|
payload.room_alias = roomString;
|
2015-09-18 17:39:16 +00:00
|
|
|
} else {
|
2016-06-10 14:12:42 +00:00
|
|
|
payload.room_id = roomString;
|
2016-06-09 17:49:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// we can't view a room unless we're logged in
|
|
|
|
// (a guest account is fine)
|
|
|
|
if (!this.state.logged_in) {
|
2016-08-10 13:34:44 +00:00
|
|
|
// we may still be loading (ie, trying to register a guest
|
|
|
|
// session); otherwise we're (probably) already showing a login
|
|
|
|
// screen. Either way, we'll show the room once the client starts.
|
2016-06-09 17:49:06 +00:00
|
|
|
this.starting_room_alias_payload = payload;
|
|
|
|
} else {
|
|
|
|
dis.dispatch(payload);
|
2015-09-25 16:22:42 +00:00
|
|
|
}
|
2016-08-28 00:55:42 +00:00
|
|
|
} else if (screen.indexOf('user/') == 0) {
|
|
|
|
var userId = screen.substring(5);
|
2016-08-28 13:04:02 +00:00
|
|
|
this.setState({ viewUserId: userId });
|
2016-11-03 18:42:26 +00:00
|
|
|
this._setPage(PageTypes.UserView);
|
2016-08-28 13:04:02 +00:00
|
|
|
this.notifyNewScreen('user/' + userId);
|
2016-08-28 00:55:42 +00:00
|
|
|
var member = new Matrix.RoomMember(null, userId);
|
|
|
|
if (member) {
|
|
|
|
dis.dispatch({
|
|
|
|
action: 'view_user',
|
|
|
|
member: member,
|
|
|
|
});
|
|
|
|
}
|
2015-07-15 19:33:12 +00:00
|
|
|
}
|
2015-11-20 14:26:49 +00:00
|
|
|
else {
|
2016-03-06 19:33:36 +00:00
|
|
|
console.info("Ignoring showScreen for '%s'", screen);
|
2015-11-20 14:26:49 +00:00
|
|
|
}
|
2015-07-15 18:25:36 +00:00
|
|
|
},
|
|
|
|
|
2015-12-17 15:12:09 +00:00
|
|
|
notifyNewScreen: function(screen) {
|
2015-07-15 18:25:36 +00:00
|
|
|
if (this.props.onNewScreen) {
|
2015-12-17 15:12:09 +00:00
|
|
|
this.props.onNewScreen(screen);
|
2015-07-15 18:25:36 +00:00
|
|
|
}
|
2015-11-30 18:11:04 +00:00
|
|
|
},
|
|
|
|
|
2016-08-28 01:05:23 +00:00
|
|
|
onAliasClick: function(event, alias) {
|
|
|
|
event.preventDefault();
|
|
|
|
dis.dispatch({action: 'view_room', room_alias: alias});
|
|
|
|
},
|
|
|
|
|
|
|
|
onUserClick: function(event, userId) {
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
|
|
// 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
|
|
|
|
// });
|
|
|
|
|
|
|
|
var member = new Matrix.RoomMember(null, userId);
|
|
|
|
if (!member) { return; }
|
|
|
|
dis.dispatch({
|
|
|
|
action: 'view_user',
|
|
|
|
member: member,
|
|
|
|
});
|
|
|
|
},
|
2015-11-30 18:11:04 +00: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 17:20:16 +00:00
|
|
|
onForgotPasswordClick: function() {
|
|
|
|
this.showScreen("forgot_password");
|
|
|
|
},
|
|
|
|
|
2016-03-15 21:04:11 +00:00
|
|
|
onReturnToGuestClick: function() {
|
|
|
|
// reanimate our guest login
|
2016-08-02 13:04:20 +00:00
|
|
|
if (this.guestCreds) {
|
2016-08-02 18:02:07 +00:00
|
|
|
Lifecycle.setLoggedIn(this.guestCreds);
|
2016-08-02 13:04:20 +00:00
|
|
|
this.guestCreds = null;
|
|
|
|
}
|
2016-03-15 21:04:11 +00:00
|
|
|
},
|
|
|
|
|
2015-11-30 18:11:04 +00:00
|
|
|
onRegistered: function(credentials) {
|
2016-08-02 18:02:07 +00:00
|
|
|
Lifecycle.setLoggedIn(credentials);
|
2015-11-30 18:11:04 +00:00
|
|
|
// do post-registration stuff
|
2016-01-15 18:58:18 +00: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 14:23:31 +00: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 18:58:18 +00:00
|
|
|
//this.showScreen("view_user_settings");
|
2016-11-03 18:42:26 +00:00
|
|
|
this._setPage(PageTypes.UserSettings);
|
2015-11-30 18:11:04 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
onFinishPostRegistration: function() {
|
|
|
|
// Don't confuse this with "PageType" which is the middle window to show
|
|
|
|
this.setState({
|
|
|
|
screen: undefined
|
|
|
|
});
|
|
|
|
this.showScreen("settings");
|
|
|
|
},
|
|
|
|
|
2016-11-02 15:58:17 +00:00
|
|
|
onVersion: function(current, latest, releaseNotes) {
|
2016-02-03 16:16:52 +00:00
|
|
|
this.setState({
|
2016-02-03 16:51:53 +00:00
|
|
|
version: current,
|
2016-08-15 22:01:02 +00:00
|
|
|
newVersion: latest,
|
2016-11-02 15:58:17 +00:00
|
|
|
hasNewVersion: current !== latest,
|
|
|
|
newVersionReleaseNotes: releaseNotes,
|
2016-02-03 16:16:52 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2016-11-02 15:10:21 +00:00
|
|
|
updateStatusIndicator: function(state, prevState) {
|
2015-12-21 12:55:13 +00:00
|
|
|
var notifCount = 0;
|
|
|
|
|
|
|
|
var rooms = MatrixClientPeg.get().getRooms();
|
|
|
|
for (var i = 0; i < rooms.length; ++i) {
|
2016-01-13 13:00:03 +00:00
|
|
|
if (rooms[i].hasMembershipState(MatrixClientPeg.get().credentials.userId, 'invite')) {
|
2016-05-17 10:14:12 +00:00
|
|
|
notifCount++;
|
2016-01-21 10:23:18 +00:00
|
|
|
} else if (rooms[i].getUnreadNotificationCount()) {
|
2016-05-17 10:14:12 +00:00
|
|
|
// if we were summing unread notifs:
|
|
|
|
// notifCount += rooms[i].getUnreadNotificationCount();
|
|
|
|
// instead, we just count the number of rooms with notifs.
|
|
|
|
notifCount++;
|
2016-01-07 10:38:44 +00:00
|
|
|
}
|
2015-12-21 12:55:13 +00:00
|
|
|
}
|
2016-03-16 01:02:49 +00:00
|
|
|
|
2016-11-02 15:10:21 +00:00
|
|
|
if (PlatformPeg.get()) {
|
|
|
|
PlatformPeg.get().setErrorStatus(state === 'ERROR');
|
|
|
|
PlatformPeg.get().setNotificationCount(notifCount);
|
2016-01-27 15:19:25 +00:00
|
|
|
}
|
2016-11-02 15:10:21 +00:00
|
|
|
|
2016-09-19 13:47:08 +00:00
|
|
|
document.title = `Riot ${state === "ERROR" ? " [offline]" : ""}${notifCount > 0 ? ` [${notifCount}]` : ""}`;
|
2015-12-21 12:55:13 +00:00
|
|
|
},
|
|
|
|
|
2015-12-23 11:47:56 +00:00
|
|
|
onUserSettingsClose: function() {
|
|
|
|
// XXX: use browser history instead to find the previous room?
|
2016-04-15 21:16:19 +00:00
|
|
|
// or maintain a this.state.pageHistory in _setPage()?
|
2016-06-14 10:37:04 +00:00
|
|
|
if (this.state.currentRoomId) {
|
2015-12-23 11:47:56 +00:00
|
|
|
dis.dispatch({
|
|
|
|
action: 'view_room',
|
2016-06-14 10:37:04 +00:00
|
|
|
room_id: this.state.currentRoomId,
|
2015-12-23 11:47:56 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
dis.dispatch({
|
2016-05-05 14:30:56 +00:00
|
|
|
action: 'view_room_directory',
|
2015-12-23 11:47:56 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-06-14 11:56:37 +00:00
|
|
|
onRoomIdResolved: function(room_id) {
|
|
|
|
// It's the RoomView's resposibility to look up room aliases, but we need the
|
|
|
|
// ID to pass into things like the Member List, so the Room View tells us when
|
|
|
|
// its done that resolution so we can display things that take a room ID.
|
|
|
|
this.setState({currentRoomId: room_id});
|
|
|
|
},
|
|
|
|
|
2015-11-30 18:11:04 +00:00
|
|
|
render: function() {
|
2016-01-12 17:20:16 +00:00
|
|
|
var ForgotPassword = sdk.getComponent('structures.login.ForgotPassword');
|
2016-11-03 18:42:26 +00:00
|
|
|
var LoggedInView = sdk.getComponent('structures.LoggedInView');
|
2015-11-30 18:11:04 +00:00
|
|
|
|
2016-08-11 12:50:38 +00:00
|
|
|
// console.log("rendering; loading="+this.state.loading+"; screen="+this.state.screen +
|
|
|
|
// "; logged_in="+this.state.logged_in+"; ready="+this.state.ready);
|
2016-08-09 23:03:29 +00:00
|
|
|
|
|
|
|
if (this.state.loading) {
|
2016-08-10 10:33:58 +00:00
|
|
|
var Spinner = sdk.getComponent('elements.Spinner');
|
2016-08-09 23:03:29 +00:00
|
|
|
return (
|
2016-08-10 10:33:58 +00:00
|
|
|
<div className="mx_MatrixChat_splash">
|
|
|
|
<Spinner />
|
|
|
|
</div>
|
2016-08-09 23:03:29 +00:00
|
|
|
);
|
|
|
|
}
|
2015-11-30 18:11:04 +00:00
|
|
|
// needs to be before normal PageTypes as you are logged in technically
|
2016-08-09 23:03:29 +00:00
|
|
|
else if (this.state.screen == 'post_registration') {
|
2015-11-30 18:11:04 +00:00
|
|
|
return (
|
|
|
|
<PostRegistration
|
|
|
|
onComplete={this.onFinishPostRegistration} />
|
|
|
|
);
|
2016-11-03 18:42:26 +00:00
|
|
|
} else if (this.state.logged_in && this.state.ready) {
|
|
|
|
/* for now, we stuff the entirety of our props and state into the LoggedInView.
|
|
|
|
* we should go through and figure out what we actually need to pass down, as well
|
|
|
|
* as using something like redux to avoid having a billion bits of state kicking around.
|
|
|
|
*/
|
2016-02-08 17:20:52 +00:00
|
|
|
return (
|
2016-11-03 18:42:26 +00:00
|
|
|
<LoggedInView ref="loggedInView" matrixClient={MatrixClientPeg.get()}
|
|
|
|
onRoomIdResolved={this.onRoomIdResolved}
|
|
|
|
onRoomCreated={this.onRoomCreated}
|
|
|
|
onUserSettingsClose={this.onUserSettingsClose}
|
|
|
|
{...this.props}
|
|
|
|
{...this.state}
|
|
|
|
/>
|
|
|
|
)
|
2016-08-09 23:03:29 +00:00
|
|
|
} else if (this.state.logged_in) {
|
|
|
|
// we think we are logged in, but are still waiting for the /sync to complete
|
2015-11-30 18:11:04 +00:00
|
|
|
var Spinner = sdk.getComponent('elements.Spinner');
|
|
|
|
return (
|
|
|
|
<div className="mx_MatrixChat_splash">
|
|
|
|
<Spinner />
|
2016-08-09 23:03:29 +00:00
|
|
|
<a href="#" className="mx_MatrixChat_splashButtons" onClick={ this.onLogoutClick }>
|
|
|
|
Logout
|
|
|
|
</a>
|
2015-11-30 18:11:04 +00: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}
|
2016-08-11 10:00:15 +00:00
|
|
|
email={this.props.startingFragmentQueryParams.email}
|
2016-01-07 17:23:32 +00:00
|
|
|
username={this.state.upgradeUsername}
|
|
|
|
guestAccessToken={this.state.guestAccessToken}
|
2016-06-21 10:05:37 +00:00
|
|
|
defaultHsUrl={this.getDefaultHsUrl()}
|
|
|
|
defaultIsUrl={this.getDefaultIsUrl()}
|
2016-06-02 10:50:00 +00:00
|
|
|
brand={this.props.config.brand}
|
2016-03-15 13:48:46 +00:00
|
|
|
customHsUrl={this.getCurrentHsUrl()}
|
|
|
|
customIsUrl={this.getCurrentIsUrl()}
|
2015-11-30 18:11:04 +00:00
|
|
|
registrationUrl={this.props.registrationUrl}
|
2016-08-12 10:41:06 +00:00
|
|
|
defaultDeviceDisplayName={this.props.defaultDeviceDisplayName}
|
2015-11-30 18:11:04 +00:00
|
|
|
onLoggedIn={this.onRegistered}
|
2016-03-06 19:33:36 +00:00
|
|
|
onLoginClick={this.onLoginClick}
|
2016-03-15 21:04:11 +00:00
|
|
|
onRegisterClick={this.onRegisterClick}
|
2016-08-02 13:04:20 +00:00
|
|
|
onCancelClick={this.guestCreds ? this.onReturnToGuestClick : null}
|
2016-03-15 21:04:11 +00:00
|
|
|
/>
|
2015-11-30 18:11:04 +00:00
|
|
|
);
|
2016-01-12 17:20:16 +00:00
|
|
|
} else if (this.state.screen == 'forgot_password') {
|
|
|
|
return (
|
|
|
|
<ForgotPassword
|
2016-06-21 10:05:37 +00:00
|
|
|
defaultHsUrl={this.getDefaultHsUrl()}
|
|
|
|
defaultIsUrl={this.getDefaultIsUrl()}
|
2016-03-15 13:48:46 +00:00
|
|
|
customHsUrl={this.getCurrentHsUrl()}
|
|
|
|
customIsUrl={this.getCurrentIsUrl()}
|
2016-03-06 19:33:36 +00:00
|
|
|
onComplete={this.onLoginClick}
|
|
|
|
onLoginClick={this.onLoginClick} />
|
2016-01-12 17:20:16 +00:00
|
|
|
);
|
2015-11-30 18:11:04 +00:00
|
|
|
} else {
|
2016-09-01 10:08:40 +00:00
|
|
|
var r = (
|
2015-11-30 18:11:04 +00:00
|
|
|
<Login
|
2016-08-02 18:02:07 +00:00
|
|
|
onLoggedIn={Lifecycle.setLoggedIn}
|
2015-11-30 18:11:04 +00:00
|
|
|
onRegisterClick={this.onRegisterClick}
|
2016-06-21 10:05:37 +00:00
|
|
|
defaultHsUrl={this.getDefaultHsUrl()}
|
|
|
|
defaultIsUrl={this.getDefaultIsUrl()}
|
2016-03-15 13:48:46 +00:00
|
|
|
customHsUrl={this.getCurrentHsUrl()}
|
|
|
|
customIsUrl={this.getCurrentIsUrl()}
|
2016-05-27 13:57:43 +00:00
|
|
|
fallbackHsUrl={this.getFallbackHsUrl()}
|
2016-08-12 10:41:06 +00:00
|
|
|
defaultDeviceDisplayName={this.props.defaultDeviceDisplayName}
|
2016-04-22 16:05:48 +00:00
|
|
|
onForgotPasswordClick={this.onForgotPasswordClick}
|
2016-08-11 12:05:16 +00:00
|
|
|
enableGuest={this.props.enableGuest}
|
2016-08-02 13:04:20 +00:00
|
|
|
onCancelClick={this.guestCreds ? this.onReturnToGuestClick : null}
|
2016-09-01 10:08:40 +00:00
|
|
|
initialErrorText={this.sessionLoadError}
|
|
|
|
/>
|
2015-11-30 18:11:04 +00:00
|
|
|
);
|
2016-09-01 10:08:40 +00:00
|
|
|
|
|
|
|
// we only want to show the session load error the first time the
|
|
|
|
// Login component is rendered. This is pretty hacky but I can't
|
|
|
|
// think of another way to achieve it.
|
|
|
|
this.sessionLoadError = null;
|
|
|
|
|
|
|
|
return r;
|
2015-11-30 18:11:04 +00:00
|
|
|
}
|
2015-06-25 16:41:55 +00:00
|
|
|
}
|
2015-11-30 18:11:04 +00:00
|
|
|
});
|