Don't switch to the home page needlessly after leaving a room (#9477)

Currently, if you leave a room that you're not currently viewing, you'll get sent back to the home page for no reason. This creates needless friction when trying to leave multiple rooms belonging to a space from the room list.

In addition to that fix, this improves the behavior when leaving a subspace, by making it take you to the parent space rather than all the way back home.
This commit is contained in:
Robin 2022-11-10 07:34:43 -05:00 committed by GitHub
parent f6347d24ef
commit 06f69abad9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 150 additions and 11 deletions

View file

@ -128,17 +128,32 @@ export async function leaveRoomBehaviour(roomId: string, retry = true, spinner =
return;
}
if (!isMetaSpace(SpaceStore.instance.activeSpace) &&
SpaceStore.instance.activeSpace !== roomId &&
SdkContextClass.instance.roomViewStore.getRoomId() === roomId
) {
dis.dispatch<ViewRoomPayload>({
action: Action.ViewRoom,
room_id: SpaceStore.instance.activeSpace,
metricsTrigger: undefined, // other
});
} else {
dis.dispatch<ViewHomePagePayload>({ action: Action.ViewHomePage });
if (SdkContextClass.instance.roomViewStore.getRoomId() === roomId) {
// We were viewing the room that was just left. In order to avoid
// 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)) {
dis.dispatch<ViewHomePagePayload>({ action: Action.ViewHomePage });
} else if (SpaceStore.instance.activeSpace === roomId) {
// View the parent space, if there is one
const parent = SpaceStore.instance.getCanonicalParent(roomId);
if (parent !== null) {
dis.dispatch<ViewRoomPayload>({
action: Action.ViewRoom,
room_id: parent.roomId,
metricsTrigger: undefined, // other
});
} else {
dis.dispatch<ViewHomePagePayload>({ action: Action.ViewHomePage });
}
} else {
dis.dispatch<ViewRoomPayload>({
action: Action.ViewRoom,
room_id: SpaceStore.instance.activeSpace,
metricsTrigger: undefined, // other
});
}
}
}