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

Commit 3a59556

Browse files
authored
Revert #124 and #135 (#139)
This seems to be causing a lot of weirdness, presumably because there's another missing thing like in #135, but I don't know what it might be and it feels like it might take a while to find. Backing these changes out to fix develop while we sort it out. Fixes element-hq/element-web#28179
1 parent 4e5cf1b commit 3a59556

30 files changed

+78
-88
lines changed

src/MatrixClientPeg.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ import { formatList } from "./utils/FormattingUtils";
4343
import SdkConfig from "./SdkConfig";
4444
import { Features } from "./settings/Settings";
4545
import { setDeviceIsolationMode } from "./settings/controllers/DeviceIsolationModeController.ts";
46-
import { ReadyWatchingStore } from "./stores/ReadyWatchingStore.ts";
4746

4847
export interface IMatrixClientCreds {
4948
homeserverUrl: string;
@@ -310,7 +309,6 @@ class MatrixClientPegClass implements IMatrixClientPeg {
310309
MatrixActionCreators.start(this.matrixClient);
311310
MatrixClientBackedSettingsHandler.matrixClient = this.matrixClient;
312311
MatrixClientBackedController.matrixClient = this.matrixClient;
313-
ReadyWatchingStore.matrixClient = this.matrixClient;
314312

315313
return opts;
316314
}

src/stores/AsyncStoreWithClient.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,8 @@ export abstract class AsyncStoreWithClient<T extends Object> extends AsyncStore<
3636
})(dispatcher);
3737
}
3838

39-
protected async start(matrixClient: MatrixClient | null): Promise<void> {
40-
await this.readyStore.start(matrixClient);
41-
}
42-
43-
// XXX: This method is intended only for use in tests.
44-
public async useUnitTestClient(cli: MatrixClient): Promise<void> {
45-
await this.readyStore.useUnitTestClient(cli);
39+
public async start(): Promise<void> {
40+
await this.readyStore.start();
4641
}
4742

4843
public get matrixClient(): MatrixClient | null {

src/stores/AutoRageshakeStore.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ interface IState {
4646
*/
4747
export default class AutoRageshakeStore extends AsyncStoreWithClient<IState> {
4848
private static readonly internalInstance = (() => {
49-
return new AutoRageshakeStore();
49+
const instance = new AutoRageshakeStore();
50+
instance.start();
51+
return instance;
5052
})();
5153

5254
private constructor() {

src/stores/BreadcrumbsStore.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ interface IState {
3030

3131
export class BreadcrumbsStore extends AsyncStoreWithClient<IState> {
3232
private static readonly internalInstance = (() => {
33-
return new BreadcrumbsStore();
33+
const instance = new BreadcrumbsStore();
34+
instance.start();
35+
return instance;
3436
})();
3537

3638
private waitingRooms: { roomId: string; addedTs: number }[] = [];

src/stores/CallStore.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export class CallStore extends AsyncStoreWithClient<{}> {
3131
public static get instance(): CallStore {
3232
if (!this._instance) {
3333
this._instance = new CallStore();
34+
this._instance.start();
3435
}
3536
return this._instance;
3637
}

src/stores/ModalWidgetStore.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ interface IState {
2424
export class ModalWidgetStore extends AsyncStoreWithClient<IState> {
2525
private static readonly internalInstance = (() => {
2626
const instance = new ModalWidgetStore();
27+
instance.start();
2728
return instance;
2829
})();
2930
private modalInstance: IHandle<typeof ModalWidgetDialog> | null = null;

src/stores/OwnBeaconStore.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ const getLocallyCreatedBeaconEventIds = (): string[] => {
8787
export class OwnBeaconStore extends AsyncStoreWithClient<OwnBeaconStoreState> {
8888
private static readonly internalInstance = (() => {
8989
const instance = new OwnBeaconStore();
90+
instance.start();
9091
return instance;
9192
})();
9293
// users beacons, keyed by event type

src/stores/OwnProfileStore.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const KEY_AVATAR_URL = "mx_profile_avatar_url";
2828
export class OwnProfileStore extends AsyncStoreWithClient<IState> {
2929
private static readonly internalInstance = (() => {
3030
const instance = new OwnProfileStore();
31+
instance.start();
3132
return instance;
3233
})();
3334

src/stores/ReadyWatchingStore.ts

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9,42 +9,27 @@
99
import { MatrixClient, SyncState } from "matrix-js-sdk/src/matrix";
1010
import { EventEmitter } from "events";
1111

12+
import { MatrixClientPeg } from "../MatrixClientPeg";
1213
import { ActionPayload } from "../dispatcher/payloads";
1314
import { IDestroyable } from "../utils/IDestroyable";
1415
import { Action } from "../dispatcher/actions";
1516
import { MatrixDispatcher } from "../dispatcher/dispatcher";
1617

1718
export abstract class ReadyWatchingStore extends EventEmitter implements IDestroyable {
18-
private static instances: ReadyWatchingStore[] = [];
19-
protected _matrixClient: MatrixClient | null = null;
19+
protected matrixClient: MatrixClient | null = null;
2020
private dispatcherRef: string | null = null;
2121

22-
public static set matrixClient(client: MatrixClient) {
23-
for (const instance of ReadyWatchingStore.instances) {
24-
instance.start(client);
25-
}
26-
}
27-
2822
public constructor(protected readonly dispatcher: MatrixDispatcher) {
2923
super();
30-
31-
this.dispatcherRef = this.dispatcher.register(this.onAction);
32-
33-
ReadyWatchingStore.instances.push(this);
34-
}
35-
36-
public get matrixClient(): MatrixClient | null {
37-
return this._matrixClient;
3824
}
3925

40-
public async start(matrixClient: MatrixClient | null): Promise<void> {
41-
const oldClient = this._matrixClient;
42-
this._matrixClient = matrixClient;
26+
public async start(): Promise<void> {
27+
this.dispatcherRef = this.dispatcher.register(this.onAction);
4328

44-
if (oldClient !== matrixClient) {
45-
await this.onNotReady();
46-
}
29+
// MatrixClientPeg can be undefined in tests because of circular dependencies with other stores
30+
const matrixClient = MatrixClientPeg?.get();
4731
if (matrixClient) {
32+
this.matrixClient = matrixClient;
4833
await this.onReady();
4934
}
5035
}
@@ -53,10 +38,8 @@ export abstract class ReadyWatchingStore extends EventEmitter implements IDestro
5338
return this.matrixClient; // for external readonly access
5439
}
5540

56-
// XXX: This method is intended only for use in tests.
57-
public async useUnitTestClient(cli: MatrixClient): Promise<void> {
58-
this._matrixClient = cli;
59-
await this.onReady();
41+
public useUnitTestClient(cli: MatrixClient): void {
42+
this.matrixClient = cli;
6043
}
6144

6245
public destroy(): void {
@@ -91,13 +74,13 @@ export abstract class ReadyWatchingStore extends EventEmitter implements IDestro
9174
if (this.matrixClient) {
9275
await this.onNotReady();
9376
}
94-
this._matrixClient = payload.matrixClient;
77+
this.matrixClient = payload.matrixClient;
9578
await this.onReady();
9679
}
9780
} else if (payload.action === "on_client_not_viable" || payload.action === Action.OnLoggedOut) {
9881
if (this.matrixClient) {
9982
await this.onNotReady();
100-
this._matrixClient = null;
83+
this.matrixClient = null;
10184
}
10285
}
10386
};

src/stores/VoiceRecordingStore.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export class VoiceRecordingStore extends AsyncStoreWithClient<IState> {
3030
public static get instance(): VoiceRecordingStore {
3131
if (!this.internalInstance) {
3232
this.internalInstance = new VoiceRecordingStore();
33+
this.internalInstance.start();
3334
}
3435
return this.internalInstance;
3536
}

0 commit comments

Comments
 (0)