Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

When accepting DM from People metaspace don't switch to Home #7272

Merged
merged 2 commits into from
Dec 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 11 additions & 15 deletions src/stores/spaces/SpaceStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -605,23 +605,22 @@ export class SpaceStoreClass extends AsyncStoreWithClient<IState> {
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is "TODO" still relevant here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah because MetaSpace.Home may be disabled so its an unhandled (Labs) edge-case

};

private onRoom = (room: Room, newMembership?: string, oldMembership?: string) => {
Expand Down Expand Up @@ -848,10 +847,7 @@ export class SpaceStoreClass extends AsyncStoreWithClient<IState> {
// 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);
}

Expand Down
4 changes: 2 additions & 2 deletions test/stores/SpaceStore-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down