2015-06-23 18:41:25 +03:00
|
|
|
/*
|
2016-01-07 07:06:39 +03:00
|
|
|
Copyright 2015, 2016 OpenMarket Ltd
|
2017-02-24 14:41:23 +03:00
|
|
|
Copyright 2017 Vector Creations Ltd
|
2019-01-11 16:15:09 +03:00
|
|
|
Copyright 2017-2019 New Vector Ltd
|
2020-01-16 00:13:56 +03:00
|
|
|
Copyright 2019, 2020 The Matrix.org Foundation C.I.C.
|
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.
|
|
|
|
*/
|
2016-09-01 13:08:40 +03:00
|
|
|
|
2020-05-14 06:03:12 +03:00
|
|
|
import React, { createRef } from 'react';
|
2020-06-26 11:37:55 +03:00
|
|
|
// @ts-ignore - XXX: no idea why this import fails
|
2020-06-26 11:35:29 +03:00
|
|
|
import * as Matrix from "matrix-js-sdk";
|
2020-05-14 06:03:12 +03:00
|
|
|
import { InvalidStoreError } from "matrix-js-sdk/src/errors";
|
|
|
|
import { RoomMember } from "matrix-js-sdk/src/models/room-member";
|
|
|
|
import { MatrixEvent } from "matrix-js-sdk/src/models/event";
|
2019-09-27 12:05:08 +03:00
|
|
|
// focus-visible is a Polyfill for the :focus-visible CSS pseudo-attribute used by _AccessibleButton.scss
|
|
|
|
import 'focus-visible';
|
2019-12-07 16:07:52 +03:00
|
|
|
// what-input helps improve keyboard accessibility
|
|
|
|
import 'what-input';
|
2019-09-27 12:05:08 +03:00
|
|
|
|
2017-05-27 22:47:09 +03:00
|
|
|
import Analytics from "../../Analytics";
|
2020-10-29 18:53:14 +03:00
|
|
|
import CountlyAnalytics from "../../CountlyAnalytics";
|
2018-07-06 13:00:39 +03:00
|
|
|
import { DecryptionFailureTracker } from "../../DecryptionFailureTracker";
|
2020-10-07 14:14:36 +03:00
|
|
|
import { MatrixClientPeg, IMatrixClientCreds } from "../../MatrixClientPeg";
|
2017-05-19 15:53:11 +03:00
|
|
|
import PlatformPeg from "../../PlatformPeg";
|
|
|
|
import SdkConfig from "../../SdkConfig";
|
|
|
|
import * as RoomListSorter from "../../RoomListSorter";
|
2020-05-14 05:41:41 +03:00
|
|
|
import dis from "../../dispatcher/dispatcher";
|
2019-03-12 19:29:16 +03:00
|
|
|
import Notifier from '../../Notifier';
|
2017-05-19 15:53:11 +03:00
|
|
|
|
|
|
|
import Modal from "../../Modal";
|
|
|
|
import Tinter from "../../Tinter";
|
2019-12-20 04:19:56 +03:00
|
|
|
import * as sdk from '../../index';
|
2020-05-14 06:03:12 +03:00
|
|
|
import { showRoomInviteDialog, showStartChatInviteDialog } from '../../RoomInvite';
|
2017-05-19 15:53:11 +03:00
|
|
|
import * as Rooms from '../../Rooms';
|
|
|
|
import linkifyMatrix from "../../linkify-matrix";
|
|
|
|
import * as Lifecycle from '../../Lifecycle';
|
2017-05-26 13:50:32 +03:00
|
|
|
// LifecycleStore is not used but does listen to and dispatch actions
|
2019-09-27 11:00:54 +03:00
|
|
|
import '../../stores/LifecycleStore';
|
2017-05-19 15:53:11 +03:00
|
|
|
import PageTypes from '../../PageTypes';
|
2019-02-14 15:35:09 +03:00
|
|
|
import { getHomePageUrl } from '../../utils/pages';
|
2017-05-19 15:53:11 +03:00
|
|
|
|
|
|
|
import createRoom from "../../createRoom";
|
2020-07-13 18:35:03 +03:00
|
|
|
import {_t, _td, getCurrentLanguage} from '../../languageHandler';
|
2020-07-29 01:37:09 +03:00
|
|
|
import SettingsStore from "../../settings/SettingsStore";
|
2020-01-31 15:28:14 +03:00
|
|
|
import ThemeController from "../../settings/controllers/ThemeController";
|
2018-09-05 19:07:39 +03:00
|
|
|
import { startAnyRegistrationFlow } from "../../Registration.js";
|
2018-09-07 14:18:25 +03:00
|
|
|
import { messageForSyncError } from '../../utils/ErrorUtils';
|
2019-03-12 18:36:12 +03:00
|
|
|
import ResizeNotifier from "../../utils/ResizeNotifier";
|
2020-05-14 06:03:12 +03:00
|
|
|
import AutoDiscoveryUtils, { ValidatedServerConfig } from "../../utils/AutoDiscoveryUtils";
|
2019-06-14 17:31:19 +03:00
|
|
|
import DMRoomMap from '../../utils/DMRoomMap';
|
2020-05-28 15:55:07 +03:00
|
|
|
import ThemeWatcher from "../../settings/watchers/ThemeWatcher";
|
|
|
|
import { FontWatcher } from '../../settings/watchers/FontWatcher';
|
2019-11-12 14:43:18 +03:00
|
|
|
import { storeRoomAliasInCache } from '../../RoomAliasCache';
|
2020-11-02 20:25:48 +03:00
|
|
|
import { defer, IDeferred, sleep } from "../../utils/promise";
|
2020-01-16 23:23:47 +03:00
|
|
|
import ToastStore from "../../stores/ToastStore";
|
2020-02-20 03:38:08 +03:00
|
|
|
import * as StorageManager from "../../utils/StorageManager";
|
2020-04-22 15:22:33 +03:00
|
|
|
import type LoggedInViewType from "./LoggedInView";
|
2020-05-14 06:03:12 +03:00
|
|
|
import { ViewUserPayload } from "../../dispatcher/payloads/ViewUserPayload";
|
|
|
|
import { Action } from "../../dispatcher/actions";
|
2020-05-23 00:04:21 +03:00
|
|
|
import {
|
|
|
|
showToast as showAnalyticsToast,
|
2020-08-29 03:11:08 +03:00
|
|
|
hideToast as hideAnalyticsToast,
|
2020-05-23 00:04:21 +03:00
|
|
|
} from "../../toasts/AnalyticsToast";
|
2020-05-28 21:03:42 +03:00
|
|
|
import {showToast as showNotificationsToast} from "../../toasts/DesktopNotificationsToast";
|
2020-06-08 17:20:15 +03:00
|
|
|
import { OpenToTabPayload } from "../../dispatcher/payloads/OpenToTabPayload";
|
2020-07-13 19:01:50 +03:00
|
|
|
import ErrorDialog from "../views/dialogs/ErrorDialog";
|
2020-07-22 05:24:16 +03:00
|
|
|
import { RoomNotificationStateStore } from "../../stores/notifications/RoomNotificationStateStore";
|
2020-07-28 20:53:43 +03:00
|
|
|
import { SettingLevel } from "../../settings/SettingLevel";
|
2020-08-20 04:21:40 +03:00
|
|
|
import { leaveRoomBehaviour } from "../../utils/membership";
|
2020-08-26 17:50:32 +03:00
|
|
|
import CreateCommunityPrototypeDialog from "../views/dialogs/CreateCommunityPrototypeDialog";
|
2020-09-12 04:49:48 +03:00
|
|
|
import ThreepidInviteStore, { IThreepidInvite, IThreepidInviteWireFormat } from "../../stores/ThreepidInviteStore";
|
2020-09-16 15:40:27 +03:00
|
|
|
import {UIFeature} from "../../settings/UIFeature";
|
2020-09-19 01:04:19 +03:00
|
|
|
import { CommunityPrototypeStore } from "../../stores/CommunityPrototypeStore";
|
2018-10-05 14:15:03 +03:00
|
|
|
|
2017-06-09 19:18:45 +03:00
|
|
|
/** constants for MatrixChat.state.view */
|
2020-04-23 12:12:50 +03:00
|
|
|
export enum Views {
|
2017-06-14 22:04:55 +03:00
|
|
|
// a special initial state which is only used at startup, while we are
|
|
|
|
// trying to re-animate a matrix client or register as a guest.
|
2020-04-22 15:08:33 +03:00
|
|
|
LOADING = 0,
|
2017-06-14 22:04:55 +03:00
|
|
|
|
2019-02-07 19:25:09 +03:00
|
|
|
// we are showing the welcome view
|
2020-04-22 15:08:33 +03:00
|
|
|
WELCOME = 1,
|
2019-02-07 19:25:09 +03:00
|
|
|
|
2017-06-14 22:04:55 +03:00
|
|
|
// we are showing the login view
|
2020-04-22 15:08:33 +03:00
|
|
|
LOGIN = 2,
|
2017-06-14 22:04:55 +03:00
|
|
|
|
|
|
|
// we are showing the registration view
|
2020-04-22 15:08:33 +03:00
|
|
|
REGISTER = 3,
|
2017-06-14 22:04:55 +03:00
|
|
|
|
2020-01-16 00:13:56 +03:00
|
|
|
// completing the registration flow
|
2020-04-22 15:08:33 +03:00
|
|
|
POST_REGISTRATION = 4,
|
2017-06-14 22:04:55 +03:00
|
|
|
|
|
|
|
// showing the 'forgot password' view
|
2020-04-22 15:08:33 +03:00
|
|
|
FORGOT_PASSWORD = 5,
|
2017-06-14 22:04:55 +03:00
|
|
|
|
2020-01-16 00:13:56 +03:00
|
|
|
// showing flow to trust this new device with cross-signing
|
2020-04-22 15:08:33 +03:00
|
|
|
COMPLETE_SECURITY = 6,
|
2017-06-14 22:04:55 +03:00
|
|
|
|
2020-01-24 22:11:57 +03:00
|
|
|
// flow to setup SSSS / cross-signing on this account
|
2020-04-22 15:08:33 +03:00
|
|
|
E2E_SETUP = 7,
|
2020-01-24 22:11:57 +03:00
|
|
|
|
2020-10-21 17:40:35 +03:00
|
|
|
// we are logged in with an active matrix client. The logged_in state also
|
2020-10-21 17:43:50 +03:00
|
|
|
// includes guests users as they too are logged in at the client level.
|
2020-04-22 15:08:33 +03:00
|
|
|
LOGGED_IN = 8,
|
2019-07-04 01:46:37 +03:00
|
|
|
|
|
|
|
// We are logged out (invalid token) but have our local state again. The user
|
|
|
|
// should log back in to rehydrate the client.
|
2020-04-22 15:08:33 +03:00
|
|
|
SOFT_LOGOUT = 9,
|
|
|
|
}
|
2016-06-09 01:03:46 +03:00
|
|
|
|
2017-11-10 13:51:28 +03:00
|
|
|
// Actions that are redirected through the onboarding process prior to being
|
|
|
|
// re-dispatched. NOTE: some actions are non-trivial and would require
|
|
|
|
// re-factoring to be included in this list in future.
|
|
|
|
const ONBOARDING_FLOW_STARTERS = [
|
2020-05-14 06:07:19 +03:00
|
|
|
Action.ViewUserSettings,
|
2017-11-10 13:51:28 +03:00
|
|
|
'view_create_chat',
|
|
|
|
'view_create_room',
|
2017-11-28 15:08:53 +03:00
|
|
|
'view_create_group',
|
2017-11-10 13:51:28 +03:00
|
|
|
];
|
|
|
|
|
2020-04-22 15:08:33 +03:00
|
|
|
interface IScreen {
|
2020-04-28 01:59:07 +03:00
|
|
|
screen: string;
|
2020-04-22 15:08:33 +03:00
|
|
|
params?: object;
|
|
|
|
}
|
|
|
|
|
2020-08-29 03:11:08 +03:00
|
|
|
/* eslint-disable camelcase */
|
2020-04-22 15:08:33 +03:00
|
|
|
interface IRoomInfo {
|
|
|
|
room_id?: string;
|
|
|
|
room_alias?: string;
|
|
|
|
event_id?: string;
|
|
|
|
|
|
|
|
auto_join?: boolean;
|
|
|
|
highlighted?: boolean;
|
|
|
|
oob_data?: object;
|
|
|
|
via_servers?: string[];
|
2020-09-12 04:49:48 +03:00
|
|
|
threepid_invite?: IThreepidInvite;
|
2020-04-22 15:08:33 +03:00
|
|
|
}
|
2020-08-29 03:11:08 +03:00
|
|
|
/* eslint-enable camelcase */
|
2020-04-22 15:08:33 +03:00
|
|
|
|
|
|
|
interface IProps { // TODO type things better
|
|
|
|
config: Record<string, any>;
|
|
|
|
serverConfig?: ValidatedServerConfig;
|
2020-09-09 18:52:46 +03:00
|
|
|
onNewScreen: (screen: string, replaceLast: boolean) => void;
|
2020-04-22 15:08:33 +03:00
|
|
|
enableGuest?: boolean;
|
|
|
|
// the queryParams extracted from the [real] query-string of the URI
|
|
|
|
realQueryParams?: Record<string, string>;
|
|
|
|
// the initial queryParams extracted from the hash-fragment of the URI
|
|
|
|
startingFragmentQueryParams?: Record<string, string>;
|
|
|
|
// called when we have completed a token login
|
|
|
|
onTokenLoginCompleted?: () => void;
|
|
|
|
// Represents the screen to display as a result of parsing the initial window.location
|
|
|
|
initialScreenAfterLogin?: IScreen;
|
|
|
|
// displayname, if any, to set on the device when logging in/registering.
|
2020-06-18 16:32:43 +03:00
|
|
|
defaultDeviceDisplayName?: string;
|
2020-04-22 15:08:33 +03:00
|
|
|
// A function that makes a registration URL
|
2020-06-18 16:32:43 +03:00
|
|
|
makeRegistrationUrl: (object) => string;
|
2020-04-22 15:08:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
interface IState {
|
|
|
|
// the master view we are showing.
|
2020-04-23 12:12:50 +03:00
|
|
|
view: Views;
|
2020-04-22 15:08:33 +03:00
|
|
|
// What the LoggedInView would be showing if visible
|
2020-08-29 03:11:08 +03:00
|
|
|
// eslint-disable-next-line camelcase
|
2020-04-22 15:08:33 +03:00
|
|
|
page_type?: PageTypes;
|
|
|
|
// 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?: string;
|
|
|
|
currentGroupId?: string;
|
|
|
|
currentGroupIsNew?: boolean;
|
|
|
|
// If we're trying to just view a user ID (i.e. /user URL), this is it
|
|
|
|
currentUserId?: string;
|
|
|
|
// this is persisted as mx_lhs_size, loaded in LoggedInView
|
|
|
|
collapseLhs: boolean;
|
|
|
|
// Parameters used in the registration dance with the IS
|
2020-08-29 03:11:08 +03:00
|
|
|
// eslint-disable-next-line camelcase
|
2020-04-22 15:08:33 +03:00
|
|
|
register_client_secret?: string;
|
2020-08-29 03:11:08 +03:00
|
|
|
// eslint-disable-next-line camelcase
|
2020-04-22 15:08:33 +03:00
|
|
|
register_session_id?: string;
|
2020-08-29 03:11:08 +03:00
|
|
|
// eslint-disable-next-line camelcase
|
2020-04-22 15:08:33 +03:00
|
|
|
register_id_sid?: string;
|
|
|
|
// When showing Modal dialogs we need to set aria-hidden on the root app element
|
|
|
|
// and disable it when there are no dialogs
|
|
|
|
hideToSRUsers: boolean;
|
|
|
|
syncError?: Error;
|
|
|
|
resizeNotifier: ResizeNotifier;
|
|
|
|
serverConfig?: ValidatedServerConfig;
|
|
|
|
ready: boolean;
|
2020-09-12 04:49:48 +03:00
|
|
|
threepidInvite?: IThreepidInvite,
|
2020-04-22 15:08:33 +03:00
|
|
|
roomOobData?: object;
|
|
|
|
viaServers?: string[];
|
|
|
|
pendingInitialSync?: boolean;
|
2020-11-02 20:24:47 +03:00
|
|
|
justRegistered?: boolean;
|
2020-04-22 15:08:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
export default class MatrixChat extends React.PureComponent<IProps, IState> {
|
2020-04-22 13:55:03 +03:00
|
|
|
static displayName = "MatrixChat";
|
2017-06-14 22:04:55 +03:00
|
|
|
|
2020-04-22 13:55:03 +03:00
|
|
|
static defaultProps = {
|
|
|
|
realQueryParams: {},
|
|
|
|
startingFragmentQueryParams: {},
|
|
|
|
config: {},
|
|
|
|
onTokenLoginCompleted: () => {},
|
|
|
|
};
|
|
|
|
|
2020-04-22 15:08:33 +03:00
|
|
|
firstSyncComplete: boolean;
|
|
|
|
firstSyncPromise: IDeferred<void>;
|
|
|
|
|
|
|
|
private screenAfterLogin?: IScreen;
|
|
|
|
private windowWidth: number;
|
|
|
|
private pageChanging: boolean;
|
|
|
|
private accountPassword?: string;
|
|
|
|
private accountPasswordTimer?: NodeJS.Timeout;
|
|
|
|
private focusComposer: boolean;
|
|
|
|
private subTitleStatus: string;
|
|
|
|
|
2020-04-22 15:22:33 +03:00
|
|
|
private readonly loggedInView: React.RefObject<LoggedInViewType>;
|
2020-04-22 15:08:33 +03:00
|
|
|
private readonly dispatcherRef: any;
|
|
|
|
private readonly themeWatcher: ThemeWatcher;
|
2020-05-07 20:01:20 +03:00
|
|
|
private readonly fontWatcher: FontWatcher;
|
2020-04-22 15:08:33 +03:00
|
|
|
|
2020-04-22 13:55:03 +03:00
|
|
|
constructor(props, context) {
|
|
|
|
super(props, context);
|
2015-10-12 12:13:01 +03:00
|
|
|
|
2020-04-22 13:55:03 +03:00
|
|
|
this.state = {
|
2020-04-23 12:12:50 +03:00
|
|
|
view: Views.LOADING,
|
2017-08-25 14:10:13 +03:00
|
|
|
collapseLhs: false,
|
2016-08-16 01:01:02 +03:00
|
|
|
|
2018-02-09 00:51:07 +03:00
|
|
|
hideToSRUsers: false,
|
2018-09-07 14:18:25 +03:00
|
|
|
|
|
|
|
syncError: null, // If the current syncing status is ERROR, the error object, otherwise null.
|
2019-03-12 18:36:12 +03:00
|
|
|
resizeNotifier: new ResizeNotifier(),
|
2020-04-22 15:08:33 +03:00
|
|
|
ready: false,
|
2015-06-11 20:25:29 +03:00
|
|
|
};
|
2016-05-27 16:57:43 +03:00
|
|
|
|
2020-04-22 15:08:33 +03:00
|
|
|
this.loggedInView = createRef();
|
2016-06-21 13:05:37 +03:00
|
|
|
|
2016-05-06 16:19:56 +03:00
|
|
|
SdkConfig.put(this.props.config);
|
2016-08-02 20:46:43 +03:00
|
|
|
|
2017-04-06 13:30:47 +03:00
|
|
|
// Used by _viewRoom before getting state from sync
|
|
|
|
this.firstSyncComplete = false;
|
2019-11-12 14:45:28 +03:00
|
|
|
this.firstSyncPromise = defer();
|
2017-04-06 13:30:47 +03:00
|
|
|
|
2016-08-03 11:53:02 +03:00
|
|
|
if (this.props.config.sync_timeline_limit) {
|
|
|
|
MatrixClientPeg.opts.initialSyncLimit = this.props.config.sync_timeline_limit;
|
|
|
|
}
|
2017-02-03 14:48:24 +03:00
|
|
|
|
2017-08-09 00:19:38 +03:00
|
|
|
// a thing to call showScreen with once login completes. this is kept
|
|
|
|
// outside this.state because updating it should never trigger a
|
|
|
|
// rerender.
|
2020-04-22 15:08:33 +03:00
|
|
|
this.screenAfterLogin = this.props.initialScreenAfterLogin;
|
2020-09-12 04:49:48 +03:00
|
|
|
if (this.screenAfterLogin) {
|
|
|
|
const params = this.screenAfterLogin.params || {};
|
|
|
|
if (this.screenAfterLogin.screen.startsWith("room/") && params['signurl'] && params['email']) {
|
|
|
|
// probably a threepid invite - try to store it
|
|
|
|
const roomId = this.screenAfterLogin.screen.substring("room/".length);
|
|
|
|
ThreepidInviteStore.instance.storeInvite(roomId, params as IThreepidInviteWireFormat);
|
|
|
|
}
|
|
|
|
}
|
2017-08-09 00:19:38 +03:00
|
|
|
|
2020-04-22 15:08:33 +03:00
|
|
|
this.windowWidth = 10000;
|
2017-08-09 00:19:38 +03:00
|
|
|
this.handleResize();
|
|
|
|
window.addEventListener('resize', this.handleResize);
|
2017-10-26 03:43:42 +03:00
|
|
|
|
2020-04-22 15:08:33 +03:00
|
|
|
this.pageChanging = false;
|
2018-03-28 13:25:28 +03:00
|
|
|
|
2017-11-14 18:28:34 +03:00
|
|
|
// check we have the right tint applied for this theme.
|
|
|
|
// N.B. we don't call the whole of setTheme() here as we may be
|
|
|
|
// racing with the theme CSS download finishing from index.js
|
2017-10-26 03:43:42 +03:00
|
|
|
Tinter.tint();
|
2019-03-12 18:37:20 +03:00
|
|
|
|
|
|
|
// For PersistentElement
|
2020-04-22 15:08:33 +03:00
|
|
|
this.state.resizeNotifier.on("middlePanelResized", this.dispatchTimelineResize);
|
2019-07-05 00:14:00 +03:00
|
|
|
|
|
|
|
// Force users to go through the soft logout page if they're soft logged out
|
|
|
|
if (Lifecycle.isSoftLogout()) {
|
|
|
|
// When the session loads it'll be detected as soft logged out and a dispatch
|
|
|
|
// will be sent out to say that, triggering this MatrixChat to show the soft
|
|
|
|
// logout page.
|
2020-10-07 14:14:36 +03:00
|
|
|
Lifecycle.loadSession();
|
2019-07-05 00:14:00 +03:00
|
|
|
}
|
2020-01-25 18:28:06 +03:00
|
|
|
|
2020-04-22 15:08:33 +03:00
|
|
|
this.accountPassword = null;
|
|
|
|
this.accountPasswordTimer = null;
|
2015-12-21 15:55:13 +03:00
|
|
|
|
2015-06-12 19:34:17 +03:00
|
|
|
this.dispatcherRef = dis.register(this.onAction);
|
2020-05-07 20:01:20 +03:00
|
|
|
|
2020-04-22 15:08:33 +03:00
|
|
|
this.themeWatcher = new ThemeWatcher();
|
2020-05-07 20:01:20 +03:00
|
|
|
this.fontWatcher = new FontWatcher();
|
2020-04-22 15:08:33 +03:00
|
|
|
this.themeWatcher.start();
|
2020-05-07 20:01:20 +03:00
|
|
|
this.fontWatcher.start();
|
2016-08-10 13:33:58 +03:00
|
|
|
|
2019-07-23 10:13:51 +03:00
|
|
|
this.focusComposer = false;
|
|
|
|
|
2019-09-24 00:01:49 +03:00
|
|
|
// object field used for tracking the status info appended to the title tag.
|
|
|
|
// we don't do it as react state as i'm scared about triggering needless react refreshes.
|
|
|
|
this.subTitleStatus = '';
|
|
|
|
|
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.
|
2016-08-28 04:05:23 +03:00
|
|
|
if (this.onAliasClick) {
|
|
|
|
linkifyMatrix.onAliasClick = this.onAliasClick;
|
|
|
|
}
|
|
|
|
if (this.onUserClick) {
|
|
|
|
linkifyMatrix.onUserClick = this.onUserClick;
|
|
|
|
}
|
2017-06-05 18:51:50 +03:00
|
|
|
if (this.onGroupClick) {
|
|
|
|
linkifyMatrix.onGroupClick = this.onGroupClick;
|
|
|
|
}
|
2015-11-30 21:11:04 +03:00
|
|
|
|
2017-06-16 16:33:14 +03:00
|
|
|
// the first thing to do is to try the token params in the query-string
|
2019-07-08 21:43:16 +03:00
|
|
|
// if the session isn't soft logged out (ie: is a clean session being logged in)
|
|
|
|
if (!Lifecycle.isSoftLogout()) {
|
2019-09-18 14:16:41 +03:00
|
|
|
Lifecycle.attemptTokenLogin(
|
|
|
|
this.props.realQueryParams,
|
|
|
|
this.props.defaultDeviceDisplayName,
|
|
|
|
).then((loggedIn) => {
|
2019-07-08 21:43:16 +03:00
|
|
|
if (loggedIn) {
|
|
|
|
this.props.onTokenLoginCompleted();
|
|
|
|
|
|
|
|
// don't do anything else until the page reloads - just stay in
|
|
|
|
// the 'loading' state.
|
|
|
|
return;
|
|
|
|
}
|
2017-06-14 12:53:48 +03:00
|
|
|
|
2019-07-08 21:43:16 +03:00
|
|
|
// if the user has followed a login or register link, don't reanimate
|
|
|
|
// the old creds, but rather go straight to the relevant page
|
2020-04-22 15:08:33 +03:00
|
|
|
const firstScreen = this.screenAfterLogin ? this.screenAfterLogin.screen : null;
|
2017-06-14 12:53:48 +03:00
|
|
|
|
2019-07-08 21:43:16 +03:00
|
|
|
if (firstScreen === 'login' ||
|
2017-06-16 16:33:14 +03:00
|
|
|
firstScreen === 'register' ||
|
|
|
|
firstScreen === 'forgot_password') {
|
2020-04-22 15:08:33 +03:00
|
|
|
this.showScreenAfterLogin();
|
2019-07-08 21:43:16 +03:00
|
|
|
return;
|
|
|
|
}
|
2017-02-03 17:34:24 +03:00
|
|
|
|
2020-04-22 15:08:33 +03:00
|
|
|
return this.loadSession();
|
2019-07-08 21:43:16 +03:00
|
|
|
});
|
|
|
|
}
|
2018-05-15 15:15:40 +03:00
|
|
|
|
|
|
|
if (SettingsStore.getValue("analyticsOptIn")) {
|
|
|
|
Analytics.enable();
|
|
|
|
}
|
2020-10-30 17:27:14 +03:00
|
|
|
CountlyAnalytics.instance.enable(/* anonymous = */ true);
|
2020-04-22 13:55:03 +03:00
|
|
|
}
|
2015-06-12 16:59:33 +03:00
|
|
|
|
2020-04-22 13:55:03 +03:00
|
|
|
// TODO: [REACT-WARNING] Replace with appropriate lifecycle stage
|
2020-08-29 03:11:08 +03:00
|
|
|
// eslint-disable-next-line camelcase
|
2020-04-22 13:55:03 +03:00
|
|
|
UNSAFE_componentWillUpdate(props, state) {
|
|
|
|
if (this.shouldTrackPageChange(this.state, state)) {
|
|
|
|
this.startPageChangeTimer();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidUpdate(prevProps, prevState) {
|
|
|
|
if (this.shouldTrackPageChange(prevState, this.state)) {
|
|
|
|
const durationMs = this.stopPageChangeTimer();
|
|
|
|
Analytics.trackPageChange(durationMs);
|
2020-10-29 18:53:14 +03:00
|
|
|
CountlyAnalytics.instance.trackPageChange(durationMs);
|
2020-04-22 13:55:03 +03:00
|
|
|
}
|
|
|
|
if (this.focusComposer) {
|
2020-06-03 04:07:46 +03:00
|
|
|
dis.fire(Action.FocusComposer);
|
2020-04-22 13:55:03 +03:00
|
|
|
this.focusComposer = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount() {
|
|
|
|
Lifecycle.stopMatrixClient();
|
|
|
|
dis.unregister(this.dispatcherRef);
|
2020-04-22 15:08:33 +03:00
|
|
|
this.themeWatcher.stop();
|
2020-05-07 20:01:20 +03:00
|
|
|
this.fontWatcher.stop();
|
2020-04-22 13:55:03 +03:00
|
|
|
window.removeEventListener('resize', this.handleResize);
|
2020-04-22 15:08:33 +03:00
|
|
|
this.state.resizeNotifier.removeListener("middlePanelResized", this.dispatchTimelineResize);
|
2020-04-22 13:55:03 +03:00
|
|
|
|
2020-04-22 15:08:33 +03:00
|
|
|
if (this.accountPasswordTimer !== null) clearTimeout(this.accountPasswordTimer);
|
2020-04-22 13:55:03 +03:00
|
|
|
}
|
2015-06-12 16:59:33 +03:00
|
|
|
|
2020-04-22 13:55:03 +03:00
|
|
|
getFallbackHsUrl() {
|
|
|
|
if (this.props.serverConfig && this.props.serverConfig.isDefault) {
|
|
|
|
return this.props.config.fallback_hs_url;
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
getServerProperties() {
|
|
|
|
let props = this.state.serverConfig;
|
|
|
|
if (!props) props = this.props.serverConfig; // for unit tests
|
|
|
|
if (!props) props = SdkConfig.get()["validated_server_config"];
|
|
|
|
return {serverConfig: props};
|
|
|
|
}
|
|
|
|
|
2020-04-22 15:08:33 +03:00
|
|
|
private loadSession() {
|
2019-03-08 03:04:50 +03:00
|
|
|
// the extra Promise.resolve() ensures that synchronous exceptions hit the same codepath as
|
|
|
|
// asynchronous ones.
|
|
|
|
return Promise.resolve().then(() => {
|
|
|
|
return Lifecycle.loadSession({
|
|
|
|
fragmentQueryParams: this.props.startingFragmentQueryParams,
|
|
|
|
enableGuest: this.props.enableGuest,
|
2019-05-03 08:09:07 +03:00
|
|
|
guestHsUrl: this.getServerProperties().serverConfig.hsUrl,
|
|
|
|
guestIsUrl: this.getServerProperties().serverConfig.isUrl,
|
2019-03-08 03:04:50 +03:00
|
|
|
defaultDeviceDisplayName: this.props.defaultDeviceDisplayName,
|
|
|
|
});
|
|
|
|
}).then((loadedSession) => {
|
|
|
|
if (!loadedSession) {
|
2020-09-12 04:53:52 +03:00
|
|
|
// fall back to showing the welcome screen... unless we have a 3pid invite pending
|
|
|
|
if (ThreepidInviteStore.instance.pickBestInvite()) {
|
|
|
|
dis.dispatch({action: 'start_registration'});
|
|
|
|
} else {
|
|
|
|
dis.dispatch({action: "view_welcome_page"});
|
|
|
|
}
|
2020-10-29 18:53:14 +03:00
|
|
|
} else if (SettingsStore.getValue("analyticsOptIn")) {
|
2020-10-30 17:27:14 +03:00
|
|
|
CountlyAnalytics.instance.enable(/* anonymous = */ false);
|
2019-03-08 03:04:50 +03:00
|
|
|
}
|
|
|
|
});
|
|
|
|
// Note we don't catch errors from this: we catch everything within
|
|
|
|
// loadSession as there's logic there to ask the user if they want
|
|
|
|
// to try logging out.
|
2020-04-22 13:55:03 +03:00
|
|
|
}
|
2015-06-18 17:03:57 +03:00
|
|
|
|
2018-03-28 12:25:28 +03:00
|
|
|
startPageChangeTimer() {
|
2018-06-04 11:38:21 +03:00
|
|
|
// Tor doesn't support performance
|
|
|
|
if (!performance || !performance.mark) return null;
|
|
|
|
|
2020-04-01 23:32:35 +03:00
|
|
|
// This shouldn't happen because UNSAFE_componentWillUpdate and componentDidUpdate
|
2018-03-28 12:25:28 +03:00
|
|
|
// are used.
|
2020-04-22 15:08:33 +03:00
|
|
|
if (this.pageChanging) {
|
2018-03-28 12:25:28 +03:00
|
|
|
console.warn('MatrixChat.startPageChangeTimer: timer already started');
|
|
|
|
return;
|
|
|
|
}
|
2020-04-22 15:08:33 +03:00
|
|
|
this.pageChanging = true;
|
2020-08-03 18:02:26 +03:00
|
|
|
performance.mark('element_MatrixChat_page_change_start');
|
2020-04-22 13:55:03 +03:00
|
|
|
}
|
2018-03-28 12:25:28 +03:00
|
|
|
|
|
|
|
stopPageChangeTimer() {
|
2018-06-04 11:38:21 +03:00
|
|
|
// Tor doesn't support performance
|
|
|
|
if (!performance || !performance.mark) return null;
|
|
|
|
|
2020-04-22 15:08:33 +03:00
|
|
|
if (!this.pageChanging) {
|
2018-03-28 12:25:28 +03:00
|
|
|
console.warn('MatrixChat.stopPageChangeTimer: timer not started');
|
|
|
|
return;
|
|
|
|
}
|
2020-04-22 15:08:33 +03:00
|
|
|
this.pageChanging = false;
|
2020-08-03 18:02:26 +03:00
|
|
|
performance.mark('element_MatrixChat_page_change_stop');
|
2018-03-28 12:25:28 +03:00
|
|
|
performance.measure(
|
2020-08-03 18:02:26 +03:00
|
|
|
'element_MatrixChat_page_change_delta',
|
|
|
|
'element_MatrixChat_page_change_start',
|
|
|
|
'element_MatrixChat_page_change_stop',
|
2018-03-28 12:25:28 +03:00
|
|
|
);
|
2020-08-03 18:02:26 +03:00
|
|
|
performance.clearMarks('element_MatrixChat_page_change_start');
|
|
|
|
performance.clearMarks('element_MatrixChat_page_change_stop');
|
|
|
|
const measurement = performance.getEntriesByName('element_MatrixChat_page_change_delta').pop();
|
2018-05-03 16:08:10 +03:00
|
|
|
|
|
|
|
// In practice, sometimes the entries list is empty, so we get no measurement
|
|
|
|
if (!measurement) return null;
|
|
|
|
|
2018-03-28 12:25:28 +03:00
|
|
|
return measurement.duration;
|
2020-04-22 13:55:03 +03:00
|
|
|
}
|
2018-03-28 12:25:28 +03:00
|
|
|
|
2020-04-22 15:08:33 +03:00
|
|
|
shouldTrackPageChange(prevState: IState, state: IState) {
|
2018-03-27 13:17:49 +03:00
|
|
|
return prevState.currentRoomId !== state.currentRoomId ||
|
|
|
|
prevState.view !== state.view ||
|
|
|
|
prevState.page_type !== state.page_type;
|
2020-04-22 13:55:03 +03:00
|
|
|
}
|
2018-03-27 13:17:49 +03:00
|
|
|
|
2020-04-22 15:08:33 +03:00
|
|
|
setStateForNewView(state: Partial<IState>) {
|
2017-06-14 22:04:55 +03:00
|
|
|
if (state.view === undefined) {
|
|
|
|
throw new Error("setStateForNewView with no view!");
|
|
|
|
}
|
2016-09-30 13:56:32 +03:00
|
|
|
const newState = {
|
2020-04-22 15:08:33 +03:00
|
|
|
currentUserId: null,
|
2020-11-02 20:24:47 +03:00
|
|
|
justRegistered: false,
|
2017-08-09 00:19:38 +03:00
|
|
|
};
|
|
|
|
Object.assign(newState, state);
|
|
|
|
this.setState(newState);
|
2020-04-22 13:55:03 +03:00
|
|
|
}
|
2016-09-30 13:56:32 +03:00
|
|
|
|
2020-04-22 13:55:03 +03:00
|
|
|
onAction = (payload) => {
|
2017-06-14 22:04:55 +03:00
|
|
|
// console.log(`MatrixClientPeg.onAction: ${payload.action}`);
|
2017-03-09 20:03:57 +03:00
|
|
|
const QuestionDialog = sdk.getComponent("dialogs.QuestionDialog");
|
2015-06-25 19:41:55 +03:00
|
|
|
|
2017-11-10 13:51:28 +03:00
|
|
|
// Start the onboarding process for certain actions
|
2017-11-10 14:13:52 +03:00
|
|
|
if (MatrixClientPeg.get() && MatrixClientPeg.get().isGuest() &&
|
2017-11-10 13:51:28 +03:00
|
|
|
ONBOARDING_FLOW_STARTERS.includes(payload.action)
|
|
|
|
) {
|
|
|
|
// This will cause `payload` to be dispatched later, once a
|
|
|
|
// sync has reached the "prepared" state. Setting a matrix ID
|
|
|
|
// will cause a full login and sync and finally the deferred
|
|
|
|
// action will be dispatched.
|
|
|
|
dis.dispatch({
|
|
|
|
action: 'do_after_sync_prepared',
|
|
|
|
deferred_action: payload,
|
|
|
|
});
|
2018-09-05 19:07:39 +03:00
|
|
|
dis.dispatch({action: 'require_registration'});
|
2017-11-10 13:51:28 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-06-12 19:34:17 +03:00
|
|
|
switch (payload.action) {
|
2019-08-16 22:10:41 +03:00
|
|
|
case 'MatrixActions.accountData':
|
|
|
|
// XXX: This is a collection of several hacks to solve a minor problem. We want to
|
|
|
|
// update our local state when the ID server changes, but don't want to put that in
|
|
|
|
// the js-sdk as we'd be then dictating how all consumers need to behave. However,
|
|
|
|
// this component is already bloated and we probably don't want this tiny logic in
|
|
|
|
// here, but there's no better place in the react-sdk for it. Additionally, we're
|
|
|
|
// abusing the MatrixActionCreator stuff to avoid errors on dispatches.
|
|
|
|
if (payload.event_type === 'm.identity_server') {
|
|
|
|
const fullUrl = payload.event_content ? payload.event_content['base_url'] : null;
|
|
|
|
if (!fullUrl) {
|
|
|
|
MatrixClientPeg.get().setIdentityServerUrl(null);
|
|
|
|
localStorage.removeItem("mx_is_access_token");
|
|
|
|
localStorage.removeItem("mx_is_url");
|
|
|
|
} else {
|
|
|
|
MatrixClientPeg.get().setIdentityServerUrl(fullUrl);
|
|
|
|
localStorage.removeItem("mx_is_access_token"); // clear token
|
|
|
|
localStorage.setItem("mx_is_url", fullUrl); // XXX: Do we still need this?
|
|
|
|
}
|
|
|
|
|
|
|
|
// redispatch the change with a more specific action
|
|
|
|
dis.dispatch({action: 'id_server_changed'});
|
|
|
|
}
|
|
|
|
break;
|
2015-06-12 19:34:17 +03:00
|
|
|
case 'logout':
|
2016-08-02 16:04:20 +03:00
|
|
|
Lifecycle.logout();
|
2015-06-12 19:34:17 +03:00
|
|
|
break;
|
2018-09-05 19:07:39 +03:00
|
|
|
case 'require_registration':
|
|
|
|
startAnyRegistrationFlow(payload);
|
|
|
|
break;
|
2015-07-13 21:14:02 +03:00
|
|
|
case 'start_registration':
|
2019-07-05 01:51:55 +03:00
|
|
|
if (Lifecycle.isSoftLogout()) {
|
2020-04-22 15:08:33 +03:00
|
|
|
this.onSoftLogout();
|
2019-07-05 01:51:55 +03:00
|
|
|
break;
|
|
|
|
}
|
2018-09-05 19:07:39 +03:00
|
|
|
// This starts the full registration flow
|
2019-06-10 12:24:06 +03:00
|
|
|
if (payload.screenAfterLogin) {
|
2020-04-22 15:08:33 +03:00
|
|
|
this.screenAfterLogin = payload.screenAfterLogin;
|
2019-06-10 12:24:06 +03:00
|
|
|
}
|
2020-04-22 15:08:33 +03:00
|
|
|
this.startRegistration(payload.params || {});
|
2015-07-13 21:14:02 +03:00
|
|
|
break;
|
|
|
|
case 'start_login':
|
2019-07-05 01:51:55 +03:00
|
|
|
if (Lifecycle.isSoftLogout()) {
|
2020-04-22 15:08:33 +03:00
|
|
|
this.onSoftLogout();
|
2019-07-05 01:51:55 +03:00
|
|
|
break;
|
|
|
|
}
|
2019-06-10 12:24:06 +03:00
|
|
|
if (payload.screenAfterLogin) {
|
2020-04-22 15:08:33 +03:00
|
|
|
this.screenAfterLogin = payload.screenAfterLogin;
|
2019-06-10 12:24:06 +03:00
|
|
|
}
|
2017-06-09 19:18:45 +03:00
|
|
|
this.setStateForNewView({
|
2020-04-23 12:12:50 +03:00
|
|
|
view: Views.LOGIN,
|
2015-07-13 21:14:02 +03:00
|
|
|
});
|
2015-07-15 21:25:36 +03:00
|
|
|
this.notifyNewScreen('login');
|
2020-01-31 16:18:01 +03:00
|
|
|
ThemeController.isLogin = true;
|
2020-04-22 15:08:33 +03:00
|
|
|
this.themeWatcher.recheck();
|
2015-10-09 00:25:33 +03:00
|
|
|
break;
|
2015-11-20 14:57:04 +03:00
|
|
|
case 'start_post_registration':
|
2017-06-14 22:04:55 +03:00
|
|
|
this.setState({
|
2020-04-23 12:12:50 +03:00
|
|
|
view: Views.POST_REGISTRATION,
|
2015-11-20 14:57:04 +03:00
|
|
|
});
|
|
|
|
break;
|
2016-01-12 20:20:16 +03:00
|
|
|
case 'start_password_recovery':
|
2017-06-09 19:18:45 +03:00
|
|
|
this.setStateForNewView({
|
2020-04-23 12:12:50 +03:00
|
|
|
view: Views.FORGOT_PASSWORD,
|
2016-01-12 20:20:16 +03:00
|
|
|
});
|
|
|
|
this.notifyNewScreen('forgot_password');
|
2015-12-13 16:49:28 +03:00
|
|
|
break;
|
2017-06-01 16:16:25 +03:00
|
|
|
case 'start_chat':
|
|
|
|
createRoom({
|
|
|
|
dmUserId: payload.user_id,
|
2015-12-13 16:49:28 +03:00
|
|
|
});
|
2015-07-13 21:14:02 +03:00
|
|
|
break;
|
2015-12-13 16:49:28 +03:00
|
|
|
case 'leave_room':
|
2020-04-22 15:08:33 +03:00
|
|
|
this.leaveRoom(payload.room_id);
|
2015-07-13 21:14:02 +03:00
|
|
|
break;
|
2020-07-13 18:35:03 +03:00
|
|
|
case 'forget_room':
|
|
|
|
this.forgetRoom(payload.room_id);
|
|
|
|
break;
|
2017-03-09 20:03:57 +03:00
|
|
|
case 'reject_invite':
|
2017-07-27 19:19:18 +03:00
|
|
|
Modal.createTrackedDialog('Reject invitation', '', QuestionDialog, {
|
2017-05-23 17:16:31 +03:00
|
|
|
title: _t('Reject invitation'),
|
|
|
|
description: _t('Are you sure you want to reject the invitation?'),
|
2017-03-09 20:03:57 +03:00
|
|
|
onFinished: (confirm) => {
|
|
|
|
if (confirm) {
|
|
|
|
// FIXME: controller shouldn't be loading a view :(
|
|
|
|
const Loader = sdk.getComponent("elements.Spinner");
|
|
|
|
const modal = Modal.createDialog(Loader, null, 'mx_Dialog_spinner');
|
|
|
|
|
2019-11-18 13:03:05 +03:00
|
|
|
MatrixClientPeg.get().leave(payload.room_id).then(() => {
|
2017-03-09 20:03:57 +03:00
|
|
|
modal.close();
|
2017-06-16 13:27:47 +03:00
|
|
|
if (this.state.currentRoomId === payload.room_id) {
|
2017-03-09 20:03:57 +03:00
|
|
|
dis.dispatch({action: 'view_next_room'});
|
|
|
|
}
|
|
|
|
}, (err) => {
|
|
|
|
modal.close();
|
2017-08-10 15:49:11 +03:00
|
|
|
Modal.createTrackedDialog('Failed to reject invitation', '', ErrorDialog, {
|
2017-05-31 17:09:09 +03:00
|
|
|
title: _t('Failed to reject invitation'),
|
2017-05-19 15:53:11 +03:00
|
|
|
description: err.toString(),
|
2017-03-09 20:03:57 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
2017-05-19 15:53:11 +03:00
|
|
|
},
|
2017-03-09 20:03:57 +03:00
|
|
|
});
|
|
|
|
break;
|
2019-04-17 11:57:45 +03:00
|
|
|
case 'view_user_info':
|
2020-04-22 15:08:33 +03:00
|
|
|
this.viewUser(payload.userId, payload.subAction);
|
2019-04-17 11:57:45 +03:00
|
|
|
break;
|
2020-02-29 02:12:10 +03:00
|
|
|
case 'view_room': {
|
2016-06-14 14:56:37 +03: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.
|
2020-04-22 15:08:33 +03:00
|
|
|
const promise = this.viewRoom(payload);
|
2020-02-29 02:12:10 +03:00
|
|
|
if (payload.deferred_action) {
|
|
|
|
promise.then(() => {
|
|
|
|
dis.dispatch(payload.deferred_action);
|
|
|
|
});
|
|
|
|
}
|
2015-06-12 20:01:38 +03:00
|
|
|
break;
|
2020-02-29 02:12:10 +03:00
|
|
|
}
|
2015-06-25 19:41:55 +03:00
|
|
|
case 'view_next_room':
|
2020-04-22 15:08:33 +03:00
|
|
|
this.viewNextRoom(1);
|
2015-09-18 20:39:16 +03:00
|
|
|
break;
|
2020-05-14 06:07:19 +03:00
|
|
|
case Action.ViewUserSettings: {
|
2020-06-08 17:20:15 +03:00
|
|
|
const tabPayload = payload as OpenToTabPayload;
|
2019-02-04 23:25:26 +03:00
|
|
|
const UserSettingsDialog = sdk.getComponent("dialogs.UserSettingsDialog");
|
2020-06-08 17:20:15 +03:00
|
|
|
Modal.createTrackedDialog('User settings', '', UserSettingsDialog,
|
|
|
|
{initialTabId: tabPayload.initialTabId},
|
2020-08-29 03:11:08 +03:00
|
|
|
/*className=*/null, /*isPriority=*/false, /*isStatic=*/true);
|
2019-02-04 23:25:26 +03:00
|
|
|
|
2019-02-11 16:31:27 +03:00
|
|
|
// View the welcome or home page if we need something to look at
|
2020-04-22 15:08:33 +03:00
|
|
|
this.viewSomethingBehindModal();
|
2015-09-18 20:39:16 +03:00
|
|
|
break;
|
2019-01-22 03:49:48 +03:00
|
|
|
}
|
2015-09-18 20:39:16 +03:00
|
|
|
case 'view_create_room':
|
2020-05-12 12:55:46 +03:00
|
|
|
this.createRoom(payload.public);
|
2015-09-18 20:39:16 +03:00
|
|
|
break;
|
2017-11-28 15:08:53 +03:00
|
|
|
case 'view_create_group': {
|
2020-08-25 22:58:15 +03:00
|
|
|
let CreateGroupDialog = sdk.getComponent("dialogs.CreateGroupDialog")
|
|
|
|
if (SettingsStore.getValue("feature_communities_v2_prototypes")) {
|
2020-08-26 17:50:32 +03:00
|
|
|
CreateGroupDialog = CreateCommunityPrototypeDialog;
|
2020-08-25 22:58:15 +03:00
|
|
|
}
|
2017-11-28 15:08:53 +03:00
|
|
|
Modal.createTrackedDialog('Create Community', '', CreateGroupDialog);
|
2020-04-22 13:55:03 +03:00
|
|
|
break;
|
2017-11-28 15:08:53 +03:00
|
|
|
}
|
2020-06-09 05:33:21 +03:00
|
|
|
case Action.ViewRoomDirectory: {
|
2019-01-29 17:34:58 +03:00
|
|
|
const RoomDirectory = sdk.getComponent("structures.RoomDirectory");
|
2020-03-13 03:02:50 +03:00
|
|
|
Modal.createTrackedDialog('Room directory', '', RoomDirectory, {},
|
|
|
|
'mx_RoomDirectory_dialogWrapper', false, true);
|
2019-01-30 09:25:07 +03:00
|
|
|
|
2019-02-11 16:31:27 +03:00
|
|
|
// View the welcome or home page if we need something to look at
|
2020-04-22 15:08:33 +03:00
|
|
|
this.viewSomethingBehindModal();
|
2020-04-22 13:55:03 +03:00
|
|
|
break;
|
2019-01-29 17:40:19 +03:00
|
|
|
}
|
2017-06-28 15:56:18 +03:00
|
|
|
case 'view_my_groups':
|
2020-04-22 15:08:33 +03:00
|
|
|
this.setPage(PageTypes.MyGroups);
|
2017-06-28 15:56:18 +03:00
|
|
|
this.notifyNewScreen('groups');
|
|
|
|
break;
|
2017-06-05 18:51:50 +03:00
|
|
|
case 'view_group':
|
2020-04-22 15:08:33 +03:00
|
|
|
this.viewGroup(payload);
|
2017-06-05 18:51:50 +03:00
|
|
|
break;
|
2019-02-07 19:25:09 +03:00
|
|
|
case 'view_welcome_page':
|
2020-04-22 15:08:33 +03:00
|
|
|
this.viewWelcome();
|
2019-02-07 19:25:09 +03:00
|
|
|
break;
|
2016-11-13 17:10:46 +03:00
|
|
|
case 'view_home_page':
|
2020-11-02 20:24:47 +03:00
|
|
|
this.viewHome(payload.justRegistered);
|
2016-11-13 17:10:46 +03:00
|
|
|
break;
|
2017-06-01 16:16:25 +03:00
|
|
|
case 'view_start_chat_or_reuse':
|
2020-04-22 15:08:33 +03:00
|
|
|
this.chatCreateOrReuse(payload.user_id);
|
2017-06-01 16:16:25 +03:00
|
|
|
break;
|
2016-09-05 12:29:03 +03:00
|
|
|
case 'view_create_chat':
|
2017-11-10 13:51:28 +03:00
|
|
|
showStartChatInviteDialog();
|
2016-09-01 18:45:24 +03:00
|
|
|
break;
|
2016-09-13 16:28:03 +03:00
|
|
|
case 'view_invite':
|
2017-08-14 19:43:00 +03:00
|
|
|
showRoomInviteDialog(payload.roomId);
|
2016-09-13 16:28:03 +03:00
|
|
|
break;
|
2019-11-26 02:51:48 +03:00
|
|
|
case 'view_last_screen':
|
|
|
|
// This function does what we want, despite the name. The idea is that it shows
|
|
|
|
// the last room we were looking at or some reasonable default/guess. We don't
|
|
|
|
// have to worry about email invites or similar being re-triggered because the
|
|
|
|
// function will have cleared that state and not execute that path.
|
2020-04-22 15:08:33 +03:00
|
|
|
this.showScreenAfterLogin();
|
2019-11-26 02:51:48 +03:00
|
|
|
break;
|
|
|
|
case 'toggle_my_groups':
|
|
|
|
// We just dispatch the page change rather than have to worry about
|
|
|
|
// what the logic is for each of these branches.
|
|
|
|
if (this.state.page_type === PageTypes.MyGroups) {
|
|
|
|
dis.dispatch({action: 'view_last_screen'});
|
|
|
|
} else {
|
|
|
|
dis.dispatch({action: 'view_my_groups'});
|
|
|
|
}
|
|
|
|
break;
|
2015-10-11 15:49:44 +03:00
|
|
|
case 'hide_left_panel':
|
|
|
|
this.setState({
|
2017-08-25 14:10:13 +03:00
|
|
|
collapseLhs: true,
|
2020-07-16 08:05:53 +03:00
|
|
|
}, () => {
|
|
|
|
this.state.resizeNotifier.notifyLeftHandleResized();
|
2015-10-11 15:49:44 +03:00
|
|
|
});
|
|
|
|
break;
|
2020-03-29 22:33:27 +03:00
|
|
|
case 'focus_room_filter': // for CtrlOrCmd+K to work by expanding the left panel first
|
2015-10-11 15:49:44 +03:00
|
|
|
case 'show_left_panel':
|
|
|
|
this.setState({
|
2017-08-25 14:10:13 +03:00
|
|
|
collapseLhs: false,
|
2020-07-16 08:05:53 +03:00
|
|
|
}, () => {
|
|
|
|
this.state.resizeNotifier.notifyLeftHandleResized();
|
2015-10-11 15:49:44 +03:00
|
|
|
});
|
|
|
|
break;
|
2016-08-02 16:04:20 +03:00
|
|
|
case 'on_logged_in':
|
2020-01-16 00:13:56 +03:00
|
|
|
if (
|
|
|
|
!Lifecycle.isSoftLogout() &&
|
2020-04-23 12:12:50 +03:00
|
|
|
this.state.view !== Views.LOGIN &&
|
|
|
|
this.state.view !== Views.REGISTER &&
|
|
|
|
this.state.view !== Views.COMPLETE_SECURITY &&
|
|
|
|
this.state.view !== Views.E2E_SETUP
|
2020-01-16 00:13:56 +03:00
|
|
|
) {
|
2020-04-22 15:08:33 +03:00
|
|
|
this.onLoggedIn();
|
2019-07-04 01:46:37 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'on_client_not_viable':
|
2020-04-22 15:08:33 +03:00
|
|
|
this.onSoftLogout();
|
2016-08-02 16:04:20 +03:00
|
|
|
break;
|
|
|
|
case 'on_logged_out':
|
2020-04-22 15:08:33 +03:00
|
|
|
this.onLoggedOut();
|
2016-08-02 16:04:20 +03:00
|
|
|
break;
|
|
|
|
case 'will_start_client':
|
2017-06-23 12:48:21 +03:00
|
|
|
this.setState({ready: false}, () => {
|
|
|
|
// if the client is about to start, we are, by definition, not ready.
|
|
|
|
// Set ready to false now, then it'll be set to true when the sync
|
|
|
|
// listener we set below fires.
|
2020-04-22 15:08:33 +03:00
|
|
|
this.onWillStartClient();
|
2017-06-23 12:48:21 +03:00
|
|
|
});
|
2016-08-10 02:03:29 +03:00
|
|
|
break;
|
2017-11-05 06:13:23 +03:00
|
|
|
case 'client_started':
|
2020-04-22 15:08:33 +03:00
|
|
|
this.onClientStarted();
|
2017-11-05 06:13:23 +03:00
|
|
|
break;
|
2017-06-16 18:12:52 +03:00
|
|
|
case 'send_event':
|
|
|
|
this.onSendEvent(payload.room_id, payload.event);
|
|
|
|
break;
|
2018-02-09 00:51:07 +03:00
|
|
|
case 'aria_hide_main_app':
|
|
|
|
this.setState({
|
|
|
|
hideToSRUsers: true,
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
case 'aria_unhide_main_app':
|
|
|
|
this.setState({
|
|
|
|
hideToSRUsers: false,
|
|
|
|
});
|
|
|
|
break;
|
2018-05-15 15:15:40 +03:00
|
|
|
case 'accept_cookies':
|
|
|
|
SettingsStore.setValue("analyticsOptIn", null, SettingLevel.DEVICE, true);
|
|
|
|
SettingsStore.setValue("showCookieBar", null, SettingLevel.DEVICE, false);
|
2020-05-23 00:04:21 +03:00
|
|
|
hideAnalyticsToast();
|
2020-10-29 18:53:14 +03:00
|
|
|
if (Analytics.canEnable()) {
|
|
|
|
Analytics.enable();
|
|
|
|
}
|
|
|
|
if (CountlyAnalytics.instance.canEnable()) {
|
2020-10-30 17:27:14 +03:00
|
|
|
CountlyAnalytics.instance.enable(/* anonymous = */ false);
|
2020-10-29 18:53:14 +03:00
|
|
|
}
|
2018-05-15 15:15:40 +03:00
|
|
|
break;
|
|
|
|
case 'reject_cookies':
|
|
|
|
SettingsStore.setValue("analyticsOptIn", null, SettingLevel.DEVICE, false);
|
|
|
|
SettingsStore.setValue("showCookieBar", null, SettingLevel.DEVICE, false);
|
2020-05-23 00:04:21 +03:00
|
|
|
hideAnalyticsToast();
|
2018-05-15 15:15:40 +03:00
|
|
|
break;
|
2015-06-12 19:34:17 +03:00
|
|
|
}
|
2020-04-22 13:55:03 +03:00
|
|
|
};
|
2015-06-12 19:34:17 +03:00
|
|
|
|
2020-04-22 15:08:33 +03:00
|
|
|
private setPage(pageType: string) {
|
2015-12-11 00:53:14 +03:00
|
|
|
this.setState({
|
2015-12-14 14:07:59 +03:00
|
|
|
page_type: pageType,
|
2015-12-11 00:53:14 +03:00
|
|
|
});
|
2020-04-22 13:55:03 +03:00
|
|
|
}
|
2015-12-11 00:53:14 +03:00
|
|
|
|
2020-04-22 15:08:33 +03:00
|
|
|
private async startRegistration(params: {[key: string]: string}) {
|
|
|
|
const newState: Partial<IState> = {
|
2020-04-23 12:12:50 +03:00
|
|
|
view: Views.REGISTER,
|
2018-02-07 18:51:03 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
// Only honour params if they are all present, otherwise we reset
|
|
|
|
// HS and IS URLs when switching to registration.
|
|
|
|
if (params.client_secret &&
|
|
|
|
params.session_id &&
|
|
|
|
params.hs_url &&
|
|
|
|
params.is_url &&
|
|
|
|
params.sid
|
|
|
|
) {
|
2019-06-12 20:11:58 +03:00
|
|
|
newState.serverConfig = await AutoDiscoveryUtils.validateServerConfigWithStaticUrls(
|
|
|
|
params.hs_url, params.is_url,
|
|
|
|
);
|
|
|
|
|
2018-02-07 18:51:03 +03:00
|
|
|
newState.register_client_secret = params.client_secret;
|
|
|
|
newState.register_session_id = params.session_id;
|
|
|
|
newState.register_id_sid = params.sid;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.setStateForNewView(newState);
|
2020-01-31 16:18:01 +03:00
|
|
|
ThemeController.isLogin = true;
|
2020-04-22 15:08:33 +03:00
|
|
|
this.themeWatcher.recheck();
|
2017-05-19 15:53:11 +03:00
|
|
|
this.notifyNewScreen('register');
|
2020-04-22 13:55:03 +03:00
|
|
|
}
|
2017-05-19 15:53:11 +03:00
|
|
|
|
2017-05-25 19:10:49 +03:00
|
|
|
// TODO: Move to RoomViewStore
|
2020-04-22 15:08:33 +03:00
|
|
|
private viewNextRoom(roomIndexDelta: number) {
|
2017-05-19 15:53:11 +03:00
|
|
|
const allRooms = RoomListSorter.mostRecentActivityFirst(
|
|
|
|
MatrixClientPeg.get().getRooms(),
|
|
|
|
);
|
2017-06-09 12:54:42 +03:00
|
|
|
// If there are 0 rooms or 1 room, view the home page because otherwise
|
|
|
|
// if there are 0, we end up trying to index into an empty array, and
|
|
|
|
// if there is 1, we end up viewing the same room.
|
|
|
|
if (allRooms.length < 2) {
|
2017-06-09 12:28:45 +03:00
|
|
|
dis.dispatch({
|
|
|
|
action: 'view_home_page',
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
2017-05-19 15:53:11 +03:00
|
|
|
let roomIndex = -1;
|
|
|
|
for (let i = 0; i < allRooms.length; ++i) {
|
2020-04-22 15:22:33 +03:00
|
|
|
if (allRooms[i].roomId === this.state.currentRoomId) {
|
2017-05-19 15:53:11 +03:00
|
|
|
roomIndex = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
roomIndex = (roomIndex + roomIndexDelta) % allRooms.length;
|
|
|
|
if (roomIndex < 0) roomIndex = allRooms.length - 1;
|
2017-05-25 19:10:49 +03:00
|
|
|
dis.dispatch({
|
|
|
|
action: 'view_room',
|
|
|
|
room_id: allRooms[roomIndex].roomId,
|
|
|
|
});
|
2020-04-22 13:55:03 +03:00
|
|
|
}
|
2017-05-19 15:53:11 +03:00
|
|
|
|
2016-02-01 19:31:12 +03:00
|
|
|
// switch view to the given room
|
|
|
|
//
|
2017-05-31 17:09:09 +03:00
|
|
|
// @param {Object} roomInfo Object containing data about the room to be joined
|
|
|
|
// @param {string=} roomInfo.room_id ID of the room to join. One of room_id or room_alias must be given.
|
|
|
|
// @param {string=} roomInfo.room_alias Alias of the room to join. One of room_id or room_alias must be given.
|
|
|
|
// @param {boolean=} roomInfo.auto_join If true, automatically attempt to join the room if not already a member.
|
|
|
|
// @param {string=} roomInfo.event_id ID of the event in this room to show: this will cause a switch to the
|
2016-06-20 20:05:58 +03:00
|
|
|
// context of that particular event.
|
2017-06-08 17:32:31 +03:00
|
|
|
// @param {boolean=} roomInfo.highlighted If true, add event_id to the hash of the URL
|
2017-06-08 19:54:41 +03:00
|
|
|
// and alter the EventTile to appear highlighted.
|
2020-09-12 04:49:48 +03:00
|
|
|
// @param {Object=} roomInfo.threepid_invite Object containing data about the third party
|
|
|
|
// we received to join the room, if any.
|
2017-05-31 17:09:09 +03:00
|
|
|
// @param {Object=} roomInfo.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)
|
2020-04-22 15:08:33 +03:00
|
|
|
private viewRoom(roomInfo: IRoomInfo) {
|
2019-07-23 10:13:51 +03:00
|
|
|
this.focusComposer = true;
|
|
|
|
|
2017-06-08 00:41:02 +03:00
|
|
|
if (roomInfo.room_alias) {
|
|
|
|
console.log(
|
|
|
|
`Switching to room alias ${roomInfo.room_alias} at event ` +
|
2017-06-08 16:33:58 +03:00
|
|
|
roomInfo.event_id,
|
2017-06-08 00:41:02 +03:00
|
|
|
);
|
|
|
|
} else {
|
|
|
|
console.log(`Switching to room id ${roomInfo.room_id} at event ` +
|
2017-06-08 16:33:58 +03:00
|
|
|
roomInfo.event_id,
|
2017-06-08 00:41:02 +03:00
|
|
|
);
|
2016-02-01 19:31:12 +03:00
|
|
|
}
|
|
|
|
|
2017-04-06 13:30:47 +03:00
|
|
|
// Wait for the first sync to complete so that if a room does have an alias,
|
|
|
|
// it would have been retrieved.
|
2017-07-12 16:02:00 +03:00
|
|
|
let waitFor = Promise.resolve(null);
|
2017-04-06 13:44:15 +03:00
|
|
|
if (!this.firstSyncComplete) {
|
2017-04-06 13:30:47 +03:00
|
|
|
if (!this.firstSyncPromise) {
|
2017-05-31 17:09:09 +03:00
|
|
|
console.warn('Cannot view a room before first sync. room_id:', roomInfo.room_id);
|
2017-04-06 13:30:47 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
waitFor = this.firstSyncPromise.promise;
|
|
|
|
}
|
|
|
|
|
2020-02-29 02:12:10 +03:00
|
|
|
return waitFor.then(() => {
|
2017-05-31 17:09:09 +03:00
|
|
|
let presentedId = roomInfo.room_alias || roomInfo.room_id;
|
|
|
|
const room = MatrixClientPeg.get().getRoom(roomInfo.room_id);
|
2015-12-10 19:26:36 +03:00
|
|
|
if (room) {
|
2017-04-06 13:30:47 +03:00
|
|
|
const theAlias = Rooms.getDisplayAliasForRoom(room);
|
2019-11-12 14:43:18 +03:00
|
|
|
if (theAlias) {
|
|
|
|
presentedId = theAlias;
|
|
|
|
// Store display alias of the presented room in cache to speed future
|
|
|
|
// navigation.
|
|
|
|
storeRoomAliasInCache(theAlias, room.roomId);
|
|
|
|
}
|
2017-04-06 13:30:47 +03:00
|
|
|
|
|
|
|
// Store this as the ID of the last room accessed. This is so that we can
|
|
|
|
// persist which room is being stored across refreshes and browser quits.
|
|
|
|
if (localStorage) {
|
|
|
|
localStorage.setItem('mx_last_room_id', room.roomId);
|
|
|
|
}
|
2015-12-10 19:26:36 +03:00
|
|
|
}
|
2016-01-08 06:22:38 +03:00
|
|
|
|
2020-09-09 18:52:46 +03:00
|
|
|
// If we are redirecting to a Room Alias and it is for the room we already showing then replace history item
|
|
|
|
const replaceLast = presentedId[0] === "#" && roomInfo.room_id === this.state.currentRoomId;
|
|
|
|
|
2017-06-08 16:17:49 +03:00
|
|
|
if (roomInfo.event_id && roomInfo.highlighted) {
|
2017-05-31 17:09:09 +03:00
|
|
|
presentedId += "/" + roomInfo.event_id;
|
2016-02-01 19:31:12 +03:00
|
|
|
}
|
2020-04-22 15:08:33 +03:00
|
|
|
this.setState({
|
2020-04-23 12:12:50 +03:00
|
|
|
view: Views.LOGGED_IN,
|
2020-04-22 15:08:33 +03:00
|
|
|
currentRoomId: roomInfo.room_id || null,
|
|
|
|
page_type: PageTypes.RoomView,
|
2020-09-12 04:49:48 +03:00
|
|
|
threepidInvite: roomInfo.threepid_invite,
|
2020-04-22 15:08:33 +03:00
|
|
|
roomOobData: roomInfo.oob_data,
|
|
|
|
viaServers: roomInfo.via_servers,
|
|
|
|
ready: true,
|
|
|
|
}, () => {
|
2020-09-09 18:52:46 +03:00
|
|
|
this.notifyNewScreen('room/' + presentedId, replaceLast);
|
2019-09-24 03:51:21 +03:00
|
|
|
});
|
2017-04-06 13:30:47 +03:00
|
|
|
});
|
2020-04-22 13:55:03 +03:00
|
|
|
}
|
2015-12-10 19:26:36 +03:00
|
|
|
|
2020-05-25 13:29:06 +03:00
|
|
|
private async viewGroup(payload) {
|
2018-05-29 15:16:39 +03:00
|
|
|
const groupId = payload.group_id;
|
2020-05-25 13:29:06 +03:00
|
|
|
|
|
|
|
// Wait for the first sync to complete
|
|
|
|
if (!this.firstSyncComplete) {
|
|
|
|
if (!this.firstSyncPromise) {
|
|
|
|
console.warn('Cannot view a group before first sync. group_id:', groupId);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
await this.firstSyncPromise.promise;
|
|
|
|
}
|
|
|
|
|
2018-05-29 15:16:39 +03:00
|
|
|
this.setState({
|
2020-05-25 13:29:06 +03:00
|
|
|
view: Views.LOGGED_IN,
|
2018-05-29 15:16:39 +03:00
|
|
|
currentGroupId: groupId,
|
|
|
|
currentGroupIsNew: payload.group_is_new,
|
|
|
|
});
|
2020-04-22 15:08:33 +03:00
|
|
|
this.setPage(PageTypes.GroupView);
|
2018-05-29 15:16:39 +03:00
|
|
|
this.notifyNewScreen('group/' + groupId);
|
2020-04-22 13:55:03 +03:00
|
|
|
}
|
2018-05-29 15:16:39 +03:00
|
|
|
|
2020-04-22 15:08:33 +03:00
|
|
|
private viewSomethingBehindModal() {
|
2020-04-23 12:12:50 +03:00
|
|
|
if (this.state.view !== Views.LOGGED_IN) {
|
2020-04-22 15:08:33 +03:00
|
|
|
this.viewWelcome();
|
2019-02-11 16:31:27 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!this.state.currentGroupId && !this.state.currentRoomId) {
|
2020-04-22 15:08:33 +03:00
|
|
|
this.viewHome();
|
2019-02-11 16:31:27 +03:00
|
|
|
}
|
2020-04-22 13:55:03 +03:00
|
|
|
}
|
2019-02-11 16:31:27 +03:00
|
|
|
|
2020-04-22 15:08:33 +03:00
|
|
|
private viewWelcome() {
|
2019-02-07 19:25:09 +03:00
|
|
|
this.setStateForNewView({
|
2020-04-23 12:12:50 +03:00
|
|
|
view: Views.WELCOME,
|
2019-02-07 19:25:09 +03:00
|
|
|
});
|
|
|
|
this.notifyNewScreen('welcome');
|
2020-01-31 16:18:01 +03:00
|
|
|
ThemeController.isLogin = true;
|
2020-04-22 15:08:33 +03:00
|
|
|
this.themeWatcher.recheck();
|
2020-04-22 13:55:03 +03:00
|
|
|
}
|
2019-02-07 19:25:09 +03:00
|
|
|
|
2020-11-02 20:24:47 +03:00
|
|
|
private viewHome(justRegistered = false) {
|
2019-01-04 00:22:16 +03:00
|
|
|
// The home page requires the "logged in" view, so we'll set that.
|
Fix browser navigation not working between /home, /login, /register, etc
All of the anchors were pointed at `#` which, when clicked, would trigger a hash change in the browser. This change races the change made by the screen handling where the screen handling ends up losing. Because the hash is then tracked as empty rather than `#/login` (for example), the state machine considers future changes as no-ops and doesn't do anything with them.
By using `preventDefault` and `stopPropagation` on the anchor click events, we prevent the browser from automatically going to an empty hash, which then means the screen handling isn't racing the browser, and the hash change state machine doesn't no-op.
After applying that fix, going between pages worked great unless you were going from /login to /home. This is because the MatrixChat state machine was now out of sync (a `view` of `LOGIN` but a `page` of `HomePage` - an invalid state). All we have to do here is ensure the right view is used when navigating to the homepage.
Fixes https://github.com/vector-im/riot-web/issues/4061
Note: the concerns in 4061 about logging out upon entering the view appear to have been solved. Navigating to the login page doesn't obliterate your session, at least in my testing.
2018-12-21 03:26:13 +03:00
|
|
|
this.setStateForNewView({
|
2020-04-23 12:12:50 +03:00
|
|
|
view: Views.LOGGED_IN,
|
2020-11-02 20:24:47 +03:00
|
|
|
justRegistered,
|
Fix browser navigation not working between /home, /login, /register, etc
All of the anchors were pointed at `#` which, when clicked, would trigger a hash change in the browser. This change races the change made by the screen handling where the screen handling ends up losing. Because the hash is then tracked as empty rather than `#/login` (for example), the state machine considers future changes as no-ops and doesn't do anything with them.
By using `preventDefault` and `stopPropagation` on the anchor click events, we prevent the browser from automatically going to an empty hash, which then means the screen handling isn't racing the browser, and the hash change state machine doesn't no-op.
After applying that fix, going between pages worked great unless you were going from /login to /home. This is because the MatrixChat state machine was now out of sync (a `view` of `LOGIN` but a `page` of `HomePage` - an invalid state). All we have to do here is ensure the right view is used when navigating to the homepage.
Fixes https://github.com/vector-im/riot-web/issues/4061
Note: the concerns in 4061 about logging out upon entering the view appear to have been solved. Navigating to the login page doesn't obliterate your session, at least in my testing.
2018-12-21 03:26:13 +03:00
|
|
|
});
|
2020-04-22 15:08:33 +03:00
|
|
|
this.setPage(PageTypes.HomePage);
|
2018-05-29 15:16:39 +03:00
|
|
|
this.notifyNewScreen('home');
|
2020-01-31 16:18:01 +03:00
|
|
|
ThemeController.isLogin = false;
|
2020-04-22 15:08:33 +03:00
|
|
|
this.themeWatcher.recheck();
|
2020-04-22 13:55:03 +03:00
|
|
|
}
|
2018-05-29 15:16:39 +03:00
|
|
|
|
2020-04-22 15:08:33 +03:00
|
|
|
private viewUser(userId: string, subAction: string) {
|
2019-04-17 11:57:45 +03:00
|
|
|
// Wait for the first sync so that `getRoom` gives us a room object if it's
|
|
|
|
// in the sync response
|
2019-04-17 19:23:49 +03:00
|
|
|
const waitForSync = this.firstSyncPromise ?
|
2019-04-17 11:57:45 +03:00
|
|
|
this.firstSyncPromise.promise : Promise.resolve();
|
2019-04-17 19:23:49 +03:00
|
|
|
waitForSync.then(() => {
|
2019-04-17 19:26:07 +03:00
|
|
|
if (subAction === 'chat') {
|
2020-04-22 15:08:33 +03:00
|
|
|
this.chatCreateOrReuse(userId);
|
2019-04-17 11:57:45 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.notifyNewScreen('user/' + userId);
|
|
|
|
this.setState({currentUserId: userId});
|
2020-04-22 15:08:33 +03:00
|
|
|
this.setPage(PageTypes.UserView);
|
2019-04-17 11:57:45 +03:00
|
|
|
});
|
2020-04-22 13:55:03 +03:00
|
|
|
}
|
2019-04-17 11:57:45 +03:00
|
|
|
|
2020-05-12 12:55:46 +03:00
|
|
|
private async createRoom(defaultPublic = false) {
|
2020-09-19 01:04:19 +03:00
|
|
|
const communityId = CommunityPrototypeStore.instance.getSelectedCommunityId();
|
|
|
|
if (communityId) {
|
|
|
|
// double check the user will have permission to associate this room with the community
|
2020-10-01 22:44:16 +03:00
|
|
|
if (!CommunityPrototypeStore.instance.isAdminOf(communityId)) {
|
2020-09-19 01:04:19 +03:00
|
|
|
Modal.createTrackedDialog('Pre-failure to create room', '', ErrorDialog, {
|
|
|
|
title: _t("Cannot create rooms in this community"),
|
|
|
|
description: _t("You do not have permission to create rooms in this community."),
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-17 15:33:07 +03:00
|
|
|
const CreateRoomDialog = sdk.getComponent('dialogs.CreateRoomDialog');
|
2020-05-12 12:55:46 +03:00
|
|
|
const modal = Modal.createTrackedDialog('Create Room', '', CreateRoomDialog, { defaultPublic });
|
2019-08-09 18:47:22 +03:00
|
|
|
|
2020-01-23 16:54:28 +03:00
|
|
|
const [shouldCreate, opts] = await modal.finished;
|
2019-08-09 18:47:22 +03:00
|
|
|
if (shouldCreate) {
|
2020-01-23 16:54:28 +03:00
|
|
|
createRoom(opts);
|
2019-08-09 18:47:22 +03:00
|
|
|
}
|
2020-04-22 13:55:03 +03:00
|
|
|
}
|
2017-06-05 19:45:01 +03:00
|
|
|
|
2020-04-22 15:08:33 +03:00
|
|
|
private chatCreateOrReuse(userId: string) {
|
2017-06-02 13:42:47 +03:00
|
|
|
// Use a deferred action to reshow the dialog once the user has registered
|
2017-06-01 16:16:25 +03:00
|
|
|
if (MatrixClientPeg.get().isGuest()) {
|
2017-06-05 15:14:55 +03:00
|
|
|
// No point in making 2 DMs with welcome bot. This assumes view_set_mxid will
|
|
|
|
// result in a new DM with the welcome user.
|
|
|
|
if (userId !== this.props.config.welcomeUserId) {
|
|
|
|
dis.dispatch({
|
|
|
|
action: 'do_after_sync_prepared',
|
|
|
|
deferred_action: {
|
|
|
|
action: 'view_start_chat_or_reuse',
|
|
|
|
user_id: userId,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
2017-06-01 16:16:25 +03:00
|
|
|
dis.dispatch({
|
2018-09-05 19:07:39 +03:00
|
|
|
action: 'require_registration',
|
2019-02-08 15:12:43 +03:00
|
|
|
// If the set_mxid dialog is cancelled, view /welcome because if the
|
|
|
|
// browser was pointing at /user/@someone:domain?action=chat, the URL
|
|
|
|
// needs to be reset so that they can revisit /user/.. // (and trigger
|
2017-06-09 15:46:45 +03:00
|
|
|
// `_chatCreateOrReuse` again)
|
2019-02-08 15:12:43 +03:00
|
|
|
go_welcome_on_cancel: true,
|
2020-02-28 13:47:23 +03:00
|
|
|
screen_after: {
|
|
|
|
screen: `user/${this.props.config.welcomeUserId}`,
|
|
|
|
params: { action: 'chat' },
|
|
|
|
},
|
2017-06-01 16:16:25 +03:00
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-08-07 21:13:59 +03:00
|
|
|
// TODO: Immutable DMs replaces this
|
|
|
|
|
|
|
|
const client = MatrixClientPeg.get();
|
|
|
|
const dmRoomMap = new DMRoomMap(client);
|
|
|
|
const dmRooms = dmRoomMap.getDMRoomsForUserId(userId);
|
|
|
|
|
|
|
|
if (dmRooms.length > 0) {
|
|
|
|
dis.dispatch({
|
|
|
|
action: 'view_room',
|
|
|
|
room_id: dmRooms[0],
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
dis.dispatch({
|
|
|
|
action: 'start_chat',
|
|
|
|
user_id: userId,
|
|
|
|
});
|
|
|
|
}
|
2020-04-22 13:55:03 +03:00
|
|
|
}
|
2017-06-01 16:16:25 +03:00
|
|
|
|
2020-04-22 15:08:33 +03:00
|
|
|
private leaveRoomWarnings(roomId: string) {
|
2018-01-20 01:27:48 +03:00
|
|
|
const roomToLeave = MatrixClientPeg.get().getRoom(roomId);
|
|
|
|
// Show a warning if there are additional complications.
|
|
|
|
const warnings = [];
|
2020-11-11 00:04:01 +03:00
|
|
|
|
|
|
|
const memberCount = roomToLeave.currentState.getJoinedMemberCount();
|
|
|
|
if (memberCount === 1) {
|
|
|
|
warnings.push(
|
|
|
|
<span className="warning" key="only_member_warning">
|
|
|
|
{' '/* Whitespace, otherwise the sentences get smashed together */ }
|
|
|
|
{ _t("You are the only member of this room. This room will become unjoinable if you leave.") }
|
|
|
|
</span>
|
|
|
|
);
|
|
|
|
|
|
|
|
return warnings;
|
|
|
|
}
|
|
|
|
|
|
|
|
const joinRules = roomToLeave.currentState.getStateEvents('m.room.join_rules', '');
|
2018-01-20 01:27:48 +03:00
|
|
|
if (joinRules) {
|
|
|
|
const rule = joinRules.getContent().join_rule;
|
|
|
|
if (rule !== "public") {
|
|
|
|
warnings.push((
|
|
|
|
<span className="warning" key="non_public_warning">
|
2018-05-22 11:28:41 +03:00
|
|
|
{' '/* Whitespace, otherwise the sentences get smashed together */ }
|
2018-01-20 01:27:48 +03:00
|
|
|
{ _t("This room is not public. You will not be able to rejoin without an invite.") }
|
|
|
|
</span>
|
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return warnings;
|
2020-04-22 13:55:03 +03:00
|
|
|
}
|
2018-01-20 01:27:48 +03:00
|
|
|
|
2020-04-22 15:08:33 +03:00
|
|
|
private leaveRoom(roomId: string) {
|
2017-05-19 15:53:11 +03:00
|
|
|
const QuestionDialog = sdk.getComponent("dialogs.QuestionDialog");
|
|
|
|
const roomToLeave = MatrixClientPeg.get().getRoom(roomId);
|
2020-04-22 15:08:33 +03:00
|
|
|
const warnings = this.leaveRoomWarnings(roomId);
|
2020-11-11 00:04:01 +03:00
|
|
|
const hasWarnings = warnings.length > 0;
|
2018-01-20 01:27:48 +03:00
|
|
|
|
2017-07-27 19:19:18 +03:00
|
|
|
Modal.createTrackedDialog('Leave room', '', QuestionDialog, {
|
2017-06-02 12:47:08 +03:00
|
|
|
title: _t("Leave room"),
|
|
|
|
description: (
|
|
|
|
<span>
|
2020-08-29 03:11:08 +03:00
|
|
|
{ _t("Are you sure you want to leave the room '%(roomName)s'?", {roomName: roomToLeave.name}) }
|
2020-04-22 13:55:03 +03:00
|
|
|
{ warnings }
|
2017-06-02 12:47:08 +03:00
|
|
|
</span>
|
|
|
|
),
|
2018-10-23 04:55:21 +03:00
|
|
|
button: _t("Leave"),
|
2020-11-11 00:04:01 +03:00
|
|
|
danger: hasWarnings,
|
2017-05-19 15:53:11 +03:00
|
|
|
onFinished: (shouldLeave) => {
|
|
|
|
if (shouldLeave) {
|
2020-08-20 04:21:40 +03:00
|
|
|
const d = leaveRoomBehaviour(roomId);
|
2017-05-19 15:53:11 +03:00
|
|
|
|
|
|
|
// FIXME: controller shouldn't be loading a view :(
|
|
|
|
const Loader = sdk.getComponent("elements.Spinner");
|
|
|
|
const modal = Modal.createDialog(Loader, null, 'mx_Dialog_spinner');
|
|
|
|
|
2020-08-20 04:21:40 +03:00
|
|
|
d.finally(() => modal.close());
|
2017-05-19 15:53:11 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
});
|
2020-04-22 13:55:03 +03:00
|
|
|
}
|
2016-08-10 02:03:29 +03:00
|
|
|
|
2020-07-13 18:35:03 +03:00
|
|
|
private forgetRoom(roomId: string) {
|
|
|
|
MatrixClientPeg.get().forget(roomId).then(() => {
|
|
|
|
// Switch to another room view if we're currently viewing the historical room
|
|
|
|
if (this.state.currentRoomId === roomId) {
|
|
|
|
dis.dispatch({ action: "view_next_room" });
|
|
|
|
}
|
2020-07-13 19:01:50 +03:00
|
|
|
}).catch((err) => {
|
2020-07-13 18:35:03 +03:00
|
|
|
const errCode = err.errcode || _td("unknown error code");
|
|
|
|
Modal.createTrackedDialog("Failed to forget room", '', ErrorDialog, {
|
|
|
|
title: _t("Failed to forget room %(errCode)s", {errCode}),
|
|
|
|
description: ((err && err.message) ? err.message : _t("Operation failed")),
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-06-14 18:29:26 +03:00
|
|
|
/**
|
|
|
|
* Starts a chat with the welcome user, if the user doesn't already have one
|
|
|
|
* @returns {string} The room ID of the new room, or null if no room was created
|
|
|
|
*/
|
2020-04-22 15:08:33 +03:00
|
|
|
private async startWelcomeUserChat() {
|
2019-06-14 18:29:26 +03:00
|
|
|
// We can end up with multiple tabs post-registration where the user
|
|
|
|
// might then end up with a session and we don't want them all making
|
|
|
|
// a chat with the welcome user: try to de-dupe.
|
|
|
|
// We need to wait for the first sync to complete for this to
|
|
|
|
// work though.
|
|
|
|
let waitFor;
|
|
|
|
if (!this.firstSyncComplete) {
|
|
|
|
waitFor = this.firstSyncPromise.promise;
|
|
|
|
} else {
|
|
|
|
waitFor = Promise.resolve();
|
|
|
|
}
|
|
|
|
await waitFor;
|
|
|
|
|
|
|
|
const welcomeUserRooms = DMRoomMap.shared().getDMRoomsForUserId(
|
|
|
|
this.props.config.welcomeUserId,
|
|
|
|
);
|
|
|
|
if (welcomeUserRooms.length === 0) {
|
|
|
|
const roomId = await createRoom({
|
|
|
|
dmUserId: this.props.config.welcomeUserId,
|
|
|
|
// Only view the welcome user if we're NOT looking at a room
|
|
|
|
andView: !this.state.currentRoomId,
|
2019-06-14 19:21:07 +03:00
|
|
|
spinner: false, // we're already showing one: we don't need another one
|
2019-06-14 18:29:26 +03:00
|
|
|
});
|
|
|
|
// This is a bit of a hack, but since the deduplication relies
|
|
|
|
// on m.direct being up to date, we need to force a sync
|
|
|
|
// of the database, otherwise if the user goes to the other
|
|
|
|
// tab before the next save happens (a few minutes), the
|
|
|
|
// saved sync will be restored from the db and this code will
|
|
|
|
// run without the update to m.direct, making another welcome
|
|
|
|
// user room (it doesn't wait for new data from the server, just
|
|
|
|
// the saved sync to be loaded).
|
|
|
|
const saveWelcomeUser = (ev) => {
|
|
|
|
if (
|
2020-04-22 15:22:33 +03:00
|
|
|
ev.getType() === 'm.direct' &&
|
2019-06-14 18:29:26 +03:00
|
|
|
ev.getContent() &&
|
|
|
|
ev.getContent()[this.props.config.welcomeUserId]
|
|
|
|
) {
|
|
|
|
MatrixClientPeg.get().store.save(true);
|
|
|
|
MatrixClientPeg.get().removeListener(
|
|
|
|
"accountData", saveWelcomeUser,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
MatrixClientPeg.get().on("accountData", saveWelcomeUser);
|
|
|
|
|
|
|
|
return roomId;
|
|
|
|
}
|
|
|
|
return null;
|
2020-04-22 13:55:03 +03:00
|
|
|
}
|
2019-06-14 18:29:26 +03:00
|
|
|
|
2016-08-02 21:05:05 +03:00
|
|
|
/**
|
|
|
|
* Called when a new logged in session has started
|
|
|
|
*/
|
2020-04-22 15:08:33 +03:00
|
|
|
private async onLoggedIn() {
|
2020-02-21 17:54:56 +03:00
|
|
|
ThemeController.isLogin = false;
|
2020-04-30 19:41:14 +03:00
|
|
|
this.themeWatcher.recheck();
|
2020-04-23 12:12:50 +03:00
|
|
|
this.setStateForNewView({ view: Views.LOGGED_IN });
|
2020-01-19 02:23:46 +03:00
|
|
|
// If a specific screen is set to be shown after login, show that above
|
|
|
|
// all else, as it probably means the user clicked on something already.
|
2020-04-22 15:08:33 +03:00
|
|
|
if (this.screenAfterLogin && this.screenAfterLogin.screen) {
|
2020-01-19 02:23:46 +03:00
|
|
|
this.showScreen(
|
2020-04-22 15:08:33 +03:00
|
|
|
this.screenAfterLogin.screen,
|
|
|
|
this.screenAfterLogin.params,
|
2020-01-19 02:23:46 +03:00
|
|
|
);
|
2020-04-22 15:08:33 +03:00
|
|
|
this.screenAfterLogin = null;
|
2020-01-19 02:23:46 +03:00
|
|
|
} else if (MatrixClientPeg.currentUserIsJustRegistered()) {
|
2019-06-14 17:31:19 +03:00
|
|
|
MatrixClientPeg.setJustRegisteredUserId(null);
|
2017-05-26 13:46:33 +03:00
|
|
|
|
2017-06-02 16:13:33 +03:00
|
|
|
if (this.props.config.welcomeUserId && getCurrentLanguage().startsWith("en")) {
|
2020-04-22 15:08:33 +03:00
|
|
|
const welcomeUserRoom = await this.startWelcomeUserChat();
|
2019-06-14 18:29:26 +03:00
|
|
|
if (welcomeUserRoom === null) {
|
2020-01-16 00:13:56 +03:00
|
|
|
// We didn't redirect to the welcome user room, so show
|
2019-06-14 18:04:09 +03:00
|
|
|
// the homepage.
|
2020-11-02 20:24:47 +03:00
|
|
|
dis.dispatch({action: 'view_home_page', justRegistered: true});
|
2019-06-14 18:29:26 +03:00
|
|
|
}
|
2020-09-12 05:20:33 +03:00
|
|
|
} else if (ThreepidInviteStore.instance.pickBestInvite()) {
|
|
|
|
// The user has a 3pid invite pending - show them that
|
|
|
|
const threepidInvite = ThreepidInviteStore.instance.pickBestInvite();
|
|
|
|
|
|
|
|
// HACK: This is a pretty brutal way of threading the invite back through
|
|
|
|
// our systems, but it's the safest we have for now.
|
|
|
|
const params = ThreepidInviteStore.instance.translateToWireFormat(threepidInvite);
|
|
|
|
this.showScreen(`room/${threepidInvite.roomId}`, params)
|
2019-06-14 18:04:09 +03:00
|
|
|
} else {
|
|
|
|
// The user has just logged in after registering,
|
|
|
|
// so show the homepage.
|
2020-11-02 20:24:47 +03:00
|
|
|
dis.dispatch({action: 'view_home_page', justRegistered: true});
|
2017-05-12 19:39:38 +03:00
|
|
|
}
|
2017-03-15 15:02:08 +03:00
|
|
|
} else {
|
2020-04-22 15:08:33 +03:00
|
|
|
this.showScreenAfterLogin();
|
2017-03-15 15:02:08 +03:00
|
|
|
}
|
2020-02-20 03:38:08 +03:00
|
|
|
|
|
|
|
StorageManager.tryPersistStorage();
|
2020-05-23 00:04:21 +03:00
|
|
|
|
2020-11-02 20:25:48 +03:00
|
|
|
// defer the following actions by 30 seconds to not throw them at the user immediately
|
|
|
|
await sleep(30);
|
2020-10-29 18:53:14 +03:00
|
|
|
if (SettingsStore.getValue("showCookieBar") &&
|
|
|
|
(Analytics.canEnable() || CountlyAnalytics.instance.canEnable())
|
|
|
|
) {
|
2020-09-16 12:29:21 +03:00
|
|
|
showAnalyticsToast(this.props.config.piwik?.policyUrl);
|
2020-05-23 00:04:21 +03:00
|
|
|
}
|
2020-04-22 13:55:03 +03:00
|
|
|
}
|
2017-03-15 15:02:08 +03:00
|
|
|
|
2020-04-22 15:08:33 +03:00
|
|
|
private showScreenAfterLogin() {
|
2017-03-08 13:25:54 +03:00
|
|
|
// If screenAfterLogin is set, use that, then null it so that a second login will
|
|
|
|
// result in view_home_page, _user_settings or _room_directory
|
2020-04-22 15:08:33 +03:00
|
|
|
if (this.screenAfterLogin && this.screenAfterLogin.screen) {
|
2017-03-08 13:25:54 +03:00
|
|
|
this.showScreen(
|
2020-04-22 15:08:33 +03:00
|
|
|
this.screenAfterLogin.screen,
|
|
|
|
this.screenAfterLogin.params,
|
2017-03-08 13:25:54 +03:00
|
|
|
);
|
2020-04-22 15:08:33 +03:00
|
|
|
this.screenAfterLogin = null;
|
2017-04-06 13:30:47 +03:00
|
|
|
} else if (localStorage && localStorage.getItem('mx_last_room_id')) {
|
|
|
|
// Before defaulting to directory, show the last viewed room
|
2020-04-22 15:08:33 +03:00
|
|
|
this.viewLastRoom();
|
2017-03-08 18:11:38 +03:00
|
|
|
} else {
|
2019-02-08 18:43:17 +03:00
|
|
|
if (MatrixClientPeg.get().isGuest()) {
|
2019-02-08 15:12:43 +03:00
|
|
|
dis.dispatch({action: 'view_welcome_page'});
|
2019-02-14 15:52:38 +03:00
|
|
|
} else if (getHomePageUrl(this.props.config)) {
|
2019-02-08 15:12:43 +03:00
|
|
|
dis.dispatch({action: 'view_home_page'});
|
2019-02-14 15:35:09 +03:00
|
|
|
} else {
|
|
|
|
this.firstSyncPromise.promise.then(() => {
|
|
|
|
dis.dispatch({action: 'view_next_room'});
|
|
|
|
});
|
2019-02-08 15:12:43 +03:00
|
|
|
}
|
2017-02-28 18:05:49 +03:00
|
|
|
}
|
2020-04-22 13:55:03 +03:00
|
|
|
}
|
2015-06-12 16:59:33 +03:00
|
|
|
|
2020-04-22 15:08:33 +03:00
|
|
|
private viewLastRoom() {
|
2019-07-08 21:43:16 +03:00
|
|
|
dis.dispatch({
|
|
|
|
action: 'view_room',
|
|
|
|
room_id: localStorage.getItem('mx_last_room_id'),
|
|
|
|
});
|
2020-04-22 13:55:03 +03:00
|
|
|
}
|
2019-07-08 21:43:16 +03:00
|
|
|
|
2016-08-02 21:05:05 +03:00
|
|
|
/**
|
|
|
|
* Called when the session is logged out
|
|
|
|
*/
|
2020-04-22 15:08:33 +03:00
|
|
|
private onLoggedOut() {
|
2016-08-02 16:04:20 +03:00
|
|
|
this.notifyNewScreen('login');
|
2017-06-09 19:18:45 +03:00
|
|
|
this.setStateForNewView({
|
2020-04-23 12:12:50 +03:00
|
|
|
view: Views.LOGIN,
|
2016-08-02 16:04:20 +03:00
|
|
|
ready: false,
|
2017-08-25 14:10:13 +03:00
|
|
|
collapseLhs: false,
|
2016-11-24 17:58:37 +03:00
|
|
|
currentRoomId: null,
|
2016-08-02 16:04:20 +03:00
|
|
|
});
|
2019-09-24 00:01:49 +03:00
|
|
|
this.subTitleStatus = '';
|
2020-04-22 15:08:33 +03:00
|
|
|
this.setPageSubtitle();
|
2020-01-31 16:18:01 +03:00
|
|
|
ThemeController.isLogin = true;
|
2020-04-22 15:08:33 +03:00
|
|
|
this.themeWatcher.recheck();
|
2020-04-22 13:55:03 +03:00
|
|
|
}
|
2016-08-02 16:04:20 +03:00
|
|
|
|
2019-07-04 01:46:37 +03:00
|
|
|
/**
|
|
|
|
* Called when the session is softly logged out
|
|
|
|
*/
|
2020-04-22 15:08:33 +03:00
|
|
|
private onSoftLogout() {
|
2019-07-04 01:46:37 +03:00
|
|
|
this.notifyNewScreen('soft_logout');
|
|
|
|
this.setStateForNewView({
|
2020-04-23 12:12:50 +03:00
|
|
|
view: Views.SOFT_LOGOUT,
|
2019-07-04 01:46:37 +03:00
|
|
|
ready: false,
|
|
|
|
collapseLhs: false,
|
|
|
|
currentRoomId: null,
|
|
|
|
});
|
2019-09-24 00:01:49 +03:00
|
|
|
this.subTitleStatus = '';
|
2020-04-22 15:08:33 +03:00
|
|
|
this.setPageSubtitle();
|
2020-04-22 13:55:03 +03:00
|
|
|
}
|
2019-07-04 01:46:37 +03:00
|
|
|
|
2016-08-02 21:05:05 +03:00
|
|
|
/**
|
|
|
|
* Called just before the matrix client is started
|
2016-08-03 11:53:02 +03:00
|
|
|
* (useful for setting listeners)
|
2016-08-02 21:05:05 +03:00
|
|
|
*/
|
2020-04-22 15:08:33 +03:00
|
|
|
private onWillStartClient() {
|
2017-06-21 13:27:18 +03:00
|
|
|
// reset the 'have completed first sync' flag,
|
|
|
|
// since we're about to start the client and therefore about
|
|
|
|
// to do the first sync
|
|
|
|
this.firstSyncComplete = false;
|
2019-11-12 14:45:28 +03:00
|
|
|
this.firstSyncPromise = defer();
|
2017-05-19 15:53:11 +03:00
|
|
|
const cli = MatrixClientPeg.get();
|
2016-08-02 16:04:20 +03:00
|
|
|
|
2017-03-22 18:06:52 +03:00
|
|
|
// Allow the JS SDK to reap timeline events. This reduces the amount of
|
|
|
|
// memory consumed as the JS SDK stores multiple distinct copies of room
|
|
|
|
// state (each of which can be 10s of MBs) for each DISJOINT timeline. This is
|
|
|
|
// particularly noticeable when there are lots of 'limited' /sync responses
|
|
|
|
// such as when laptops unsleep.
|
2020-08-03 18:02:26 +03:00
|
|
|
// https://github.com/vector-im/element-web/issues/3307#issuecomment-282895568
|
2020-04-22 15:08:33 +03:00
|
|
|
cli.setCanResetTimelineCallback((roomId) => {
|
|
|
|
console.log("Request to reset timeline in room ", roomId, " viewing:", this.state.currentRoomId);
|
|
|
|
if (roomId !== this.state.currentRoomId) {
|
2017-03-22 18:06:52 +03:00
|
|
|
// It is safe to remove events from rooms we are not viewing.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
// We are viewing the room which we want to reset. It is only safe to do
|
|
|
|
// this if we are not scrolled up in the view. To find out, delegate to
|
|
|
|
// the timeline panel. If the timeline panel doesn't exist, then we assume
|
|
|
|
// it is safe to reset the timeline.
|
2020-05-07 12:02:40 +03:00
|
|
|
if (!this.loggedInView.current) {
|
2017-03-22 18:06:52 +03:00
|
|
|
return true;
|
|
|
|
}
|
2020-04-22 15:08:33 +03:00
|
|
|
return this.loggedInView.current.canResetTimelineInRoom(roomId);
|
2017-03-22 18:06:52 +03:00
|
|
|
});
|
|
|
|
|
2020-04-22 15:08:33 +03:00
|
|
|
cli.on('sync', (state, prevState, data) => {
|
2017-05-25 11:30:57 +03:00
|
|
|
// LifecycleStore and others cannot directly subscribe to matrix client for
|
|
|
|
// events because flux only allows store state changes during flux dispatches.
|
|
|
|
// So dispatch directly from here. Ideally we'd use a SyncStateStore that
|
|
|
|
// would do this dispatch and expose the sync state itself (by listening to
|
|
|
|
// its own dispatch).
|
2017-05-24 18:56:13 +03:00
|
|
|
dis.dispatch({action: 'sync_state', prevState, state});
|
2018-09-07 14:18:25 +03:00
|
|
|
|
2018-09-27 23:31:55 +03:00
|
|
|
if (state === "ERROR" || state === "RECONNECTING") {
|
2020-04-22 15:08:33 +03:00
|
|
|
if (data.error instanceof InvalidStoreError) {
|
2018-10-10 19:07:17 +03:00
|
|
|
Lifecycle.handleInvalidStoreError(data.error);
|
|
|
|
}
|
2020-04-22 15:08:33 +03:00
|
|
|
this.setState({syncError: data.error || true});
|
|
|
|
} else if (this.state.syncError) {
|
|
|
|
this.setState({syncError: null});
|
2018-09-07 14:18:25 +03:00
|
|
|
}
|
|
|
|
|
2020-04-22 15:08:33 +03:00
|
|
|
this.updateStatusIndicator(state, prevState);
|
2015-12-15 17:23:58 +03:00
|
|
|
if (state === "SYNCING" && prevState === "SYNCING") {
|
|
|
|
return;
|
|
|
|
}
|
2019-11-26 04:14:03 +03:00
|
|
|
console.info("MatrixClient sync state => %s", state);
|
2015-11-12 18:15:00 +03:00
|
|
|
if (state !== "PREPARED") { return; }
|
2015-09-25 19:22:42 +03:00
|
|
|
|
2020-04-22 15:08:33 +03:00
|
|
|
this.firstSyncComplete = true;
|
|
|
|
this.firstSyncPromise.resolve();
|
2015-09-25 19:22:42 +03:00
|
|
|
|
2020-11-02 20:25:48 +03:00
|
|
|
if (Notifier.shouldShowPrompt() && !MatrixClientPeg.userRegisteredWithinLastHours(24)) {
|
|
|
|
showNotificationsToast(false);
|
2020-05-28 21:03:42 +03:00
|
|
|
}
|
|
|
|
|
2020-06-03 04:07:46 +03:00
|
|
|
dis.fire(Action.FocusComposer);
|
2020-04-22 15:08:33 +03:00
|
|
|
this.setState({
|
2019-03-29 18:19:39 +03:00
|
|
|
ready: true,
|
|
|
|
});
|
2015-06-12 16:59:33 +03:00
|
|
|
});
|
2020-09-16 15:44:24 +03:00
|
|
|
|
|
|
|
if (SettingsStore.getValue(UIFeature.Voip)) {
|
|
|
|
cli.on('Call.incoming', function(call) {
|
|
|
|
// we dispatch this synchronously to make sure that the event
|
|
|
|
// handlers on the call are set up immediately (so that if
|
|
|
|
// we get an immediate hangup, we don't get a stuck call)
|
|
|
|
dis.dispatch({
|
|
|
|
action: 'incoming_call',
|
|
|
|
call: call,
|
|
|
|
}, true);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-07-04 01:46:37 +03:00
|
|
|
cli.on('Session.logged_out', function(errObj) {
|
2018-07-16 00:33:00 +03:00
|
|
|
if (Lifecycle.isLoggingOut()) return;
|
2019-07-04 01:46:37 +03:00
|
|
|
|
|
|
|
if (errObj.httpStatus === 401 && errObj.data && errObj.data['soft_logout']) {
|
|
|
|
console.warn("Soft logout issued by server - avoiding data deletion");
|
|
|
|
Lifecycle.softLogout();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-07-27 19:19:18 +03:00
|
|
|
Modal.createTrackedDialog('Signed out', '', ErrorDialog, {
|
2017-05-23 17:16:31 +03:00
|
|
|
title: _t('Signed Out'),
|
|
|
|
description: _t('For security, this session has been signed out. Please sign in again.'),
|
2016-03-15 13:48:16 +03:00
|
|
|
});
|
|
|
|
dis.dispatch({
|
2017-05-19 15:53:11 +03:00
|
|
|
action: 'logout',
|
2016-03-15 13:48:16 +03:00
|
|
|
});
|
|
|
|
});
|
2018-05-22 17:47:31 +03:00
|
|
|
cli.on('no_consent', function(message, consentUri) {
|
|
|
|
const QuestionDialog = sdk.getComponent("dialogs.QuestionDialog");
|
|
|
|
Modal.createTrackedDialog('No Consent Dialog', '', QuestionDialog, {
|
|
|
|
title: _t('Terms and Conditions'),
|
|
|
|
description: <div>
|
|
|
|
<p> { _t(
|
2020-04-22 13:55:03 +03:00
|
|
|
'To continue using the %(homeserverDomain)s homeserver ' +
|
|
|
|
'you must review and agree to our terms and conditions.',
|
|
|
|
{ homeserverDomain: cli.getDomain() },
|
|
|
|
) }
|
2018-05-22 17:47:31 +03:00
|
|
|
</p>
|
|
|
|
</div>,
|
|
|
|
button: _t('Review terms and conditions'),
|
|
|
|
cancelButton: _t('Dismiss'),
|
|
|
|
onFinished: (confirmed) => {
|
|
|
|
if (confirmed) {
|
2020-02-24 01:22:12 +03:00
|
|
|
const wnd = window.open(consentUri, '_blank');
|
|
|
|
wnd.opener = null;
|
2018-05-22 17:47:31 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
}, null, true);
|
|
|
|
});
|
|
|
|
|
2018-07-05 15:54:44 +03:00
|
|
|
const dft = new DecryptionFailureTracker((total, errorCode) => {
|
|
|
|
Analytics.trackEvent('E2E', 'Decryption failure', errorCode, total);
|
2020-11-02 13:28:57 +03:00
|
|
|
CountlyAnalytics.instance.track("decryption_failure", { errorCode }, null, { sum: total });
|
2018-07-05 15:54:44 +03:00
|
|
|
}, (errorCode) => {
|
|
|
|
// Map JS-SDK error codes to tracker codes for aggregation
|
|
|
|
switch (errorCode) {
|
|
|
|
case 'MEGOLM_UNKNOWN_INBOUND_SESSION_ID':
|
|
|
|
return 'olm_keys_not_sent_error';
|
|
|
|
case 'OLM_UNKNOWN_MESSAGE_INDEX':
|
|
|
|
return 'olm_index_error';
|
|
|
|
case undefined:
|
|
|
|
return 'unexpected_error';
|
|
|
|
default:
|
|
|
|
return 'unspecified_error';
|
|
|
|
}
|
2018-06-12 16:13:09 +03:00
|
|
|
});
|
2018-06-15 19:08:11 +03:00
|
|
|
|
|
|
|
// Shelved for later date when we have time to think about persisting history of
|
|
|
|
// tracked events across sessions.
|
|
|
|
// dft.loadTrackedEventHashMap();
|
2018-06-12 16:13:09 +03:00
|
|
|
|
2018-06-15 19:58:43 +03:00
|
|
|
dft.start();
|
2018-06-15 15:33:07 +03:00
|
|
|
|
|
|
|
// When logging out, stop tracking failures and destroy state
|
2018-06-15 19:58:43 +03:00
|
|
|
cli.on("Session.logged_out", () => dft.stop());
|
2018-07-05 15:54:44 +03:00
|
|
|
cli.on("Event.decrypted", (e, err) => dft.eventDecrypted(e, err));
|
2018-06-15 15:33:07 +03:00
|
|
|
|
2017-11-05 06:13:23 +03:00
|
|
|
cli.on("Room", (room) => {
|
2017-11-06 00:56:41 +03:00
|
|
|
if (MatrixClientPeg.get().isCryptoEnabled()) {
|
|
|
|
const blacklistEnabled = SettingsStore.getValueAt(
|
|
|
|
SettingLevel.ROOM_DEVICE,
|
|
|
|
"blacklistUnverifiedDevices",
|
|
|
|
room.roomId,
|
2017-11-09 03:41:32 +03:00
|
|
|
/*explicit=*/true,
|
2017-11-06 00:56:41 +03:00
|
|
|
);
|
|
|
|
room.setBlacklistUnverifiedDevices(blacklistEnabled);
|
|
|
|
}
|
2017-11-05 06:13:23 +03:00
|
|
|
});
|
2017-12-06 18:28:20 +03:00
|
|
|
cli.on("crypto.warning", (type) => {
|
|
|
|
switch (type) {
|
|
|
|
case 'CRYPTO_WARNING_OLD_VERSION_DETECTED':
|
|
|
|
Modal.createTrackedDialog('Crypto migrated', '', ErrorDialog, {
|
|
|
|
title: _t('Old cryptography data detected'),
|
|
|
|
description: _t(
|
2020-07-10 21:07:11 +03:00
|
|
|
"Data from an older version of %(brand)s has been detected. " +
|
2020-04-22 15:22:33 +03:00
|
|
|
"This will have caused end-to-end cryptography to malfunction " +
|
|
|
|
"in the older version. End-to-end encrypted messages exchanged " +
|
|
|
|
"recently whilst using the older version may not be decryptable " +
|
|
|
|
"in this version. This may also cause messages exchanged with this " +
|
|
|
|
"version to fail. If you experience problems, log out and back in " +
|
2017-12-06 21:57:48 +03:00
|
|
|
"again. To retain message history, export and re-import your keys.",
|
2020-08-29 03:11:08 +03:00
|
|
|
{ brand: SdkConfig.get().brand },
|
2017-12-06 18:28:20 +03:00
|
|
|
),
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
});
|
2019-01-11 16:15:09 +03:00
|
|
|
cli.on("crypto.keyBackupFailed", async (errcode) => {
|
|
|
|
let haveNewVersion;
|
|
|
|
let newVersionInfo;
|
|
|
|
// if key backup is still enabled, there must be a new backup in place
|
|
|
|
if (MatrixClientPeg.get().getKeyBackupEnabled()) {
|
|
|
|
haveNewVersion = true;
|
|
|
|
} else {
|
|
|
|
// otherwise check the server to see if there's a new one
|
|
|
|
try {
|
|
|
|
newVersionInfo = await MatrixClientPeg.get().getKeyBackupVersion();
|
|
|
|
if (newVersionInfo !== null) haveNewVersion = true;
|
|
|
|
} catch (e) {
|
|
|
|
console.error("Saw key backup error but failed to check backup version!", e);
|
2019-01-11 00:13:44 +03:00
|
|
|
return;
|
2019-01-11 16:15:09 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (haveNewVersion) {
|
|
|
|
Modal.createTrackedDialogAsync('New Recovery Method', 'New Recovery Method',
|
2020-09-10 15:56:07 +03:00
|
|
|
import('../../async-components/views/dialogs/security/NewRecoveryMethodDialog'),
|
2019-01-11 16:42:40 +03:00
|
|
|
{ newVersionInfo },
|
2019-01-11 16:15:09 +03:00
|
|
|
);
|
|
|
|
} else {
|
|
|
|
Modal.createTrackedDialogAsync('Recovery Method Removed', 'Recovery Method Removed',
|
2020-09-10 15:56:07 +03:00
|
|
|
import('../../async-components/views/dialogs/security/RecoveryMethodRemovedDialog'),
|
2019-01-11 16:15:09 +03:00
|
|
|
);
|
2019-01-11 00:13:44 +03:00
|
|
|
}
|
2018-12-13 18:55:48 +03:00
|
|
|
});
|
2018-10-15 23:41:00 +03:00
|
|
|
|
2020-03-17 13:20:58 +03:00
|
|
|
cli.on("crypto.keySignatureUploadFailure", (failures, source, continuation) => {
|
|
|
|
const KeySignatureUploadFailedDialog =
|
|
|
|
sdk.getComponent('views.dialogs.KeySignatureUploadFailedDialog');
|
|
|
|
Modal.createTrackedDialog(
|
|
|
|
'Failed to upload key signatures',
|
|
|
|
'Failed to upload key signatures',
|
|
|
|
KeySignatureUploadFailedDialog,
|
|
|
|
{ failures, source, continuation });
|
|
|
|
});
|
|
|
|
|
2020-03-06 18:50:39 +03:00
|
|
|
cli.on("crypto.verification.request", request => {
|
2020-03-06 19:22:56 +03:00
|
|
|
if (request.verifier) {
|
|
|
|
const IncomingSasDialog = sdk.getComponent("views.dialogs.IncomingSasDialog");
|
|
|
|
Modal.createTrackedDialog('Incoming Verification', '', IncomingSasDialog, {
|
|
|
|
verifier: request.verifier,
|
2020-03-06 19:20:08 +03:00
|
|
|
}, null, /* priority = */ false, /* static = */ true);
|
|
|
|
} else if (request.pending) {
|
2020-03-06 18:50:39 +03:00
|
|
|
ToastStore.sharedInstance().addOrReplaceToast({
|
|
|
|
key: 'verifreq_' + request.channel.transactionId,
|
2020-04-03 18:04:58 +03:00
|
|
|
title: request.isSelfVerification ? _t("Self-verification request") : _t("Verification Request"),
|
2020-03-06 18:50:39 +03:00
|
|
|
icon: "verification",
|
|
|
|
props: {request},
|
|
|
|
component: sdk.getComponent("toasts.VerificationRequestToast"),
|
2020-05-22 14:57:48 +03:00
|
|
|
priority: 90,
|
2020-03-06 18:50:39 +03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2018-10-15 23:41:00 +03:00
|
|
|
// Fire the tinter right on startup to ensure the default theme is applied
|
|
|
|
// A later sync can/will correct the tint to be the right value for the user
|
2018-10-23 07:07:41 +03:00
|
|
|
const colorScheme = SettingsStore.getValue("roomColor");
|
|
|
|
Tinter.tint(colorScheme.primary_color, colorScheme.secondary_color);
|
2020-04-22 13:55:03 +03:00
|
|
|
}
|
2017-11-05 06:13:23 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Called shortly after the matrix client has started. Useful for
|
|
|
|
* setting up anything that requires the client to be started.
|
|
|
|
* @private
|
|
|
|
*/
|
2020-04-22 15:08:33 +03:00
|
|
|
private onClientStarted() {
|
2017-11-05 06:13:23 +03:00
|
|
|
const cli = MatrixClientPeg.get();
|
|
|
|
|
2017-11-06 00:56:41 +03:00
|
|
|
if (cli.isCryptoEnabled()) {
|
|
|
|
const blacklistEnabled = SettingsStore.getValueAt(
|
|
|
|
SettingLevel.DEVICE,
|
2017-11-06 01:37:06 +03:00
|
|
|
"blacklistUnverifiedDevices",
|
2017-11-06 00:56:41 +03:00
|
|
|
);
|
|
|
|
cli.setGlobalBlacklistUnverifiedDevices(blacklistEnabled);
|
2020-01-14 00:54:14 +03:00
|
|
|
|
|
|
|
// With cross-signing enabled, we send to unknown devices
|
|
|
|
// without prompting. Any bad-device status the user should
|
|
|
|
// be aware of will be signalled through the room shield
|
|
|
|
// changing colour. More advanced behaviour will come once
|
|
|
|
// we implement more settings.
|
2020-05-27 12:28:25 +03:00
|
|
|
cli.setGlobalErrorOnUnknownDevices(false);
|
2017-11-06 00:56:41 +03:00
|
|
|
}
|
2020-04-22 13:55:03 +03:00
|
|
|
}
|
2015-07-15 21:25:36 +03:00
|
|
|
|
2020-04-28 01:59:07 +03:00
|
|
|
showScreen(screen: string, params?: {[key: string]: any}) {
|
|
|
|
if (screen === 'register') {
|
2015-07-15 22:33:12 +03:00
|
|
|
dis.dispatch({
|
|
|
|
action: 'start_registration',
|
2017-05-19 15:53:11 +03:00
|
|
|
params: params,
|
2015-07-15 22:33:12 +03:00
|
|
|
});
|
2020-04-28 01:59:07 +03:00
|
|
|
} else if (screen === 'login') {
|
2015-07-15 22:33:12 +03:00
|
|
|
dis.dispatch({
|
|
|
|
action: 'start_login',
|
2017-05-19 15:53:11 +03:00
|
|
|
params: params,
|
2015-07-15 22:33:12 +03:00
|
|
|
});
|
2020-04-28 01:59:07 +03:00
|
|
|
} else if (screen === 'forgot_password') {
|
2016-01-12 20:20:16 +03:00
|
|
|
dis.dispatch({
|
|
|
|
action: 'start_password_recovery',
|
2017-05-19 15:53:11 +03:00
|
|
|
params: params,
|
2016-01-12 20:20:16 +03:00
|
|
|
});
|
2019-07-08 21:43:16 +03:00
|
|
|
} else if (screen === 'soft_logout') {
|
2019-07-10 08:44:14 +03:00
|
|
|
if (MatrixClientPeg.get() && MatrixClientPeg.get().getUserId() && !Lifecycle.isSoftLogout()) {
|
2019-07-08 21:43:16 +03:00
|
|
|
// Logged in - visit a room
|
2020-04-28 01:59:07 +03:00
|
|
|
this.viewLastRoom();
|
2019-07-08 21:43:16 +03:00
|
|
|
} else {
|
|
|
|
// Ultimately triggers soft_logout if needed
|
|
|
|
dis.dispatch({
|
|
|
|
action: 'start_login',
|
|
|
|
params: params,
|
|
|
|
});
|
|
|
|
}
|
2020-04-28 01:59:07 +03:00
|
|
|
} else if (screen === 'new') {
|
2015-11-11 04:01:48 +03:00
|
|
|
dis.dispatch({
|
|
|
|
action: 'view_create_room',
|
|
|
|
});
|
2020-04-28 01:59:07 +03:00
|
|
|
} else if (screen === 'settings') {
|
2020-05-14 06:07:19 +03:00
|
|
|
dis.fire(Action.ViewUserSettings);
|
2020-04-28 01:59:07 +03:00
|
|
|
} else if (screen === 'welcome') {
|
2019-02-07 19:25:09 +03:00
|
|
|
dis.dispatch({
|
|
|
|
action: 'view_welcome_page',
|
|
|
|
});
|
2020-04-28 01:59:07 +03:00
|
|
|
} else if (screen === 'home') {
|
2016-11-13 17:10:46 +03:00
|
|
|
dis.dispatch({
|
|
|
|
action: 'view_home_page',
|
|
|
|
});
|
2020-04-28 01:59:07 +03:00
|
|
|
} else if (screen === 'start') {
|
2017-05-30 16:27:02 +03:00
|
|
|
this.showScreen('home');
|
|
|
|
dis.dispatch({
|
2018-09-05 20:08:49 +03:00
|
|
|
action: 'require_registration',
|
2017-05-30 16:27:02 +03:00
|
|
|
});
|
2020-04-28 01:59:07 +03:00
|
|
|
} else if (screen === 'directory') {
|
2020-10-29 18:53:14 +03:00
|
|
|
if (this.state.view === Views.WELCOME) {
|
|
|
|
CountlyAnalytics.instance.track("onboarding_room_directory");
|
|
|
|
}
|
2020-06-09 05:33:21 +03:00
|
|
|
dis.fire(Action.ViewRoomDirectory);
|
2020-06-26 00:00:22 +03:00
|
|
|
} else if (screen === "start_sso" || screen === "start_cas") {
|
|
|
|
// TODO if logged in, skip SSO
|
|
|
|
let cli = MatrixClientPeg.get();
|
|
|
|
if (!cli) {
|
|
|
|
const {hsUrl, isUrl} = this.props.serverConfig;
|
2020-06-26 11:35:29 +03:00
|
|
|
cli = Matrix.createClient({
|
2020-06-26 00:00:22 +03:00
|
|
|
baseUrl: hsUrl,
|
|
|
|
idBaseUrl: isUrl,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
const type = screen === "start_sso" ? "sso" : "cas";
|
|
|
|
PlatformPeg.get().startSingleSignOn(cli, type, this.getFragmentAfterLogin());
|
2020-04-28 01:59:07 +03:00
|
|
|
} else if (screen === 'groups') {
|
2017-06-28 15:56:18 +03:00
|
|
|
dis.dispatch({
|
|
|
|
action: 'view_my_groups',
|
|
|
|
});
|
2020-01-16 01:10:59 +03:00
|
|
|
} else if (screen === 'complete_security') {
|
2020-01-16 00:13:56 +03:00
|
|
|
dis.dispatch({
|
|
|
|
action: 'start_complete_security',
|
|
|
|
});
|
2020-04-28 01:59:07 +03:00
|
|
|
} else if (screen === 'post_registration') {
|
2015-11-20 14:57:04 +03:00
|
|
|
dis.dispatch({
|
|
|
|
action: 'start_post_registration',
|
|
|
|
});
|
2020-04-28 01:59:07 +03:00
|
|
|
} else if (screen.indexOf('room/') === 0) {
|
2019-12-24 17:06:50 +03:00
|
|
|
// Rooms can have the following formats:
|
|
|
|
// #room_alias:domain or !opaque_id:domain
|
|
|
|
const room = screen.substring(5);
|
|
|
|
const domainOffset = room.indexOf(':') + 1; // 0 in case room does not contain a :
|
|
|
|
let eventOffset = room.length;
|
|
|
|
// room aliases can contain slashes only look for slash after domain
|
|
|
|
if (room.substring(domainOffset).indexOf('/') > -1) {
|
|
|
|
eventOffset = domainOffset + room.substring(domainOffset).indexOf('/');
|
|
|
|
}
|
|
|
|
const roomString = room.substring(0, eventOffset);
|
|
|
|
let eventId = room.substring(eventOffset + 1); // empty string if no event id given
|
2019-03-26 08:02:25 +03:00
|
|
|
|
|
|
|
// Previously we pulled the eventID from the segments in such a way
|
|
|
|
// where if there was no eventId then we'd get undefined. However, we
|
|
|
|
// now do a splice and join to handle v3 event IDs which results in
|
|
|
|
// an empty string. To maintain our potential contract with the rest
|
|
|
|
// of the app, we coerce the eventId to be undefined where applicable.
|
|
|
|
if (!eventId) eventId = undefined;
|
|
|
|
|
2020-08-03 18:02:26 +03:00
|
|
|
// TODO: Handle encoded room/event IDs: https://github.com/vector-im/element-web/issues/9149
|
2016-03-01 21:23:57 +03:00
|
|
|
|
2020-09-12 04:49:48 +03:00
|
|
|
let threepidInvite: IThreepidInvite;
|
|
|
|
if (params.signurl && params.email) {
|
|
|
|
threepidInvite = ThreepidInviteStore.instance
|
|
|
|
.storeInvite(roomString, params as IThreepidInviteWireFormat);
|
|
|
|
}
|
2016-03-01 21:23:57 +03:00
|
|
|
|
2018-10-19 22:30:38 +03:00
|
|
|
// on our URLs there might be a ?via=matrix.org or similar to help
|
|
|
|
// joins to the room succeed. We'll pass these through as an array
|
|
|
|
// to other levels. If there's just one ?via= then params.via is a
|
|
|
|
// single string. If someone does something like ?via=one.com&via=two.com
|
|
|
|
// then params.via is an array of strings.
|
|
|
|
let via = [];
|
|
|
|
if (params.via) {
|
|
|
|
if (typeof(params.via) === 'string') via = [params.via];
|
|
|
|
else via = params.via;
|
|
|
|
}
|
|
|
|
|
2017-05-19 15:53:11 +03:00
|
|
|
const payload = {
|
2016-06-10 17:12:42 +03:00
|
|
|
action: 'view_room',
|
|
|
|
event_id: eventId,
|
2018-10-19 22:30:38 +03:00
|
|
|
via_servers: via,
|
2017-06-08 19:57:37 +03:00
|
|
|
// If an event ID is given in the URL hash, notify RoomViewStore to mark
|
|
|
|
// it as highlighted, which will propagate to RoomView and highlight the
|
|
|
|
// associated EventTile.
|
2017-06-08 16:17:49 +03:00
|
|
|
highlighted: Boolean(eventId),
|
2020-09-12 04:49:48 +03:00
|
|
|
threepid_invite: threepidInvite,
|
2020-09-12 04:55:15 +03:00
|
|
|
// TODO: Replace oob_data with the threepidInvite (which has the same info).
|
|
|
|
// This isn't done yet because it's threaded through so many more places.
|
|
|
|
// See https://github.com/vector-im/element-web/issues/15157
|
2020-09-12 04:49:48 +03:00
|
|
|
oob_data: {
|
|
|
|
name: threepidInvite?.roomName,
|
|
|
|
avatarUrl: threepidInvite?.roomAvatarUrl,
|
|
|
|
inviterName: threepidInvite?.inviterName,
|
|
|
|
},
|
2020-04-28 01:59:07 +03:00
|
|
|
room_alias: undefined,
|
|
|
|
room_id: undefined,
|
2016-06-10 17:12:42 +03:00
|
|
|
};
|
2020-04-28 01:59:07 +03:00
|
|
|
if (roomString[0] === '#') {
|
2016-06-10 17:12:42 +03:00
|
|
|
payload.room_alias = roomString;
|
2015-09-18 20:39:16 +03:00
|
|
|
} else {
|
2016-06-10 17:12:42 +03:00
|
|
|
payload.room_id = roomString;
|
2016-06-09 20:49:06 +03:00
|
|
|
}
|
|
|
|
|
2019-02-11 16:49:18 +03:00
|
|
|
dis.dispatch(payload);
|
2020-04-28 01:59:07 +03:00
|
|
|
} else if (screen.indexOf('user/') === 0) {
|
2017-05-19 15:53:11 +03:00
|
|
|
const userId = screen.substring(5);
|
2019-04-17 19:26:07 +03:00
|
|
|
dis.dispatch({
|
|
|
|
action: 'view_user_info',
|
|
|
|
userId: userId,
|
|
|
|
subAction: params.action,
|
|
|
|
});
|
2020-04-28 01:59:07 +03:00
|
|
|
} else if (screen.indexOf('group/') === 0) {
|
2017-06-05 18:51:50 +03:00
|
|
|
const groupId = screen.substring(6);
|
|
|
|
|
|
|
|
// TODO: Check valid group ID
|
|
|
|
|
|
|
|
dis.dispatch({
|
|
|
|
action: 'view_group',
|
|
|
|
group_id: groupId,
|
|
|
|
});
|
2017-05-19 15:53:11 +03:00
|
|
|
} else {
|
2016-03-06 22:33:36 +03:00
|
|
|
console.info("Ignoring showScreen for '%s'", screen);
|
2015-11-20 17:26:49 +03:00
|
|
|
}
|
2020-04-22 13:55:03 +03:00
|
|
|
}
|
2015-07-15 21:25:36 +03:00
|
|
|
|
2020-09-09 18:52:46 +03:00
|
|
|
notifyNewScreen(screen: string, replaceLast = false) {
|
2015-07-15 21:25:36 +03:00
|
|
|
if (this.props.onNewScreen) {
|
2020-09-09 18:52:46 +03:00
|
|
|
this.props.onNewScreen(screen, replaceLast);
|
2015-07-15 21:25:36 +03:00
|
|
|
}
|
2020-04-22 15:08:33 +03:00
|
|
|
this.setPageSubtitle();
|
2020-04-22 13:55:03 +03:00
|
|
|
}
|
2015-11-30 21:11:04 +03:00
|
|
|
|
2020-04-22 15:08:33 +03:00
|
|
|
onAliasClick(event: MouseEvent, alias: string) {
|
2016-08-28 04:05:23 +03:00
|
|
|
event.preventDefault();
|
|
|
|
dis.dispatch({action: 'view_room', room_alias: alias});
|
2020-04-22 13:55:03 +03:00
|
|
|
}
|
2016-08-28 04:05:23 +03:00
|
|
|
|
2020-04-22 15:08:33 +03:00
|
|
|
onUserClick(event: MouseEvent, userId: string) {
|
2016-08-28 04:05:23 +03:00
|
|
|
event.preventDefault();
|
|
|
|
|
2020-04-22 15:08:33 +03:00
|
|
|
const member = new RoomMember(null, userId);
|
2016-08-28 04:05:23 +03:00
|
|
|
if (!member) { return; }
|
2020-05-14 06:03:12 +03:00
|
|
|
dis.dispatch<ViewUserPayload>({
|
|
|
|
action: Action.ViewUser,
|
2016-08-28 04:05:23 +03:00
|
|
|
member: member,
|
|
|
|
});
|
2020-04-22 13:55:03 +03:00
|
|
|
}
|
2015-11-30 21:11:04 +03:00
|
|
|
|
2020-04-22 15:08:33 +03:00
|
|
|
onGroupClick(event: MouseEvent, groupId: string) {
|
2017-06-05 18:51:50 +03:00
|
|
|
event.preventDefault();
|
|
|
|
dis.dispatch({action: 'view_group', group_id: groupId});
|
2020-04-22 13:55:03 +03:00
|
|
|
}
|
2017-06-05 18:51:50 +03:00
|
|
|
|
2020-04-22 15:08:33 +03:00
|
|
|
onLogoutClick(event: React.MouseEvent<HTMLAnchorElement, MouseEvent>) {
|
2015-11-30 21:11:04 +03:00
|
|
|
dis.dispatch({
|
2017-05-19 15:53:11 +03:00
|
|
|
action: 'logout',
|
2015-11-30 21:11:04 +03:00
|
|
|
});
|
|
|
|
event.stopPropagation();
|
|
|
|
event.preventDefault();
|
2020-04-22 13:55:03 +03:00
|
|
|
}
|
2015-11-30 21:11:04 +03:00
|
|
|
|
2020-04-22 15:08:33 +03:00
|
|
|
handleResize = () => {
|
2017-05-19 15:53:11 +03:00
|
|
|
const hideLhsThreshold = 1000;
|
|
|
|
const showLhsThreshold = 1000;
|
2015-11-30 21:11:04 +03:00
|
|
|
|
2020-04-22 15:08:33 +03:00
|
|
|
if (this.windowWidth > hideLhsThreshold && window.innerWidth <= hideLhsThreshold) {
|
2015-11-30 21:11:04 +03:00
|
|
|
dis.dispatch({ action: 'hide_left_panel' });
|
|
|
|
}
|
2020-04-22 15:08:33 +03:00
|
|
|
if (this.windowWidth <= showLhsThreshold && window.innerWidth > showLhsThreshold) {
|
2015-11-30 21:11:04 +03:00
|
|
|
dis.dispatch({ action: 'show_left_panel' });
|
|
|
|
}
|
|
|
|
|
2019-03-12 18:36:12 +03:00
|
|
|
this.state.resizeNotifier.notifyWindowResized();
|
2020-04-22 15:08:33 +03:00
|
|
|
this.windowWidth = window.innerWidth;
|
2020-04-22 13:55:03 +03:00
|
|
|
};
|
2015-11-30 21:11:04 +03:00
|
|
|
|
2020-04-22 15:08:33 +03:00
|
|
|
private dispatchTimelineResize() {
|
2019-03-29 16:32:26 +03:00
|
|
|
dis.dispatch({ action: 'timeline_resize' });
|
2020-04-22 13:55:03 +03:00
|
|
|
}
|
2019-03-12 18:37:20 +03:00
|
|
|
|
2020-04-22 15:08:33 +03:00
|
|
|
onRoomCreated(roomId: string) {
|
2015-11-30 21:11:04 +03:00
|
|
|
dis.dispatch({
|
|
|
|
action: "view_room",
|
2017-05-19 15:53:11 +03:00
|
|
|
room_id: roomId,
|
2015-11-30 21:11:04 +03:00
|
|
|
});
|
2020-04-22 13:55:03 +03:00
|
|
|
}
|
2015-11-30 21:11:04 +03:00
|
|
|
|
2020-04-22 13:55:03 +03:00
|
|
|
onRegisterClick = () => {
|
2015-11-30 21:11:04 +03:00
|
|
|
this.showScreen("register");
|
2020-04-22 13:55:03 +03:00
|
|
|
};
|
2015-11-30 21:11:04 +03:00
|
|
|
|
2020-04-22 13:55:03 +03:00
|
|
|
onLoginClick = () => {
|
2015-11-30 21:11:04 +03:00
|
|
|
this.showScreen("login");
|
2020-04-22 13:55:03 +03:00
|
|
|
};
|
2015-11-30 21:11:04 +03:00
|
|
|
|
2020-04-22 13:55:03 +03:00
|
|
|
onForgotPasswordClick = () => {
|
2016-01-12 20:20:16 +03:00
|
|
|
this.showScreen("forgot_password");
|
2020-04-22 13:55:03 +03:00
|
|
|
};
|
2016-01-12 20:20:16 +03:00
|
|
|
|
2020-10-07 14:14:36 +03:00
|
|
|
onRegisterFlowComplete = (credentials: IMatrixClientCreds, password: string) => {
|
2020-01-25 18:28:06 +03:00
|
|
|
return this.onUserCompletedLoginFlow(credentials, password);
|
2020-04-22 13:55:03 +03:00
|
|
|
};
|
2020-01-24 22:11:57 +03:00
|
|
|
|
2017-06-19 12:22:18 +03:00
|
|
|
// returns a promise which resolves to the new MatrixClient
|
2020-10-07 14:14:36 +03:00
|
|
|
onRegistered(credentials: IMatrixClientCreds) {
|
2017-06-19 12:22:18 +03:00
|
|
|
return Lifecycle.setLoggedIn(credentials);
|
2020-04-22 13:55:03 +03:00
|
|
|
}
|
2017-02-13 17:36:03 +03:00
|
|
|
|
2020-04-22 13:55:03 +03:00
|
|
|
onFinishPostRegistration = () => {
|
2015-11-30 21:11:04 +03:00
|
|
|
// Don't confuse this with "PageType" which is the middle window to show
|
|
|
|
this.setState({
|
2020-04-23 12:12:50 +03:00
|
|
|
view: Views.LOGGED_IN,
|
2015-11-30 21:11:04 +03:00
|
|
|
});
|
|
|
|
this.showScreen("settings");
|
2020-04-22 13:55:03 +03:00
|
|
|
};
|
2015-11-30 21:11:04 +03:00
|
|
|
|
2020-04-22 15:08:33 +03:00
|
|
|
onSendEvent(roomId: string, event: MatrixEvent) {
|
2017-06-16 18:12:52 +03:00
|
|
|
const cli = MatrixClientPeg.get();
|
|
|
|
if (!cli) {
|
|
|
|
dis.dispatch({action: 'message_send_failed'});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-11-18 13:03:05 +03:00
|
|
|
cli.sendEvent(roomId, event.getType(), event.getContent()).then(() => {
|
2017-06-16 18:12:52 +03:00
|
|
|
dis.dispatch({action: 'message_sent'});
|
|
|
|
}, (err) => {
|
|
|
|
dis.dispatch({action: 'message_send_failed'});
|
|
|
|
});
|
2020-04-22 13:55:03 +03:00
|
|
|
}
|
2017-06-16 18:12:52 +03:00
|
|
|
|
2020-04-22 15:22:33 +03:00
|
|
|
private setPageSubtitle(subtitle = '') {
|
2019-09-24 00:01:49 +03:00
|
|
|
if (this.state.currentRoomId) {
|
2019-09-24 13:53:33 +03:00
|
|
|
const client = MatrixClientPeg.get();
|
|
|
|
const room = client && client.getRoom(this.state.currentRoomId);
|
2019-09-24 00:01:49 +03:00
|
|
|
if (room) {
|
2019-11-13 01:12:54 +03:00
|
|
|
subtitle = `${this.subTitleStatus} | ${ room.name } ${subtitle}`;
|
2019-09-24 00:01:49 +03:00
|
|
|
}
|
2019-11-13 01:12:54 +03:00
|
|
|
} else {
|
|
|
|
subtitle = `${this.subTitleStatus} ${subtitle}`;
|
2019-09-24 00:01:49 +03:00
|
|
|
}
|
2020-09-27 23:20:41 +03:00
|
|
|
|
2020-09-27 23:06:02 +03:00
|
|
|
const title = `${SdkConfig.get().brand} ${subtitle}`;
|
|
|
|
|
|
|
|
if (document.title !== title) {
|
|
|
|
document.title = title;
|
|
|
|
}
|
2020-04-22 13:55:03 +03:00
|
|
|
}
|
2017-06-20 17:31:12 +03:00
|
|
|
|
2020-04-22 15:08:33 +03:00
|
|
|
updateStatusIndicator(state: string, prevState: string) {
|
2020-07-22 05:24:16 +03:00
|
|
|
const notificationState = RoomNotificationStateStore.instance.globalState;
|
|
|
|
const numUnreadRooms = notificationState.numUnreadStates; // we know that states === rooms here
|
2016-03-16 04:02:49 +03:00
|
|
|
|
2016-11-02 18:10:21 +03:00
|
|
|
if (PlatformPeg.get()) {
|
|
|
|
PlatformPeg.get().setErrorStatus(state === 'ERROR');
|
2020-07-22 05:24:16 +03:00
|
|
|
PlatformPeg.get().setNotificationCount(numUnreadRooms);
|
2016-01-27 18:19:25 +03:00
|
|
|
}
|
2016-11-02 18:10:21 +03:00
|
|
|
|
2019-09-24 00:01:49 +03:00
|
|
|
this.subTitleStatus = '';
|
2017-06-07 13:40:46 +03:00
|
|
|
if (state === "ERROR") {
|
2019-09-24 00:01:49 +03:00
|
|
|
this.subTitleStatus += `[${_t("Offline")}] `;
|
2017-06-07 13:40:46 +03:00
|
|
|
}
|
2020-07-22 05:24:16 +03:00
|
|
|
if (numUnreadRooms > 0) {
|
|
|
|
this.subTitleStatus += `[${numUnreadRooms}]`;
|
2017-06-07 13:40:46 +03:00
|
|
|
}
|
|
|
|
|
2020-04-22 15:08:33 +03:00
|
|
|
this.setPageSubtitle();
|
2020-04-22 13:55:03 +03:00
|
|
|
}
|
2015-12-21 15:55:13 +03:00
|
|
|
|
2018-05-29 15:16:39 +03:00
|
|
|
onCloseAllSettings() {
|
|
|
|
dis.dispatch({ action: 'close_settings' });
|
2020-04-22 13:55:03 +03:00
|
|
|
}
|
2015-12-23 14:47:56 +03:00
|
|
|
|
2020-04-22 15:08:33 +03:00
|
|
|
onServerConfigChange = (serverConfig: ValidatedServerConfig) => {
|
|
|
|
this.setState({serverConfig});
|
2020-04-22 13:55:03 +03:00
|
|
|
};
|
2018-12-05 09:34:57 +03:00
|
|
|
|
2020-04-22 15:08:33 +03:00
|
|
|
private makeRegistrationUrl = (params: {[key: string]: string}) => {
|
2017-02-24 14:41:23 +03:00
|
|
|
if (this.props.startingFragmentQueryParams.referrer) {
|
|
|
|
params.referrer = this.props.startingFragmentQueryParams.referrer;
|
|
|
|
}
|
|
|
|
return this.props.makeRegistrationUrl(params);
|
2020-04-22 13:55:03 +03:00
|
|
|
};
|
2017-02-24 14:41:23 +03:00
|
|
|
|
2020-09-15 17:25:50 +03:00
|
|
|
/**
|
|
|
|
* After registration or login, we run various post-auth steps before entering the app
|
|
|
|
* proper, such setting up cross-signing or verifying the new session.
|
|
|
|
*
|
|
|
|
* Note: SSO users (and any others using token login) currently do not pass through
|
|
|
|
* this, as they instead jump straight into the app after `attemptTokenLogin`.
|
|
|
|
*/
|
2020-10-07 14:14:36 +03:00
|
|
|
onUserCompletedLoginFlow = async (credentials: IMatrixClientCreds, password: string) => {
|
2020-04-22 15:08:33 +03:00
|
|
|
this.accountPassword = password;
|
2020-01-25 18:28:06 +03:00
|
|
|
// self-destruct the password after 5mins
|
2020-04-22 15:08:33 +03:00
|
|
|
if (this.accountPasswordTimer !== null) clearTimeout(this.accountPasswordTimer);
|
|
|
|
this.accountPasswordTimer = setTimeout(() => {
|
|
|
|
this.accountPassword = null;
|
|
|
|
this.accountPasswordTimer = null;
|
2020-01-25 18:28:06 +03:00
|
|
|
}, 60 * 5 * 1000);
|
2020-01-28 15:30:39 +03:00
|
|
|
|
2020-06-05 19:52:09 +03:00
|
|
|
// Create and start the client
|
|
|
|
await Lifecycle.setLoggedIn(credentials);
|
2020-01-16 14:52:02 +03:00
|
|
|
|
2020-01-16 00:13:56 +03:00
|
|
|
const cli = MatrixClientPeg.get();
|
2020-06-05 19:52:09 +03:00
|
|
|
const cryptoEnabled = cli.isCryptoEnabled();
|
|
|
|
if (!cryptoEnabled) {
|
2020-04-22 15:08:33 +03:00
|
|
|
this.onLoggedIn();
|
2020-01-16 00:13:56 +03:00
|
|
|
}
|
|
|
|
|
2020-06-05 19:52:09 +03:00
|
|
|
const promisesList = [this.firstSyncPromise.promise];
|
|
|
|
if (cryptoEnabled) {
|
|
|
|
// wait for the client to finish downloading cross-signing keys for us so we
|
|
|
|
// know whether or not we have keys set up on this account
|
|
|
|
promisesList.push(cli.downloadKeys([cli.getUserId()]));
|
|
|
|
}
|
|
|
|
|
2020-06-15 14:59:38 +03:00
|
|
|
// Now update the state to say we're waiting for the first sync to complete rather
|
2020-06-15 14:11:45 +03:00
|
|
|
// than for the login to finish.
|
2020-04-15 14:21:49 +03:00
|
|
|
this.setState({ pendingInitialSync: true });
|
2020-01-16 00:13:56 +03:00
|
|
|
|
2020-06-05 19:52:09 +03:00
|
|
|
await Promise.all(promisesList);
|
|
|
|
|
|
|
|
if (!cryptoEnabled) {
|
2020-04-15 15:45:12 +03:00
|
|
|
this.setState({ pendingInitialSync: false });
|
2020-06-05 20:08:25 +03:00
|
|
|
return;
|
2020-04-15 15:45:12 +03:00
|
|
|
}
|
|
|
|
|
2020-06-05 18:40:20 +03:00
|
|
|
const crossSigningIsSetUp = cli.getStoredCrossSigningForUser(cli.getUserId());
|
|
|
|
if (crossSigningIsSetUp) {
|
2020-06-03 16:31:34 +03:00
|
|
|
this.setStateForNewView({ view: Views.COMPLETE_SECURITY });
|
|
|
|
} else if (await cli.doesServerSupportUnstableFeature("org.matrix.e2e_cross_signing")) {
|
2020-04-23 12:12:50 +03:00
|
|
|
this.setStateForNewView({ view: Views.E2E_SETUP });
|
2020-01-16 00:13:56 +03:00
|
|
|
} else {
|
2020-04-22 15:08:33 +03:00
|
|
|
this.onLoggedIn();
|
2020-01-16 00:13:56 +03:00
|
|
|
}
|
2020-04-15 14:21:49 +03:00
|
|
|
this.setState({ pendingInitialSync: false });
|
2020-04-22 13:55:03 +03:00
|
|
|
};
|
2020-01-16 00:13:56 +03:00
|
|
|
|
2020-01-24 22:11:57 +03:00
|
|
|
// complete security / e2e setup has finished
|
2020-04-22 13:55:03 +03:00
|
|
|
onCompleteSecurityE2eSetupFinished = () => {
|
2020-04-22 15:08:33 +03:00
|
|
|
this.onLoggedIn();
|
2020-04-22 13:55:03 +03:00
|
|
|
};
|
2020-01-16 00:13:56 +03:00
|
|
|
|
2020-06-26 00:00:22 +03:00
|
|
|
getFragmentAfterLogin() {
|
2020-05-13 08:24:04 +03:00
|
|
|
let fragmentAfterLogin = "";
|
2020-06-29 17:40:20 +03:00
|
|
|
const initialScreenAfterLogin = this.props.initialScreenAfterLogin;
|
|
|
|
if (initialScreenAfterLogin &&
|
2020-08-03 18:02:26 +03:00
|
|
|
// XXX: workaround for https://github.com/vector-im/element-web/issues/11643 causing a login-loop
|
2020-06-29 17:40:20 +03:00
|
|
|
!["welcome", "login", "register", "start_sso", "start_cas"].includes(initialScreenAfterLogin.screen)
|
2020-06-02 18:26:07 +03:00
|
|
|
) {
|
2020-06-29 17:40:20 +03:00
|
|
|
fragmentAfterLogin = `/${initialScreenAfterLogin.screen}`;
|
2020-05-13 08:24:04 +03:00
|
|
|
}
|
2020-06-26 00:00:22 +03:00
|
|
|
return fragmentAfterLogin;
|
|
|
|
}
|
2020-05-13 08:24:04 +03:00
|
|
|
|
2020-06-26 00:00:22 +03:00
|
|
|
render() {
|
|
|
|
const fragmentAfterLogin = this.getFragmentAfterLogin();
|
2020-09-17 13:55:10 +03:00
|
|
|
let view = null;
|
2019-10-02 18:26:23 +03:00
|
|
|
|
2020-04-23 12:12:50 +03:00
|
|
|
if (this.state.view === Views.LOADING) {
|
2017-03-29 17:24:47 +03:00
|
|
|
const Spinner = sdk.getComponent('elements.Spinner');
|
2019-10-02 18:26:23 +03:00
|
|
|
view = (
|
2016-08-10 13:33:58 +03:00
|
|
|
<div className="mx_MatrixChat_splash">
|
|
|
|
<Spinner />
|
|
|
|
</div>
|
2016-08-10 02:03:29 +03:00
|
|
|
);
|
2020-04-23 12:12:50 +03:00
|
|
|
} else if (this.state.view === Views.COMPLETE_SECURITY) {
|
2020-01-16 00:13:56 +03:00
|
|
|
const CompleteSecurity = sdk.getComponent('structures.auth.CompleteSecurity');
|
|
|
|
view = (
|
|
|
|
<CompleteSecurity
|
2020-01-24 22:11:57 +03:00
|
|
|
onFinished={this.onCompleteSecurityE2eSetupFinished}
|
|
|
|
/>
|
|
|
|
);
|
2020-04-23 12:12:50 +03:00
|
|
|
} else if (this.state.view === Views.E2E_SETUP) {
|
2020-01-24 22:11:57 +03:00
|
|
|
const E2eSetup = sdk.getComponent('structures.auth.E2eSetup');
|
|
|
|
view = (
|
|
|
|
<E2eSetup
|
|
|
|
onFinished={this.onCompleteSecurityE2eSetupFinished}
|
2020-04-22 15:08:33 +03:00
|
|
|
accountPassword={this.accountPassword}
|
2020-01-16 00:13:56 +03:00
|
|
|
/>
|
|
|
|
);
|
2020-04-23 12:12:50 +03:00
|
|
|
} else if (this.state.view === Views.POST_REGISTRATION) {
|
2019-10-02 18:26:23 +03:00
|
|
|
// needs to be before normal PageTypes as you are logged in technically
|
2019-01-22 01:11:10 +03:00
|
|
|
const PostRegistration = sdk.getComponent('structures.auth.PostRegistration');
|
2019-10-02 18:26:23 +03:00
|
|
|
view = (
|
2015-11-30 21:11:04 +03:00
|
|
|
<PostRegistration
|
|
|
|
onComplete={this.onFinishPostRegistration} />
|
|
|
|
);
|
2020-04-23 12:12:50 +03:00
|
|
|
} else if (this.state.view === Views.LOGGED_IN) {
|
2018-10-10 19:07:17 +03:00
|
|
|
// store errors stop the client syncing and require user intervention, so we'll
|
|
|
|
// be showing a dialog. Don't show anything else.
|
2020-04-22 15:08:33 +03:00
|
|
|
const isStoreError = this.state.syncError && this.state.syncError instanceof InvalidStoreError;
|
2018-10-10 19:07:17 +03:00
|
|
|
|
2017-06-15 19:36:57 +03:00
|
|
|
// `ready` and `view==LOGGED_IN` may be set before `page_type` (because the
|
|
|
|
// latter is set via the dispatcher). If we don't yet have a `page_type`,
|
|
|
|
// keep showing the spinner for now.
|
2018-10-10 19:07:17 +03:00
|
|
|
if (this.state.ready && this.state.page_type && !isStoreError) {
|
2017-06-15 19:36:57 +03:00
|
|
|
/* 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.
|
|
|
|
*/
|
|
|
|
const LoggedInView = sdk.getComponent('structures.LoggedInView');
|
2019-10-02 18:26:23 +03:00
|
|
|
view = (
|
2020-04-23 12:12:50 +03:00
|
|
|
<LoggedInView
|
|
|
|
{...this.props}
|
|
|
|
{...this.state}
|
|
|
|
ref={this.loggedInView}
|
|
|
|
matrixClient={MatrixClientPeg.get()}
|
2017-06-15 19:36:57 +03:00
|
|
|
onRoomCreated={this.onRoomCreated}
|
2018-05-29 15:16:39 +03:00
|
|
|
onCloseAllSettings={this.onCloseAllSettings}
|
2017-06-15 19:36:57 +03:00
|
|
|
onRegistered={this.onRegistered}
|
|
|
|
currentRoomId={this.state.currentRoomId}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
// we think we are logged in, but are still waiting for the /sync to complete
|
|
|
|
const Spinner = sdk.getComponent('elements.Spinner');
|
2018-09-07 14:18:25 +03:00
|
|
|
let errorBox;
|
2018-10-10 19:07:17 +03:00
|
|
|
if (this.state.syncError && !isStoreError) {
|
2018-09-07 14:18:25 +03:00
|
|
|
errorBox = <div className="mx_MatrixChat_syncError">
|
|
|
|
{messageForSyncError(this.state.syncError)}
|
|
|
|
</div>;
|
|
|
|
}
|
2019-10-02 18:26:23 +03:00
|
|
|
view = (
|
2017-06-15 19:36:57 +03:00
|
|
|
<div className="mx_MatrixChat_splash">
|
2018-09-07 14:18:25 +03:00
|
|
|
{errorBox}
|
2017-06-15 19:36:57 +03:00
|
|
|
<Spinner />
|
2017-09-28 13:21:06 +03:00
|
|
|
<a href="#" className="mx_MatrixChat_splashButtons" onClick={this.onLogoutClick}>
|
2019-10-02 18:26:23 +03:00
|
|
|
{_t('Logout')}
|
2017-06-15 19:36:57 +03:00
|
|
|
</a>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
2020-04-23 12:12:50 +03:00
|
|
|
} else if (this.state.view === Views.WELCOME) {
|
2019-02-07 19:25:09 +03:00
|
|
|
const Welcome = sdk.getComponent('auth.Welcome');
|
2020-06-26 00:02:39 +03:00
|
|
|
view = <Welcome />;
|
2020-09-17 13:55:10 +03:00
|
|
|
} else if (this.state.view === Views.REGISTER && SettingsStore.getValue(UIFeature.Registration)) {
|
2019-01-22 01:11:10 +03:00
|
|
|
const Registration = sdk.getComponent('structures.auth.Registration');
|
2020-09-12 05:20:33 +03:00
|
|
|
const email = ThreepidInviteStore.instance.pickBestInvite()?.toEmail;
|
2019-10-02 18:26:23 +03:00
|
|
|
view = (
|
2015-11-30 21:11:04 +03:00
|
|
|
<Registration
|
|
|
|
clientSecret={this.state.register_client_secret}
|
|
|
|
sessionId={this.state.register_session_id}
|
|
|
|
idSid={this.state.register_id_sid}
|
2020-09-12 05:20:33 +03:00
|
|
|
email={email}
|
2016-06-02 13:50:00 +03:00
|
|
|
brand={this.props.config.brand}
|
2020-04-22 15:08:33 +03:00
|
|
|
makeRegistrationUrl={this.makeRegistrationUrl}
|
2020-01-24 22:11:57 +03:00
|
|
|
onLoggedIn={this.onRegisterFlowComplete}
|
2016-03-06 22:33:36 +03:00
|
|
|
onLoginClick={this.onLoginClick}
|
2018-02-07 18:51:03 +03:00
|
|
|
onServerConfigChange={this.onServerConfigChange}
|
2020-01-30 14:27:54 +03:00
|
|
|
defaultDeviceDisplayName={this.props.defaultDeviceDisplayName}
|
2019-06-12 20:11:58 +03:00
|
|
|
{...this.getServerProperties()}
|
2019-05-03 08:09:07 +03:00
|
|
|
/>
|
2015-11-30 21:11:04 +03:00
|
|
|
);
|
2020-09-17 13:55:10 +03:00
|
|
|
} else if (this.state.view === Views.FORGOT_PASSWORD && SettingsStore.getValue(UIFeature.PasswordReset)) {
|
2019-01-22 01:11:10 +03:00
|
|
|
const ForgotPassword = sdk.getComponent('structures.auth.ForgotPassword');
|
2019-10-02 18:26:23 +03:00
|
|
|
view = (
|
2016-01-12 20:20:16 +03:00
|
|
|
<ForgotPassword
|
2016-03-06 22:33:36 +03:00
|
|
|
onComplete={this.onLoginClick}
|
2019-05-03 08:09:07 +03:00
|
|
|
onLoginClick={this.onLoginClick}
|
|
|
|
onServerConfigChange={this.onServerConfigChange}
|
|
|
|
{...this.getServerProperties()}
|
|
|
|
/>
|
2016-01-12 20:20:16 +03:00
|
|
|
);
|
2020-04-23 12:12:50 +03:00
|
|
|
} else if (this.state.view === Views.LOGIN) {
|
2020-09-17 13:55:10 +03:00
|
|
|
const showPasswordReset = SettingsStore.getValue(UIFeature.PasswordReset);
|
2019-01-22 01:11:10 +03:00
|
|
|
const Login = sdk.getComponent('structures.auth.Login');
|
2019-10-02 18:26:23 +03:00
|
|
|
view = (
|
2015-11-30 21:11:04 +03:00
|
|
|
<Login
|
2020-04-15 14:21:49 +03:00
|
|
|
isSyncing={this.state.pendingInitialSync}
|
2020-01-16 00:13:56 +03:00
|
|
|
onLoggedIn={this.onUserCompletedLoginFlow}
|
2015-11-30 21:11:04 +03:00
|
|
|
onRegisterClick={this.onRegisterClick}
|
2016-05-27 16:57:43 +03:00
|
|
|
fallbackHsUrl={this.getFallbackHsUrl()}
|
2016-08-12 13:41:06 +03:00
|
|
|
defaultDeviceDisplayName={this.props.defaultDeviceDisplayName}
|
2020-09-17 13:55:10 +03:00
|
|
|
onForgotPasswordClick={showPasswordReset ? this.onForgotPasswordClick : undefined}
|
2018-02-07 18:51:03 +03:00
|
|
|
onServerConfigChange={this.onServerConfigChange}
|
2020-05-13 08:24:04 +03:00
|
|
|
fragmentAfterLogin={fragmentAfterLogin}
|
2019-05-03 08:09:07 +03:00
|
|
|
{...this.getServerProperties()}
|
2016-09-01 13:08:40 +03:00
|
|
|
/>
|
2015-11-30 21:11:04 +03:00
|
|
|
);
|
2020-04-23 12:12:50 +03:00
|
|
|
} else if (this.state.view === Views.SOFT_LOGOUT) {
|
2019-07-04 01:46:37 +03:00
|
|
|
const SoftLogout = sdk.getComponent('structures.auth.SoftLogout');
|
2019-10-02 18:26:23 +03:00
|
|
|
view = (
|
2019-07-08 21:43:16 +03:00
|
|
|
<SoftLogout
|
|
|
|
realQueryParams={this.props.realQueryParams}
|
|
|
|
onTokenLoginCompleted={this.props.onTokenLoginCompleted}
|
2020-05-13 08:24:04 +03:00
|
|
|
fragmentAfterLogin={fragmentAfterLogin}
|
2019-07-08 21:43:16 +03:00
|
|
|
/>
|
2019-07-04 01:46:37 +03:00
|
|
|
);
|
2019-10-02 18:26:23 +03:00
|
|
|
} else {
|
|
|
|
console.error(`Unknown view ${this.state.view}`);
|
2019-07-04 01:46:37 +03:00
|
|
|
}
|
|
|
|
|
2019-10-02 18:26:23 +03:00
|
|
|
const ErrorBoundary = sdk.getComponent('elements.ErrorBoundary');
|
|
|
|
return <ErrorBoundary>
|
|
|
|
{view}
|
|
|
|
</ErrorBoundary>;
|
2020-04-22 13:55:03 +03:00
|
|
|
}
|
|
|
|
}
|
2020-08-19 18:13:29 +03:00
|
|
|
|
|
|
|
export function isLoggedIn(): boolean {
|
|
|
|
// JRS: Maybe we should move the step that writes this to the window out of
|
2020-08-24 18:44:47 +03:00
|
|
|
// `element-web` and into this file? Better yet, we should probably create a
|
|
|
|
// store to hold this state.
|
|
|
|
// See also https://github.com/vector-im/element-web/issues/15034.
|
2020-08-19 18:13:29 +03:00
|
|
|
const app = window.matrixChat;
|
|
|
|
return app && (app as MatrixChat).state.view === Views.LOGGED_IN;
|
|
|
|
}
|