Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit da43b33

Browse files
committed
Remove "on_logging_in" action
Signed-off-by: Mikhail Aheichyk <[email protected]>
1 parent 1c6d1bf commit da43b33

File tree

2 files changed

+8
-27
lines changed

2 files changed

+8
-27
lines changed

src/Lifecycle.ts

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,8 @@ dis.register((payload) => {
7373
onLoggedOut();
7474
} else if (payload.action === Action.OverwriteLogin) {
7575
const typed = <OverwriteLoginPayload>payload;
76-
// is invoked without dispatching of "on_logging_in"
7776
// noinspection JSIgnoredPromiseFromCall - we don't care if it fails
78-
doSetLoggedIn(typed.credentials, true, false);
77+
doSetLoggedIn(typed.credentials, true);
7978
}
8079
});
8180

@@ -569,19 +568,15 @@ export async function hydrateSession(credentials: IMatrixClientCreds): Promise<M
569568
}
570569

571570
/**
572-
* fires on_logging_in, optionally clears localstorage, persists new credentials
571+
* optionally clears localstorage, persists new credentials
573572
* to localstorage, starts the new client.
574573
*
575574
* @param {IMatrixClientCreds} credentials
576575
* @param {Boolean} clearStorageEnabled
577-
* @param {Boolean} dispatchOnLoggingIn if true then "on_logging_in" is dispatched
576+
*
578577
* @returns {Promise} promise which resolves to the new MatrixClient once it has been started
579578
*/
580-
async function doSetLoggedIn(
581-
credentials: IMatrixClientCreds,
582-
clearStorageEnabled: boolean,
583-
dispatchOnLoggingIn = true,
584-
): Promise<MatrixClient> {
579+
async function doSetLoggedIn(credentials: IMatrixClientCreds, clearStorageEnabled: boolean): Promise<MatrixClient> {
585580
credentials.guest = Boolean(credentials.guest);
586581

587582
const softLogout = isSoftLogout();
@@ -600,20 +595,6 @@ async function doSetLoggedIn(
600595
" freshLogin: " + credentials.freshLogin,
601596
);
602597

603-
// This is dispatched to indicate that the user is still in the process of logging in
604-
// because async code may take some time to resolve, breaking the assumption that
605-
// `setLoggedIn` takes an "instant" to complete, and dispatch `on_logged_in` a few ms
606-
// later than MatrixChat might assume.
607-
//
608-
// we fire it *synchronously* to make sure it fires before on_logged_in.
609-
// (dis.dispatch uses `window.setTimeout`, which does not guarantee ordering.)
610-
//
611-
// can be disabled to resolve "Cannot dispatch in the middle of a dispatch."
612-
// error when it is invoked via another dispatch that is not yet finished.
613-
if (dispatchOnLoggingIn) {
614-
dis.dispatch({ action: "on_logging_in" }, true);
615-
}
616-
617598
if (clearStorageEnabled) {
618599
await clearStorage();
619600
}

test/Lifecycle-test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,10 @@ describe("Lifecycle", () => {
6666
});
6767

6868
it("should setLoggedIn", async () => {
69-
// promise to wait 'on_logging_in'
70-
const loggingInPromise = new Promise((resolve, reject) => {
69+
// promise to wait 'on_logged_in'
70+
const loggedInPromise = new Promise((resolve, reject) => {
7171
defaultDispatcher.register((payload: ActionPayload) => {
72-
if (payload.action === "on_logging_in") {
72+
if (payload.action === Action.OnLoggedIn) {
7373
resolve(undefined);
7474
}
7575
});
@@ -81,6 +81,6 @@ describe("Lifecycle", () => {
8181
userId: "@some_user_id",
8282
});
8383

84-
await expect(loggingInPromise).resolves.toBeUndefined();
84+
await expect(loggedInPromise).resolves.toBeUndefined();
8585
});
8686
});

0 commit comments

Comments
 (0)