Open DMs during sync catch-up instead of blocking on parent maps.
Prefer the direct route for m.direct rooms and allow joined space children before roomToParents finishes backfilling.
This commit is contained in:
@@ -1,15 +1,19 @@
|
||||
import React, { ReactNode } from 'react';
|
||||
import { useParams } from 'react-router-dom';
|
||||
import { useAtomValue } from 'jotai';
|
||||
import { decodeRouteParam } from '../../pathUtils';
|
||||
import { useSelectedRoom } from '../../../hooks/router/useSelectedRoom';
|
||||
import { IsDirectRoomProvider, RoomProvider } from '../../../hooks/useRoom';
|
||||
import { useMatrixClient } from '../../../hooks/useMatrixClient';
|
||||
import { JoinBeforeNavigate } from '../../../features/join-before-navigate';
|
||||
import { useDirectRooms } from './useDirectRooms';
|
||||
import { mDirectAtom } from '../../../state/mDirectList';
|
||||
import { Membership } from '../../../../types/matrix/room';
|
||||
|
||||
export function DirectRouteRoomProvider({ children }: { children: ReactNode }) {
|
||||
const mx = useMatrixClient();
|
||||
const rooms = useDirectRooms();
|
||||
const mDirects = useAtomValue(mDirectAtom);
|
||||
|
||||
const { roomIdOrAlias: rawRoomIdOrAlias, eventId: rawEventId } = useParams();
|
||||
const roomIdOrAlias = decodeRouteParam(rawRoomIdOrAlias);
|
||||
@@ -17,7 +21,13 @@ export function DirectRouteRoomProvider({ children }: { children: ReactNode }) {
|
||||
const roomId = useSelectedRoom();
|
||||
const room = mx.getRoom(roomId);
|
||||
|
||||
if (!room || !rooms.includes(room.roomId)) {
|
||||
// useDirectRooms can lag m.direct / allRooms during catch-up; allow joined m.direct rooms.
|
||||
const isJoinedDirect =
|
||||
Boolean(room) &&
|
||||
room!.getMyMembership() === Membership.Join &&
|
||||
(rooms.includes(room!.roomId) || mDirects.has(room!.roomId));
|
||||
|
||||
if (!room || !isJoinedDirect) {
|
||||
return (
|
||||
<JoinBeforeNavigate
|
||||
roomIdOrAlias={roomIdOrAlias ?? rawRoomIdOrAlias!}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import React, { ReactNode } from 'react';
|
||||
import React, { ReactNode, useEffect } from 'react';
|
||||
import { useParams } from 'react-router-dom';
|
||||
import { useAtom, useAtomValue } from 'jotai';
|
||||
import { decodeRouteParam } from '../../pathUtils';
|
||||
@@ -30,7 +30,31 @@ export function SpaceRouteRoomProvider({ children }: { children: ReactNode }) {
|
||||
const roomId = useSelectedRoom();
|
||||
const room = mx.getRoom(roomId);
|
||||
|
||||
if (!room || !allRooms.includes(room.roomId)) {
|
||||
const isJoined = Boolean(room && allRooms.includes(room.roomId));
|
||||
const isSpaceChild = Boolean(room && getSpaceChildren(space).includes(room.roomId));
|
||||
const hasParentMapping = Boolean(
|
||||
room && getAllParents(roomToParents, room.roomId).has(space.roomId)
|
||||
);
|
||||
|
||||
// roomToParents can lag behind live space state during catch-up sync.
|
||||
// If the room is clearly a child of this space, backfill the map and open it.
|
||||
useEffect(() => {
|
||||
if (!room || !isJoined || hasParentMapping || !isSpaceChild) return;
|
||||
setRoomToParents({
|
||||
type: 'PUT',
|
||||
parent: space.roomId,
|
||||
children: [room.roomId],
|
||||
});
|
||||
}, [
|
||||
room,
|
||||
isJoined,
|
||||
hasParentMapping,
|
||||
isSpaceChild,
|
||||
space.roomId,
|
||||
setRoomToParents,
|
||||
]);
|
||||
|
||||
if (!room || !isJoined) {
|
||||
// room is not joined
|
||||
return (
|
||||
<JoinBeforeNavigate
|
||||
@@ -50,16 +74,7 @@ export function SpaceRouteRoomProvider({ children }: { children: ReactNode }) {
|
||||
);
|
||||
}
|
||||
|
||||
if (!getAllParents(roomToParents, room.roomId).has(space.roomId)) {
|
||||
if (getSpaceChildren(space).includes(room.roomId)) {
|
||||
// fill missing roomToParent mapping
|
||||
setRoomToParents({
|
||||
type: 'PUT',
|
||||
parent: space.roomId,
|
||||
children: [room.roomId],
|
||||
});
|
||||
}
|
||||
|
||||
if (!hasParentMapping && !isSpaceChild) {
|
||||
return (
|
||||
<JoinBeforeNavigate
|
||||
roomIdOrAlias={roomIdOrAlias ?? rawRoomIdOrAlias!}
|
||||
|
||||
Reference in New Issue
Block a user