diff --git a/src/stores/RoomViewStore.tsx b/src/stores/RoomViewStore.tsx index 84b02df411..6112694777 100644 --- a/src/stores/RoomViewStore.tsx +++ b/src/stores/RoomViewStore.tsx @@ -93,7 +93,6 @@ export class RoomViewStore extends Store { public static readonly instance = new RoomViewStore(); private state = INITIAL_STATE; // initialize state - private forcedMatrixClient: MatrixClient; // Keep these out of state to avoid causing excessive/recursive updates private roomIdActivityListeners: Record = {}; @@ -102,14 +101,6 @@ export class RoomViewStore extends Store { super(dis); } - private get matrixClient(): MatrixClient { - return this.forcedMatrixClient || MatrixClientPeg.get(); - } - - public useUnitTestClient(client: MatrixClient) { - this.forcedMatrixClient = client; - } - public addRoomListener(roomId: string, fn: Listener) { if (!this.roomIdActivityListeners[roomId]) this.roomIdActivityListeners[roomId] = []; this.roomIdActivityListeners[roomId].push(fn); @@ -214,7 +205,7 @@ export class RoomViewStore extends Store { this.setState({ shouldPeek: false }); } - const cli = this.matrixClient; + const cli = MatrixClientPeg.get(); const updateMetrics = () => { const room = cli.getRoom(payload.roomId); @@ -290,7 +281,7 @@ export class RoomViewStore extends Store { trigger: payload.metricsTrigger, viaKeyboard: payload.metricsViaKeyboard, isDM: !!DMRoomMap.shared().getUserIdForRoomId(payload.room_id), - isSpace: this.matrixClient.getRoom(payload.room_id)?.isSpaceRoom(), + isSpace: MatrixClientPeg.get().getRoom(payload.room_id)?.isSpaceRoom(), activeSpace, }); } @@ -349,7 +340,7 @@ export class RoomViewStore extends Store { wasContextSwitch: payload.context_switch, }); try { - const result = await this.matrixClient.getRoomIdForAlias(payload.room_alias); + const result = await MatrixClientPeg.get().getRoomIdForAlias(payload.room_alias); storeRoomAliasInCache(payload.room_alias, result.room_id); roomId = result.room_id; } catch (err) { @@ -386,7 +377,7 @@ export class RoomViewStore extends Store { joining: true, }); - const cli = this.matrixClient; + const cli = MatrixClientPeg.get(); // take a copy of roomAlias & roomId as they may change by the time the join is complete const { roomAlias, roomId } = this.state; const address = roomAlias || roomId; @@ -418,7 +409,7 @@ export class RoomViewStore extends Store { } private getInvitingUserId(roomId: string): string { - const cli = this.matrixClient; + const cli = MatrixClientPeg.get(); const room = cli.getRoom(roomId); if (room && room.getMyMembership() === "invite") { const myMember = room.getMember(cli.getUserId()); @@ -443,7 +434,7 @@ export class RoomViewStore extends Store { // only provide a better error message for invites if (invitingUserId) { // if the inviting user is on the same HS, there can only be one cause: they left. - if (invitingUserId.endsWith(`:${this.matrixClient.getDomain()}`)) { + if (invitingUserId.endsWith(`:${MatrixClientPeg.get().getDomain()}`)) { description = _t("The person who invited you has already left."); } else { description = _t("The person who invited you has already left, or their server is offline."); diff --git a/test/components/structures/RightPanel-test.tsx b/test/components/structures/RightPanel-test.tsx index a845a7ed80..7d68d1753d 100644 --- a/test/components/structures/RightPanel-test.tsx +++ b/test/components/structures/RightPanel-test.tsx @@ -32,7 +32,6 @@ import { RightPanelPhases } from "../../../src/stores/right-panel/RightPanelStor import RightPanelStore from "../../../src/stores/right-panel/RightPanelStore"; import { UPDATE_EVENT } from "../../../src/stores/AsyncStore"; import { WidgetLayoutStore } from "../../../src/stores/widgets/WidgetLayoutStore"; -import { RoomViewStore } from "../../../src/stores/RoomViewStore"; describe("RightPanel", () => { it("renders info from only one room during room changes", async () => { @@ -76,7 +75,6 @@ describe("RightPanel", () => { // @ts-ignore await WidgetLayoutStore.instance.onReady(); RightPanelStore.instance.useUnitTestClient(cli); - RoomViewStore.instance.useUnitTestClient(cli); // @ts-ignore await RightPanelStore.instance.onReady(); diff --git a/test/components/views/elements/AppTile-test.tsx b/test/components/views/elements/AppTile-test.tsx index 2b07c214eb..8843a9c602 100644 --- a/test/components/views/elements/AppTile-test.tsx +++ b/test/components/views/elements/AppTile-test.tsx @@ -36,7 +36,6 @@ import WidgetStore, { IApp } from "../../../../src/stores/WidgetStore"; import AppTile from "../../../../src/components/views/elements/AppTile"; import { Container, WidgetLayoutStore } from "../../../../src/stores/widgets/WidgetLayoutStore"; import AppsDrawer from "../../../../src/components/views/rooms/AppsDrawer"; -import { RoomViewStore } from "../../../../src/stores/RoomViewStore"; describe("AppTile", () => { let cli; @@ -109,7 +108,6 @@ describe("AppTile", () => { // @ts-ignore await WidgetLayoutStore.instance.onReady(); RightPanelStore.instance.useUnitTestClient(cli); - RoomViewStore.instance.useUnitTestClient(cli); // @ts-ignore await RightPanelStore.instance.onReady(); });