Fix codepath which can wrongly cause automatic space switch from all rooms (#8560)

* Fix codepath which can wrongly cause automatic space switch from all rooms

* Improve typing
This commit is contained in:
Michael Telatynski 2022-05-11 16:44:02 +01:00 committed by GitHub
parent 13aa610cd2
commit f9c85ac7c2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 37 additions and 36 deletions

View file

@ -803,8 +803,7 @@ export class SpaceStoreClass extends AsyncStoreWithClient<IState> {
this.updateNotificationStates(notificationStatesToUpdate);
};
private switchSpaceIfNeeded = () => {
const roomId = RoomViewStore.instance.getRoomId();
private switchSpaceIfNeeded = (roomId = RoomViewStore.instance.getRoomId()) => {
if (!this.isRoomInSpace(this.activeSpace, roomId) && !this.matrixClient.getRoom(roomId)?.isSpaceRoom()) {
this.switchToRelatedSpace(roomId);
}
@ -856,7 +855,7 @@ export class SpaceStoreClass extends AsyncStoreWithClient<IState> {
// if the room currently being viewed was just joined then switch to its related space
if (newMembership === "join" && room.roomId === RoomViewStore.instance.getRoomId()) {
this.switchToRelatedSpace(room.roomId);
this.switchSpaceIfNeeded(room.roomId);
}
}
return;
@ -1131,8 +1130,8 @@ 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.isRoomInSpace(this.activeSpace, roomId)) {
this.switchToRelatedSpace(roomId);
} else {
this.switchSpaceIfNeeded(roomId);
}
// Persist last viewed room from a space