From 9e33ee823a580f3ac029a14729b3d031673facac Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Fri, 3 Dec 2021 09:52:31 +0000 Subject: [PATCH 1/2] When accepting DM from People metaspace don't switch to Home --- src/stores/spaces/SpaceStore.ts | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/src/stores/spaces/SpaceStore.ts b/src/stores/spaces/SpaceStore.ts index 9ec98cdeb11..13cd8b5b3a0 100644 --- a/src/stores/spaces/SpaceStore.ts +++ b/src/stores/spaces/SpaceStore.ts @@ -605,23 +605,22 @@ export class SpaceStoreClass extends AsyncStoreWithClient { private switchToRelatedSpace = (roomId: string) => { if (this.suggestedRooms.find(r => r.room_id === roomId)) return; - let parent = this.getCanonicalParent(roomId); + // try to find the canonical parent first + let parent: SpaceKey = this.getCanonicalParent(roomId)?.roomId; + + // otherwise, try to find a root space which contains this room if (!parent) { - parent = this.rootSpaces.find(s => this.spaceFilteredRooms.get(s.roomId)?.has(roomId)); + parent = this.rootSpaces.find(s => this.spaceFilteredRooms.get(s.roomId)?.has(roomId))?.roomId; } + + // otherwise, try to find a metaspace which contains this room if (!parent) { - const parentIds = Array.from(this.parentMap.get(roomId) || []); - for (const parentId of parentIds) { - const room = this.matrixClient.getRoom(parentId); - if (room) { - parent = room; - break; - } - } + // search meta spaces in reverse as Home is the first and least specific one + parent = [...this.enabledMetaSpaces].reverse().find(s => this.getSpaceFilteredRoomIds(s).has(roomId)); } // don't trigger a context switch when we are switching a space to match the chosen room - this.setActiveSpace(parent?.roomId ?? MetaSpace.Home, false); // TODO + this.setActiveSpace(parent ?? MetaSpace.Home, false); // TODO }; private onRoom = (room: Room, newMembership?: string, oldMembership?: string) => { @@ -848,10 +847,7 @@ export class SpaceStoreClass extends AsyncStoreWithClient { // Don't context switch when navigating to the space room // as it will cause you to end up in the wrong room this.setActiveSpace(room.roomId, false); - } else if ( - (!this.allRoomsInHome || this.activeSpace[0] === "!") && - !this.getSpaceFilteredRoomIds(this.activeSpace).has(roomId) - ) { + } else if (!this.getSpaceFilteredRoomIds(this.activeSpace).has(roomId)) { this.switchToRelatedSpace(roomId); } From 3670d5ae2c2ff367f9e939e0dc968b2e5a32c659 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Fri, 3 Dec 2021 11:11:04 +0000 Subject: [PATCH 2/2] Update tests to match improved behaviour --- test/stores/SpaceStore-test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/stores/SpaceStore-test.ts b/test/stores/SpaceStore-test.ts index d6d05668113..228d7da0597 100644 --- a/test/stores/SpaceStore-test.ts +++ b/test/stores/SpaceStore-test.ts @@ -810,11 +810,11 @@ describe("SpaceStore", () => { expect(store.activeSpace).toBe(space1); }); - it("switch to home for orphaned room", async () => { + it("switch to other rooms for orphaned room", async () => { viewRoom(room1); store.setActiveSpace(space1, false); viewRoom(orphan1); - expect(store.activeSpace).toBe(MetaSpace.Home); + expect(store.activeSpace).toBe(MetaSpace.Orphans); }); it("switch to first space when selected metaspace is disabled", async () => {