Remove SpaceStore singleton (#34088)
* Remove dead code * Remove LegacyCallHandler singleton Route via SDKContext to cut import cycles * Remove SpaceStore singleton Route via SDKContext to cut import cycles * Fix tests * Fix tests * Fix tests * Fix tests * Iterate * Post-merge fixup * Iterate
This commit is contained in:
@@ -14,9 +14,9 @@ import { showAnyInviteErrors } from "../RoomInvite";
|
||||
import Modal, { type IHandle } from "../Modal";
|
||||
import { _t } from "../languageHandler";
|
||||
import ErrorDialog from "../components/views/dialogs/ErrorDialog";
|
||||
import SpaceStore from "../stores/spaces/SpaceStore";
|
||||
import Spinner from "../components/views/elements/Spinner";
|
||||
import MultiInviter, { type MultiInviterOptions } from "./MultiInviter";
|
||||
import { SDKContextClass } from "../contexts/SDKContextClass.ts";
|
||||
|
||||
export interface RoomUpgradeProgress {
|
||||
roomUpgraded: boolean;
|
||||
@@ -73,7 +73,7 @@ export async function upgradeRoom(
|
||||
|
||||
let parentsToRelink: Room[] = [];
|
||||
if (updateSpaces) {
|
||||
parentsToRelink = Array.from(SpaceStore.instance.getKnownParents(room.roomId))
|
||||
parentsToRelink = Array.from(SDKContextClass.instance.spaceStore.getKnownParents(room.roomId))
|
||||
.map((roomId) => cli.getRoom(roomId))
|
||||
.filter((parent) =>
|
||||
parent?.currentState.maySendStateEvent(EventType.SpaceChild, cli.getUserId()!),
|
||||
|
||||
@@ -8,10 +8,10 @@ Please see LICENSE files in the repository root for full details.
|
||||
|
||||
import { type Room } from "matrix-js-sdk/src/matrix";
|
||||
|
||||
import SpaceStore from "../stores/spaces/SpaceStore";
|
||||
import { _t } from "../languageHandler";
|
||||
import DMRoomMap from "./DMRoomMap";
|
||||
import { formatList } from "./FormattingUtils";
|
||||
import { SDKContextClass } from "../contexts/SDKContextClass.ts";
|
||||
|
||||
export interface RoomContextDetails {
|
||||
details: string | null;
|
||||
@@ -26,7 +26,7 @@ export function roomContextDetails(room: Room): RoomContextDetails | null {
|
||||
return { details: dmPartner };
|
||||
}
|
||||
|
||||
const [parent, secondParent, ...otherParents] = SpaceStore.instance.getKnownParents(room.roomId);
|
||||
const [parent, secondParent, ...otherParents] = SDKContextClass.instance.spaceStore.getKnownParents(room.roomId);
|
||||
if (secondParent && !otherParents?.length) {
|
||||
// exactly 2 edge case for improved i18n
|
||||
const space1Name = room.client.getRoom(parent)?.name;
|
||||
|
||||
@@ -20,7 +20,6 @@ import { Action } from "../dispatcher/actions";
|
||||
import { leaveRoomBehaviour } from "./leave-behaviour";
|
||||
import { SDKContextClass } from "../contexts/SDKContextClass";
|
||||
import DMRoomMap from "../utils/DMRoomMap";
|
||||
import SpaceStore from "../stores/spaces/SpaceStore";
|
||||
import { MetaSpace } from "../stores/spaces";
|
||||
import { type ActionPayload } from "../dispatcher/payloads";
|
||||
import SettingsStore from "../settings/SettingsStore";
|
||||
@@ -55,12 +54,12 @@ describe("leaveRoomBehaviour", () => {
|
||||
}
|
||||
});
|
||||
|
||||
await setupAsyncStoreWithClient(SpaceStore.instance, client);
|
||||
await setupAsyncStoreWithClient(SDKContextClass.instance.spaceStore, client);
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
SpaceStore.instance.setActiveSpace(MetaSpace.Home);
|
||||
await resetAsyncStoreWithClient(SpaceStore.instance);
|
||||
SDKContextClass.instance.spaceStore.setActiveSpace(MetaSpace.Home);
|
||||
await resetAsyncStoreWithClient(SDKContextClass.instance.spaceStore);
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
|
||||
@@ -114,11 +113,11 @@ describe("leaveRoomBehaviour", () => {
|
||||
});
|
||||
|
||||
it("returns to the parent space after leaving a room inside of a space that was being viewed", async () => {
|
||||
vi.spyOn(SpaceStore.instance, "getCanonicalParent").mockImplementation((roomId) =>
|
||||
vi.spyOn(SDKContextClass.instance.spaceStore, "getCanonicalParent").mockImplementation((roomId) =>
|
||||
roomId === room.roomId ? space : null,
|
||||
);
|
||||
viewRoom(room);
|
||||
SpaceStore.instance.setActiveSpace(space.roomId, false);
|
||||
SDKContextClass.instance.spaceStore.setActiveSpace(space.roomId, false);
|
||||
|
||||
await leaveRoomBehaviour(client, room.roomId);
|
||||
await expectDispatch({
|
||||
@@ -130,7 +129,7 @@ describe("leaveRoomBehaviour", () => {
|
||||
|
||||
it("returns to the home page after leaving a top-level space that was being viewed", async () => {
|
||||
viewRoom(space);
|
||||
SpaceStore.instance.setActiveSpace(space.roomId, false);
|
||||
SDKContextClass.instance.spaceStore.setActiveSpace(space.roomId, false);
|
||||
|
||||
await leaveRoomBehaviour(client, space.roomId);
|
||||
await expectDispatch({ action: Action.ViewHomePage });
|
||||
@@ -138,11 +137,11 @@ describe("leaveRoomBehaviour", () => {
|
||||
|
||||
it("returns to the parent space after leaving a subspace that was being viewed", async () => {
|
||||
room.isSpaceRoom.mockReturnValue(true);
|
||||
vi.spyOn(SpaceStore.instance, "getCanonicalParent").mockImplementation((roomId) =>
|
||||
vi.spyOn(SDKContextClass.instance.spaceStore, "getCanonicalParent").mockImplementation((roomId) =>
|
||||
roomId === room.roomId ? space : null,
|
||||
);
|
||||
viewRoom(room);
|
||||
SpaceStore.instance.setActiveSpace(room.roomId, false);
|
||||
SDKContextClass.instance.spaceStore.setActiveSpace(room.roomId, false);
|
||||
|
||||
await leaveRoomBehaviour(client, room.roomId);
|
||||
await expectDispatch({
|
||||
|
||||
@@ -16,7 +16,6 @@ import Spinner from "../components/views/elements/Spinner";
|
||||
import { _t } from "../languageHandler";
|
||||
import ErrorDialog from "../components/views/dialogs/ErrorDialog";
|
||||
import { isMetaSpace } from "../stores/spaces";
|
||||
import SpaceStore from "../stores/spaces/SpaceStore";
|
||||
import dis from "../dispatcher/dispatcher";
|
||||
import { type ViewRoomPayload } from "../dispatcher/payloads/ViewRoomPayload";
|
||||
import { Action } from "../dispatcher/actions";
|
||||
@@ -165,11 +164,11 @@ export async function leaveRoomBehaviour(
|
||||
// accidentally viewing the next room in the list and clearing its
|
||||
// notifications, switch to a neutral ground such as the home page or
|
||||
// space landing page.
|
||||
if (isMetaSpace(SpaceStore.instance.activeSpace)) {
|
||||
if (isMetaSpace(SDKContextClass.instance.spaceStore.activeSpace)) {
|
||||
dis.dispatch<ViewHomePagePayload>({ action: Action.ViewHomePage });
|
||||
} else if (SpaceStore.instance.activeSpace === roomId) {
|
||||
} else if (SDKContextClass.instance.spaceStore.activeSpace === roomId) {
|
||||
// View the parent space, if there is one
|
||||
const parent = SpaceStore.instance.getCanonicalParent(roomId);
|
||||
const parent = SDKContextClass.instance.spaceStore.getCanonicalParent(roomId);
|
||||
if (parent !== null) {
|
||||
dis.dispatch<ViewRoomPayload>({
|
||||
action: Action.ViewRoom,
|
||||
@@ -182,7 +181,7 @@ export async function leaveRoomBehaviour(
|
||||
} else {
|
||||
dis.dispatch<ViewRoomPayload>({
|
||||
action: Action.ViewRoom,
|
||||
room_id: SpaceStore.instance.activeSpace,
|
||||
room_id: SDKContextClass.instance.spaceStore.activeSpace,
|
||||
metricsTrigger: undefined, // other
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user