iterate PR

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
Michael Telatynski 2020-04-23 10:12:50 +01:00
parent 54e976f5a8
commit 4cf234197b

View file

@ -69,7 +69,7 @@ import * as StorageManager from "../../utils/StorageManager";
import type LoggedInViewType from "./LoggedInView"; import type LoggedInViewType from "./LoggedInView";
/** constants for MatrixChat.state.view */ /** constants for MatrixChat.state.view */
export enum VIEWS { export enum Views {
// a special initial state which is only used at startup, while we are // 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. // trying to re-animate a matrix client or register as a guest.
LOADING = 0, LOADING = 0,
@ -152,7 +152,7 @@ interface IProps { // TODO type things better
interface IState { interface IState {
// the master view we are showing. // the master view we are showing.
view: VIEWS; view: Views;
// What the LoggedInView would be showing if visible // What the LoggedInView would be showing if visible
page_type?: PageTypes; page_type?: PageTypes;
// The ID of the room we're viewing. This is either populated directly // The ID of the room we're viewing. This is either populated directly
@ -193,7 +193,6 @@ interface IState {
} }
export default class MatrixChat extends React.PureComponent<IProps, IState> { export default class MatrixChat extends React.PureComponent<IProps, IState> {
static VIEWS = VIEWS; // we export this so that the integration tests can use it :-S
static displayName = "MatrixChat"; static displayName = "MatrixChat";
static defaultProps = { static defaultProps = {
@ -222,7 +221,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
super(props, context); super(props, context);
this.state = { this.state = {
view: VIEWS.LOADING, view: Views.LOADING,
collapseLhs: false, collapseLhs: false,
leftDisabled: false, leftDisabled: false,
middleDisabled: false, middleDisabled: false,
@ -538,7 +537,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
this.screenAfterLogin = payload.screenAfterLogin; this.screenAfterLogin = payload.screenAfterLogin;
} }
this.setStateForNewView({ this.setStateForNewView({
view: VIEWS.LOGIN, view: Views.LOGIN,
}); });
this.notifyNewScreen('login'); this.notifyNewScreen('login');
ThemeController.isLogin = true; ThemeController.isLogin = true;
@ -546,12 +545,12 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
break; break;
case 'start_post_registration': case 'start_post_registration':
this.setState({ this.setState({
view: VIEWS.POST_REGISTRATION, view: Views.POST_REGISTRATION,
}); });
break; break;
case 'start_password_recovery': case 'start_password_recovery':
this.setStateForNewView({ this.setStateForNewView({
view: VIEWS.FORGOT_PASSWORD, view: Views.FORGOT_PASSWORD,
}); });
this.notifyNewScreen('forgot_password'); this.notifyNewScreen('forgot_password');
break; break;
@ -706,10 +705,10 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
case 'on_logged_in': case 'on_logged_in':
if ( if (
!Lifecycle.isSoftLogout() && !Lifecycle.isSoftLogout() &&
this.state.view !== VIEWS.LOGIN && this.state.view !== Views.LOGIN &&
this.state.view !== VIEWS.REGISTER && this.state.view !== Views.REGISTER &&
this.state.view !== VIEWS.COMPLETE_SECURITY && this.state.view !== Views.COMPLETE_SECURITY &&
this.state.view !== VIEWS.E2E_SETUP this.state.view !== Views.E2E_SETUP
) { ) {
this.onLoggedIn(); this.onLoggedIn();
} }
@ -781,7 +780,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
private async startRegistration(params: {[key: string]: string}) { private async startRegistration(params: {[key: string]: string}) {
const newState: Partial<IState> = { const newState: Partial<IState> = {
view: VIEWS.REGISTER, view: Views.REGISTER,
}; };
// Only honour params if they are all present, otherwise we reset // Only honour params if they are all present, otherwise we reset
@ -914,7 +913,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
presentedId += "/" + roomInfo.event_id; presentedId += "/" + roomInfo.event_id;
} }
this.setState({ this.setState({
view: VIEWS.LOGGED_IN, view: Views.LOGGED_IN,
currentRoomId: roomInfo.room_id || null, currentRoomId: roomInfo.room_id || null,
page_type: PageTypes.RoomView, page_type: PageTypes.RoomView,
thirdPartyInvite: roomInfo.third_party_invite, thirdPartyInvite: roomInfo.third_party_invite,
@ -938,7 +937,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
} }
private viewSomethingBehindModal() { private viewSomethingBehindModal() {
if (this.state.view !== VIEWS.LOGGED_IN) { if (this.state.view !== Views.LOGGED_IN) {
this.viewWelcome(); this.viewWelcome();
return; return;
} }
@ -949,7 +948,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
private viewWelcome() { private viewWelcome() {
this.setStateForNewView({ this.setStateForNewView({
view: VIEWS.WELCOME, view: Views.WELCOME,
}); });
this.notifyNewScreen('welcome'); this.notifyNewScreen('welcome');
ThemeController.isLogin = true; ThemeController.isLogin = true;
@ -959,7 +958,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
private viewHome() { private viewHome() {
// The home page requires the "logged in" view, so we'll set that. // The home page requires the "logged in" view, so we'll set that.
this.setStateForNewView({ this.setStateForNewView({
view: VIEWS.LOGGED_IN, view: Views.LOGGED_IN,
}); });
this.setPage(PageTypes.HomePage); this.setPage(PageTypes.HomePage);
this.notifyNewScreen('home'); this.notifyNewScreen('home');
@ -1216,7 +1215,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
*/ */
private async onLoggedIn() { private async onLoggedIn() {
ThemeController.isLogin = false; ThemeController.isLogin = false;
this.setStateForNewView({ view: VIEWS.LOGGED_IN }); this.setStateForNewView({ view: Views.LOGGED_IN });
// If a specific screen is set to be shown after login, show that above // 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. // all else, as it probably means the user clicked on something already.
if (this.screenAfterLogin && this.screenAfterLogin.screen) { if (this.screenAfterLogin && this.screenAfterLogin.screen) {
@ -1285,7 +1284,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
private onLoggedOut() { private onLoggedOut() {
this.notifyNewScreen('login'); this.notifyNewScreen('login');
this.setStateForNewView({ this.setStateForNewView({
view: VIEWS.LOGIN, view: Views.LOGIN,
ready: false, ready: false,
collapseLhs: false, collapseLhs: false,
currentRoomId: null, currentRoomId: null,
@ -1302,7 +1301,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
private onSoftLogout() { private onSoftLogout() {
this.notifyNewScreen('soft_logout'); this.notifyNewScreen('soft_logout');
this.setStateForNewView({ this.setStateForNewView({
view: VIEWS.SOFT_LOGOUT, view: Views.SOFT_LOGOUT,
ready: false, ready: false,
collapseLhs: false, collapseLhs: false,
currentRoomId: null, currentRoomId: null,
@ -1824,7 +1823,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
onFinishPostRegistration = () => { onFinishPostRegistration = () => {
// Don't confuse this with "PageType" which is the middle window to show // Don't confuse this with "PageType" which is the middle window to show
this.setState({ this.setState({
view: VIEWS.LOGGED_IN, view: Views.LOGGED_IN,
}); });
this.showScreen("settings"); this.showScreen("settings");
}; };
@ -1948,7 +1947,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
// Auto-enable cross-signing for the new session when key found in // Auto-enable cross-signing for the new session when key found in
// secret storage. // secret storage.
SettingsStore.setValue("feature_cross_signing", null, SettingLevel.DEVICE, true); SettingsStore.setValue("feature_cross_signing", null, SettingLevel.DEVICE, true);
this.setStateForNewView({ view: VIEWS.COMPLETE_SECURITY }); this.setStateForNewView({ view: Views.COMPLETE_SECURITY });
} else if ( } else if (
SettingsStore.getValue("feature_cross_signing") && SettingsStore.getValue("feature_cross_signing") &&
await cli.doesServerSupportUnstableFeature("org.matrix.e2e_cross_signing") await cli.doesServerSupportUnstableFeature("org.matrix.e2e_cross_signing")
@ -1956,7 +1955,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
// This will only work if the feature is set to 'enable' in the config, // This will only work if the feature is set to 'enable' in the config,
// since it's too early in the lifecycle for users to have turned the // since it's too early in the lifecycle for users to have turned the
// labs flag on. // labs flag on.
this.setStateForNewView({ view: VIEWS.E2E_SETUP }); this.setStateForNewView({ view: Views.E2E_SETUP });
} else { } else {
this.onLoggedIn(); this.onLoggedIn();
} }
@ -1975,21 +1974,21 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
let view; let view;
if (this.state.view === VIEWS.LOADING) { if (this.state.view === Views.LOADING) {
const Spinner = sdk.getComponent('elements.Spinner'); const Spinner = sdk.getComponent('elements.Spinner');
view = ( view = (
<div className="mx_MatrixChat_splash"> <div className="mx_MatrixChat_splash">
<Spinner /> <Spinner />
</div> </div>
); );
} else if (this.state.view === VIEWS.COMPLETE_SECURITY) { } else if (this.state.view === Views.COMPLETE_SECURITY) {
const CompleteSecurity = sdk.getComponent('structures.auth.CompleteSecurity'); const CompleteSecurity = sdk.getComponent('structures.auth.CompleteSecurity');
view = ( view = (
<CompleteSecurity <CompleteSecurity
onFinished={this.onCompleteSecurityE2eSetupFinished} onFinished={this.onCompleteSecurityE2eSetupFinished}
/> />
); );
} else if (this.state.view === VIEWS.E2E_SETUP) { } else if (this.state.view === Views.E2E_SETUP) {
const E2eSetup = sdk.getComponent('structures.auth.E2eSetup'); const E2eSetup = sdk.getComponent('structures.auth.E2eSetup');
view = ( view = (
<E2eSetup <E2eSetup
@ -1997,14 +1996,14 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
accountPassword={this.accountPassword} accountPassword={this.accountPassword}
/> />
); );
} else if (this.state.view === VIEWS.POST_REGISTRATION) { } else if (this.state.view === Views.POST_REGISTRATION) {
// needs to be before normal PageTypes as you are logged in technically // needs to be before normal PageTypes as you are logged in technically
const PostRegistration = sdk.getComponent('structures.auth.PostRegistration'); const PostRegistration = sdk.getComponent('structures.auth.PostRegistration');
view = ( view = (
<PostRegistration <PostRegistration
onComplete={this.onFinishPostRegistration} /> onComplete={this.onFinishPostRegistration} />
); );
} else if (this.state.view === VIEWS.LOGGED_IN) { } else if (this.state.view === Views.LOGGED_IN) {
// store errors stop the client syncing and require user intervention, so we'll // store errors stop the client syncing and require user intervention, so we'll
// be showing a dialog. Don't show anything else. // be showing a dialog. Don't show anything else.
const isStoreError = this.state.syncError && this.state.syncError instanceof InvalidStoreError; const isStoreError = this.state.syncError && this.state.syncError instanceof InvalidStoreError;
@ -2019,15 +2018,16 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
*/ */
const LoggedInView = sdk.getComponent('structures.LoggedInView'); const LoggedInView = sdk.getComponent('structures.LoggedInView');
view = ( view = (
<LoggedInView ref={this.loggedInView} <LoggedInView
{...this.props}
{...this.state}
ref={this.loggedInView}
matrixClient={MatrixClientPeg.get()} matrixClient={MatrixClientPeg.get()}
onRoomCreated={this.onRoomCreated} onRoomCreated={this.onRoomCreated}
onCloseAllSettings={this.onCloseAllSettings} onCloseAllSettings={this.onCloseAllSettings}
onRegistered={this.onRegistered} onRegistered={this.onRegistered}
currentRoomId={this.state.currentRoomId} currentRoomId={this.state.currentRoomId}
showCookieBar={this.state.showCookieBar} showCookieBar={this.state.showCookieBar}
{...this.props}
{...this.state}
/> />
); );
} else { } else {
@ -2049,10 +2049,10 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
</div> </div>
); );
} }
} else if (this.state.view === VIEWS.WELCOME) { } else if (this.state.view === Views.WELCOME) {
const Welcome = sdk.getComponent('auth.Welcome'); const Welcome = sdk.getComponent('auth.Welcome');
view = <Welcome {...this.getServerProperties()} />; view = <Welcome {...this.getServerProperties()} />;
} else if (this.state.view === VIEWS.REGISTER) { } else if (this.state.view === Views.REGISTER) {
const Registration = sdk.getComponent('structures.auth.Registration'); const Registration = sdk.getComponent('structures.auth.Registration');
view = ( view = (
<Registration <Registration
@ -2069,7 +2069,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
{...this.getServerProperties()} {...this.getServerProperties()}
/> />
); );
} else if (this.state.view === VIEWS.FORGOT_PASSWORD) { } else if (this.state.view === Views.FORGOT_PASSWORD) {
const ForgotPassword = sdk.getComponent('structures.auth.ForgotPassword'); const ForgotPassword = sdk.getComponent('structures.auth.ForgotPassword');
view = ( view = (
<ForgotPassword <ForgotPassword
@ -2079,7 +2079,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
{...this.getServerProperties()} {...this.getServerProperties()}
/> />
); );
} else if (this.state.view === VIEWS.LOGIN) { } else if (this.state.view === Views.LOGIN) {
const Login = sdk.getComponent('structures.auth.Login'); const Login = sdk.getComponent('structures.auth.Login');
view = ( view = (
<Login <Login
@ -2093,7 +2093,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
{...this.getServerProperties()} {...this.getServerProperties()}
/> />
); );
} else if (this.state.view === VIEWS.SOFT_LOGOUT) { } else if (this.state.view === Views.SOFT_LOGOUT) {
const SoftLogout = sdk.getComponent('structures.auth.SoftLogout'); const SoftLogout = sdk.getComponent('structures.auth.SoftLogout');
view = ( view = (
<SoftLogout <SoftLogout