diff --git a/src/app/hooks/useNotificationJumper.ts b/src/app/hooks/useNotificationJumper.ts index 6f7c7768..2f121d9e 100644 --- a/src/app/hooks/useNotificationJumper.ts +++ b/src/app/hooks/useNotificationJumper.ts @@ -8,6 +8,7 @@ import { useSyncState } from './useSyncState'; import { useMatrixClient } from './useMatrixClient'; import { getCanonicalAliasOrRoomId } from '../utils/matrix'; import { getDirectRoomPath, getHomeRoomPath, getSpaceRoomPath } from '../pages/pathUtils'; +import { getOrphanParents, guessPerfectParent } from '../utils/room'; import { roomToParentsAtom } from '../state/room/roomToParents'; import { createLogger } from '../utils/debug'; @@ -62,12 +63,15 @@ export function NotificationJumper() { // If the room lives inside a space, route through the space path so // SpaceRouteRoomProvider can resolve it — HomeRouteRoomProvider only // knows orphan rooms and would show JoinBeforeNavigate otherwise. - const parents = roomToParents.get(pending.roomId); - const firstParentId = parents && [...parents][0]; - if (firstParentId) { + // Use getOrphanParents + guessPerfectParent (same as useRoomNavigate) so + // we always navigate to a root-level space, not a subspace — subspace + // paths are not recognised by the router and land on JoinBeforeNavigate. + const orphanParents = getOrphanParents(roomToParents, pending.roomId); + if (orphanParents.length > 0) { + const parentSpace = guessPerfectParent(mx, pending.roomId, orphanParents) ?? orphanParents[0]; navigate( getSpaceRoomPath( - getCanonicalAliasOrRoomId(mx, firstParentId), + getCanonicalAliasOrRoomId(mx, parentSpace), roomIdOrAlias, pending.eventId )