Skip to content

Commit 16a1e61

Browse files
committed
Add a new state between LOADING and LOGGED_IN
... so that we can transition into COMPLETE_SECURITY without going via LOGGED_IN.
1 parent ecd05e9 commit 16a1e61

2 files changed

Lines changed: 50 additions & 42 deletions

File tree

src/Views.ts

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -41,27 +41,31 @@ Please see LICENSE files in the repository root for full details.
4141
* │ │ │ │ "Sign in instead" ▲
4242
* │ │ └────────────────────────────────┐ │ │
4343
* │ └────────────────────────────────────────┐ │ │ │
44-
* │ ▼ ▼ ▼ │
45-
* │ ┌──────────────────┐ │
46-
* │ │ (postLoginSetup) │ │
47-
* │ └──────────────────┘ │
48-
* │ ┌────────────────────────────────────┘ │ │ │
49-
* │ │ E2EE not enabled ┌─────────────┘ └──────┐ │
50-
* │ │ │ Account has │ Account lacks │
51-
* │ │ │ cross-signing │ cross-signing │
52-
* │ │ │ keys │ keys │
53-
* │ │ Client started and ▼ ▼ │
54-
* │ │ force_verification ┌─────────────────┐ ┌─────────────────┐ │
55-
* │ │ pending │ COMPLETE_ │ │ E2E_SETUP │ │
56-
* │ │ ┌─────────────────►│ SECURITY │ │ │ │
57-
* │ │ │ └─────────────────┘ └─────────────────┘ │ "Forgotten
58-
* │ │ │ ┌───────────────────────┘ │ │ your
59-
* │ │ │ │ ┌───────────────────────────────────────────────┘ │ password?"
60-
* │ │ │ │ │ │
61-
* │ │ │ │ │ (from all other states │
62-
* │ │ │ │ │ except LOCK_STOLEN) │
63-
* │ │ │ │ │ └──────────────┐ │
64-
* ▼ ▼ │ ▼ ▼ Soft logout error ▼ │
44+
* ▼ ▼ ▼ ▼ │
45+
* ┌─────────────────┐ ┌──────────────────┐ │
46+
* │ PENDING_CLIENT_ │ │ (postLoginSetup) │ │
47+
* │ START │ └──────────────────┘ │
48+
* └─────────────────┘ Account has │ │ │ Account lacks │
49+
* │ │ cross-signing │ │ │ cross-signing │
50+
* │ └───┐ keys │ │ │ keys │
51+
* │ Client │ │ │ │ │
52+
* │ started, │ Client started and │ │ │ │
53+
* │ force_verif │ force_verification │ │ └──────┐ │
54+
* │ not reqd │ pending │ │ │ │
55+
* │ ▼ │ │ │ │
56+
* │ ┌─────────────────┐ │ │ │ │
57+
* │ │ COMPLETE_ │◄─────────────────┘ │ ▼ │
58+
* │ │ SECURITY │ │ ┌─────────────────┐ │
59+
* │ └─────────────────┘ │ │ E2E_SETUP │ │
60+
* │ │ │ │ │ │
61+
* │ ┌─────────┘ E2EE not enabled │ └─────────────────┘ │ "Forgotten
62+
* │ │ ┌──────────────────────────────────────┘ │ │ your
63+
* │ │ │ ┌───────────────────────────────────────────────┘ │ password?"
64+
* │ │ │ │ │
65+
* │ │ │ │ (from all other states │
66+
* │ │ │ │ except LOCK_STOLEN) │
67+
* │ │ │ │ └──────────────┐ │
68+
* ▼ ▼ ▼ ▼ Soft logout error ▼ │
6569
* ┌─────────────────┐ ┌─────────────────┐
6670
* │ LOGGED_IN │ Re-authentication succeeded │ SOFT_LOGOUT │
6771
* │ │◄────────────────────────────────────────────────────────│ │
@@ -102,6 +106,12 @@ enum Views {
102106
// flow to setup SSSS / cross-signing on this account
103107
E2E_SETUP,
104108

109+
/**
110+
* We have successfully recovered a session from localstorage, but the client
111+
* has not yet been started.
112+
*/
113+
PENDING_CLIENT_START,
114+
105115
// we are logged in with an active matrix client. The logged_in state also
106116
// includes guests users as they too are logged in at the client level.
107117
LOGGED_IN,

src/components/structures/MatrixChat.tsx

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1520,18 +1520,8 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
15201520
this.stores.client = MatrixClientPeg.safeGet();
15211521
StorageManager.tryPersistStorage();
15221522

1523-
// If we're in the middle of a login/registration, we wait for it to complete before transitioning to the logged
1524-
// in view the login flow will call `postLoginSetup` when it's done, which will arrange for `onShowPostLoginScreen`
1525-
// to be called.
1526-
if (
1527-
!this.tokenLogin &&
1528-
!Lifecycle.isSoftLogout() &&
1529-
this.state.view !== Views.LOGIN &&
1530-
this.state.view !== Views.REGISTER &&
1531-
this.state.view !== Views.COMPLETE_SECURITY &&
1532-
this.state.view !== Views.E2E_SETUP
1533-
) {
1534-
this.onShowPostLoginScreen();
1523+
if (this.state.view === Views.LOADING && !Lifecycle.isSoftLogout() && !this.tokenLogin) {
1524+
this.setStateForNewView({ view: Views.PENDING_CLIENT_START });
15351525
}
15361526
}
15371527

@@ -1764,15 +1754,6 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
17641754
const cli = MatrixClientPeg.safeGet();
17651755

17661756
const shouldForceVerification = await this.shouldForceVerification();
1767-
// XXX: Don't replace the screen if it's already one of these: postLoginSetup
1768-
// changes to these screens in certain circumstances so we shouldn't clobber it.
1769-
// We should probably have one place where we decide what the next screen is after
1770-
// login.
1771-
if (![Views.COMPLETE_SECURITY, Views.E2E_SETUP].includes(this.state.view)) {
1772-
if (shouldForceVerification) {
1773-
this.setStateForNewView({ view: Views.COMPLETE_SECURITY });
1774-
}
1775-
}
17761757

17771758
const crypto = cli.getCrypto();
17781759
if (crypto) {
@@ -1789,6 +1770,14 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
17891770
this.setState({
17901771
ready: true,
17911772
});
1773+
1774+
if (this.state.view === Views.PENDING_CLIENT_START) {
1775+
if (shouldForceVerification) {
1776+
this.setStateForNewView({ view: Views.COMPLETE_SECURITY });
1777+
} else {
1778+
await this.onShowPostLoginScreen();
1779+
}
1780+
}
17921781
}
17931782

17941783
public showScreen(screen: string, params?: { [key: string]: any }): void {
@@ -2147,6 +2136,15 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
21472136
view = <CompleteSecurity onFinished={this.onCompleteSecurityE2eSetupFinished} />;
21482137
} else if (this.state.view === Views.E2E_SETUP) {
21492138
view = <E2eSetup onCancelled={this.onCompleteSecurityE2eSetupFinished} />;
2139+
} else if (this.state.view === Views.PENDING_CLIENT_START) {
2140+
// we think we are logged in, but are still waiting for the /sync to complete
2141+
view = (
2142+
<LoginSplashView
2143+
matrixClient={MatrixClientPeg.safeGet()}
2144+
onLogoutClick={this.onLogoutClick}
2145+
syncError={this.state.syncError}
2146+
/>
2147+
);
21502148
} else if (this.state.view === Views.LOGGED_IN) {
21512149
// `ready` and `view==LOGGED_IN` may be set before `page_type` (because the
21522150
// latter is set via the dispatcher). If we don't yet have a `page_type`,

0 commit comments

Comments
 (0)