Skip to content

Commit b7de7d3

Browse files
committed
Documentation in MatrixChat and Lifecycle
1 parent 52c04ab commit b7de7d3

2 files changed

Lines changed: 57 additions & 2 deletions

File tree

src/Lifecycle.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,9 @@ async function abortLogin(): Promise<void> {
599599
}
600600

601601
/** Attempt to restore the session from localStorage or indexeddb.
602+
*
603+
* If the credentials are found, and the session is successfully restored,
604+
* emits {@link Action.OnLoggedIn}, {@link Action.WillStartClient} and {@link Action.StartedClient}.
602605
*
603606
* @returns true if a session was found; false if no existing session was found.
604607
*
@@ -787,6 +790,8 @@ async function createOidcTokenRefresher(credentials: IMatrixClientCreds): Promis
787790
* optionally clears localstorage, persists new credentials
788791
* to localstorage, starts the new client.
789792
*
793+
* Emits {@link Action.OnLoggedIn}, {@link Action.WillStartClient} and {@link Action.StartedClient}.
794+
*
790795
* @param {IMatrixClientCreds} credentials The credentials to use
791796
* @param {Boolean} clearStorageEnabled True to clear storage before starting the new client
792797
* @param {Boolean} isFreshLogin True if this is a fresh login, false if it is previous session being restored
@@ -1019,6 +1024,12 @@ export function isLoggingOut(): boolean {
10191024
* Starts the matrix client and all other react-sdk services that
10201025
* listen for events while a session is logged in.
10211026
*
1027+
* By the time this method is called, we have successfully logged in if necessary, and the client has been set up with
1028+
* the access token.
1029+
*
1030+
* Emits {@link Acction.WillStartClient} before starting the client, and {@link Action.ClientStarted} when the client has
1031+
* been started.
1032+
*
10221033
* @param client the matrix client to start
10231034
* @param startSyncing - `true` to actually start syncing the client.
10241035
* @param clientPegOpts - Options to pass through to {@link MatrixClientPeg.start}.

src/components/structures/MatrixChat.tsx

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,13 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
225225
private firstSyncPromise: PromiseWithResolvers<void>;
226226

227227
private screenAfterLogin?: IScreen;
228+
229+
/** True if we have successfully completed an OIDC or token login.
230+
*
231+
* XXX it's unclear if this is ever cleared, so what happens if the user logs out and then logs back in?
232+
*/
228233
private tokenLogin?: boolean;
234+
229235
// What to focus on next component update, if anything
230236
private focusNext: FocusNextType;
231237
private subTitleStatus: string;
@@ -386,6 +392,26 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
386392
await Lifecycle.onSessionLockStolen();
387393
}
388394

395+
/**
396+
* Perform actions that are specific to a user that has just logged in (compare {@link onLoggedIn}, which, despite
397+
* its name, is called when an already-logged-in client is restored at session startup).
398+
*
399+
* Called when:
400+
*
401+
* - We successfully completed an OIDC or token login, via {@link initSession}.
402+
* - The {@link Login} or {@link Register} components notify us that we successfully completed a non-OIDC login or
403+
* registration.
404+
*
405+
* In both cases, {@link Action.OnLoggedIn} will already have been emitted, but the call to {@link onLoggedIn} will
406+
* have been suppressed (by either {@link tokenLogin} being set, or the view being set to {@link Views.LOGIN} or
407+
* {@link Views.REGISTER}).
408+
*
409+
* {@link onWillStartClient} and {@link onClientStarted} will already have been called (but not necessarily
410+
* completed).
411+
*
412+
* This method either calls {@link onLiggedIn} directly, or switches to {@link Views.E2E_SETUP} or
413+
* {@link Views.COMPLETE_SECURITY}, which will later call {@link onCompleteSecurityE2eSetupFinished}.
414+
*/
389415
private async postLoginSetup(): Promise<void> {
390416
const cli = MatrixClientPeg.safeGet();
391417
const cryptoEnabled = Boolean(cli.getCrypto());
@@ -1369,7 +1395,15 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
13691395
}
13701396

13711397
/**
1372-
* Called when a new logged in session has started
1398+
* Called when a new logged in session has started.
1399+
*
1400+
* Called:
1401+
*
1402+
* - on {@link Action.OnLoggedIn}, but only when we don't expect a separate call to {@link postLoginSetup}.
1403+
* - from {@link postLoginSetup}, when we don't have crypto setup tasks to perform after the login.
1404+
*
1405+
* It's never actually called if we have crypto setup tasks to perform after login (which we normally do, unless
1406+
* crypto is disabled.) XXX: is this a bug or a feature?
13731407
*/
13741408
private async onLoggedIn(): Promise<void> {
13751409
ThemeController.isLogin = false;
@@ -1379,6 +1413,16 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
13791413
await this.onShowPostLoginScreen();
13801414
}
13811415

1416+
/**
1417+
* Show the first screen after the application is successfully loaded in a logged-in state.
1418+
*
1419+
* Called:
1420+
*
1421+
* - by {@link onLoggedIn}
1422+
* - by {@link onCompleteSecurityE2eSetupFinished}
1423+
*
1424+
* In other words, whenever we think we have completed the login and E2E setup tasks.
1425+
*/
13821426
private async onShowPostLoginScreen(): Promise<void> {
13831427
this.setStateForNewView({ view: Views.LOGGED_IN });
13841428
// If a specific screen is set to be shown after login, show that above
@@ -2043,7 +2087,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
20432087
PerformanceMonitor.instance.stop(PerformanceEntryNames.REGISTER);
20442088
};
20452089

2046-
// complete security / e2e setup has finished
2090+
/** Called when {@link Views.E2E_SETUP} or {@link Views.COMPLETE_SECURITY} have completed. */
20472091
private onCompleteSecurityE2eSetupFinished = async (): Promise<void> => {
20482092
const forceVerify = await this.shouldForceVerification();
20492093
if (forceVerify) {

0 commit comments

Comments
 (0)