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

Commit b607da5

Browse files
committed
Break import cycles by not directly depending on Lifecycle
1 parent e644b2b commit b607da5

File tree

4 files changed

+44
-6
lines changed

4 files changed

+44
-6
lines changed

src/Lifecycle.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ import VideoChannelStore from "./stores/VideoChannelStore";
6363
import { fixStuckDevices } from "./utils/VideoChannelUtils";
6464
import { Action } from "./dispatcher/actions";
6565
import AbstractLocalStorageSettingsHandler from "./settings/handlers/AbstractLocalStorageSettingsHandler";
66+
import { OverwriteLoginPayload } from "./dispatcher/payloads/OverwriteLoginPayload";
6667

6768
const HOMESERVER_URL_KEY = "mx_hs_url";
6869
const ID_SERVER_URL_KEY = "mx_is_url";
@@ -71,6 +72,10 @@ dis.register((payload) => {
7172
if (payload.action === Action.TriggerLogout) {
7273
// noinspection JSIgnoredPromiseFromCall - we don't care if it fails
7374
onLoggedOut();
75+
} else if (payload.action === Action.OverwriteLogin) {
76+
const typed = <OverwriteLoginPayload>payload;
77+
// noinspection JSIgnoredPromiseFromCall - we don't care if it fails
78+
doSetLoggedIn(typed.credentials, true);
7479
}
7580
});
7681

@@ -558,7 +563,7 @@ export async function hydrateSession(credentials: IMatrixClientCreds): Promise<M
558563
*
559564
* @returns {Promise} promise which resolves to the new MatrixClient once it has been started
560565
*/
561-
export async function doSetLoggedIn(
566+
async function doSetLoggedIn(
562567
credentials: IMatrixClientCreds,
563568
clearStorageEnabled: boolean,
564569
): Promise<MatrixClient> {

src/dispatcher/actions.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,4 +315,9 @@ export enum Action {
315315
* Fired when the client was logged in. No additional payload information required.
316316
*/
317317
OnLoggedIn = "on_logged_in",
318+
319+
/**
320+
* Overwrites the existing login with fresh session credentials. Use with a OverwriteLoginPayload.
321+
*/
322+
OverwriteLogin = "overwrite_login",
318323
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
Copyright 2022 The Matrix.org Foundation C.I.C.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
import { ActionPayload } from "../payloads";
18+
import { Action } from "../actions";
19+
import { IMatrixClientCreds } from "../../MatrixClientPeg";
20+
21+
export interface OverwriteLoginPayload extends ActionPayload {
22+
action: Action.OverwriteLogin;
23+
24+
credentials: IMatrixClientCreds;
25+
}

src/modules/ProxiedModuleApi.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ import { _t } from "../languageHandler";
2828
import { ModuleUiDialog } from "../components/views/dialogs/ModuleUiDialog";
2929
import SdkConfig from "../SdkConfig";
3030
import PlatformPeg from "../PlatformPeg";
31-
import { doSetLoggedIn } from "../Lifecycle";
3231
import dispatcher from "../dispatcher/dispatcher";
3332
import { navigateToPermalink } from "../utils/permalinks/navigator";
3433
import { parsePermalink } from "../utils/permalinks/Permalinks";
3534
import { MatrixClientPeg } from "../MatrixClientPeg";
3635
import { getCachedRoomIDForAlias } from "../RoomAliasCache";
3736
import { Action } from "../dispatcher/actions";
37+
import { OverwriteLoginPayload } from "../dispatcher/payloads/OverwriteLoginPayload";
3838

3939
/**
4040
* Glue between the `ModuleApi` interface and the react-sdk. Anticipates one instance
@@ -136,10 +136,13 @@ export class ProxiedModuleApi implements ModuleApi {
136136
* @override
137137
*/
138138
public async overwriteAccountAuth(accountInfo: AccountAuthInfo): Promise<void> {
139-
await doSetLoggedIn({
140-
...accountInfo,
141-
guest: false,
142-
}, true);
139+
dispatcher.dispatch<OverwriteLoginPayload>({
140+
action: Action.OverwriteLogin,
141+
credentials: {
142+
...accountInfo,
143+
guest: false,
144+
},
145+
}, true); // require to be sync to match inherited interface behaviour
143146
}
144147

145148
/**

0 commit comments

Comments
 (0)