Merge pull request #6906 from matrix-org/t3chguy/fix/19246
commit
5264b1db9d
|
@ -15,17 +15,17 @@ limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import React, {
|
import React, {
|
||||||
|
Dispatch,
|
||||||
|
KeyboardEvent,
|
||||||
|
KeyboardEventHandler,
|
||||||
ReactNode,
|
ReactNode,
|
||||||
|
SetStateAction,
|
||||||
useCallback,
|
useCallback,
|
||||||
|
useContext,
|
||||||
useEffect,
|
useEffect,
|
||||||
useMemo,
|
useMemo,
|
||||||
useRef,
|
useRef,
|
||||||
useState,
|
useState,
|
||||||
KeyboardEvent,
|
|
||||||
KeyboardEventHandler,
|
|
||||||
useContext,
|
|
||||||
SetStateAction,
|
|
||||||
Dispatch,
|
|
||||||
} from "react";
|
} from "react";
|
||||||
import { Room } from "matrix-js-sdk/src/models/room";
|
import { Room } from "matrix-js-sdk/src/models/room";
|
||||||
import { RoomHierarchy } from "matrix-js-sdk/src/room-hierarchy";
|
import { RoomHierarchy } from "matrix-js-sdk/src/room-hierarchy";
|
||||||
|
@ -33,7 +33,8 @@ import { EventType, RoomType } from "matrix-js-sdk/src/@types/event";
|
||||||
import { IHierarchyRelation, IHierarchyRoom } from "matrix-js-sdk/src/@types/spaces";
|
import { IHierarchyRelation, IHierarchyRoom } from "matrix-js-sdk/src/@types/spaces";
|
||||||
import { MatrixClient } from "matrix-js-sdk/src/matrix";
|
import { MatrixClient } from "matrix-js-sdk/src/matrix";
|
||||||
import classNames from "classnames";
|
import classNames from "classnames";
|
||||||
import { sortBy } from "lodash";
|
import { sortBy, uniqBy } from "lodash";
|
||||||
|
import { GuestAccess, HistoryVisibility } from "matrix-js-sdk/src/@types/partials";
|
||||||
|
|
||||||
import dis from "../../dispatcher/dispatcher";
|
import dis from "../../dispatcher/dispatcher";
|
||||||
import defaultDispatcher from "../../dispatcher/dispatcher";
|
import defaultDispatcher from "../../dispatcher/dispatcher";
|
||||||
|
@ -333,6 +334,30 @@ interface IHierarchyLevelProps {
|
||||||
onToggleClick?(parentId: string, childId: string): void;
|
onToggleClick?(parentId: string, childId: string): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const toLocalRoom = (cli: MatrixClient, room: IHierarchyRoom): IHierarchyRoom => {
|
||||||
|
const history = cli.getRoomUpgradeHistory(room.room_id, true);
|
||||||
|
const cliRoom = history[history.length - 1];
|
||||||
|
if (cliRoom) {
|
||||||
|
return {
|
||||||
|
...room,
|
||||||
|
room_id: cliRoom.roomId,
|
||||||
|
room_type: cliRoom.getType(),
|
||||||
|
name: cliRoom.name,
|
||||||
|
topic: cliRoom.currentState.getStateEvents(EventType.RoomTopic, "")?.getContent().topic,
|
||||||
|
avatar_url: cliRoom.getMxcAvatarUrl(),
|
||||||
|
canonical_alias: cliRoom.getCanonicalAlias(),
|
||||||
|
aliases: cliRoom.getAltAliases(),
|
||||||
|
world_readable: cliRoom.currentState.getStateEvents(EventType.RoomHistoryVisibility, "")?.getContent()
|
||||||
|
.history_visibility === HistoryVisibility.WorldReadable,
|
||||||
|
guest_can_join: cliRoom.currentState.getStateEvents(EventType.RoomGuestAccess, "")?.getContent()
|
||||||
|
.guest_access === GuestAccess.CanJoin,
|
||||||
|
num_joined_members: cliRoom.getJoinedMemberCount(),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return room;
|
||||||
|
};
|
||||||
|
|
||||||
export const HierarchyLevel = ({
|
export const HierarchyLevel = ({
|
||||||
root,
|
root,
|
||||||
roomSet,
|
roomSet,
|
||||||
|
@ -353,7 +378,7 @@ export const HierarchyLevel = ({
|
||||||
const [subspaces, childRooms] = sortedChildren.reduce((result, ev: IHierarchyRelation) => {
|
const [subspaces, childRooms] = sortedChildren.reduce((result, ev: IHierarchyRelation) => {
|
||||||
const room = hierarchy.roomMap.get(ev.state_key);
|
const room = hierarchy.roomMap.get(ev.state_key);
|
||||||
if (room && roomSet.has(room)) {
|
if (room && roomSet.has(room)) {
|
||||||
result[room.room_type === RoomType.Space ? 0 : 1].push(room);
|
result[room.room_type === RoomType.Space ? 0 : 1].push(toLocalRoom(cli, room));
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}, [[] as IHierarchyRoom[], [] as IHierarchyRoom[]]);
|
}, [[] as IHierarchyRoom[], [] as IHierarchyRoom[]]);
|
||||||
|
@ -361,7 +386,7 @@ export const HierarchyLevel = ({
|
||||||
const newParents = new Set(parents).add(root.room_id);
|
const newParents = new Set(parents).add(root.room_id);
|
||||||
return <React.Fragment>
|
return <React.Fragment>
|
||||||
{
|
{
|
||||||
childRooms.map(room => (
|
uniqBy(childRooms, "room_id").map(room => (
|
||||||
<Tile
|
<Tile
|
||||||
key={room.room_id}
|
key={room.room_id}
|
||||||
room={room}
|
room={room}
|
||||||
|
|
|
@ -283,7 +283,8 @@ export class SpaceStoreClass extends AsyncStoreWithClient<IState> {
|
||||||
const createTs = childRoom?.currentState.getStateEvents(EventType.RoomCreate, "")?.getTs();
|
const createTs = childRoom?.currentState.getStateEvents(EventType.RoomCreate, "")?.getTs();
|
||||||
return getChildOrder(ev.getContent().order, createTs, roomId);
|
return getChildOrder(ev.getContent().order, createTs, roomId);
|
||||||
}).map(ev => {
|
}).map(ev => {
|
||||||
return this.matrixClient.getRoom(ev.getStateKey());
|
const history = this.matrixClient.getRoomUpgradeHistory(ev.getStateKey(), true);
|
||||||
|
return history[history.length - 1];
|
||||||
}).filter(room => {
|
}).filter(room => {
|
||||||
return room?.getMyMembership() === "join" || room?.getMyMembership() === "invite";
|
return room?.getMyMembership() === "join" || room?.getMyMembership() === "invite";
|
||||||
}) || [];
|
}) || [];
|
||||||
|
@ -511,8 +512,13 @@ export class SpaceStoreClass extends AsyncStoreWithClient<IState> {
|
||||||
hiddenChildren.get(spaceId)?.forEach(roomId => {
|
hiddenChildren.get(spaceId)?.forEach(roomId => {
|
||||||
roomIds.add(roomId);
|
roomIds.add(roomId);
|
||||||
});
|
});
|
||||||
this.spaceFilteredRooms.set(spaceId, roomIds);
|
|
||||||
return roomIds;
|
// Expand room IDs to all known versions of the given rooms
|
||||||
|
const expandedRoomIds = new Set(Array.from(roomIds).flatMap(roomId => {
|
||||||
|
return this.matrixClient.getRoomUpgradeHistory(roomId, true).map(r => r.roomId);
|
||||||
|
}));
|
||||||
|
this.spaceFilteredRooms.set(spaceId, expandedRoomIds);
|
||||||
|
return expandedRoomIds;
|
||||||
};
|
};
|
||||||
|
|
||||||
fn(s.roomId, new Set());
|
fn(s.roomId, new Set());
|
||||||
|
|
|
@ -77,6 +77,7 @@ describe("SpaceStore", () => {
|
||||||
|
|
||||||
const run = async () => {
|
const run = async () => {
|
||||||
client.getRoom.mockImplementation(roomId => rooms.find(room => room.roomId === roomId));
|
client.getRoom.mockImplementation(roomId => rooms.find(room => room.roomId === roomId));
|
||||||
|
client.getRoomUpgradeHistory.mockImplementation(roomId => [rooms.find(room => room.roomId === roomId)]);
|
||||||
await testUtils.setupAsyncStoreWithClient(store, client);
|
await testUtils.setupAsyncStoreWithClient(store, client);
|
||||||
jest.runAllTimers();
|
jest.runAllTimers();
|
||||||
};
|
};
|
||||||
|
|
|
@ -103,6 +103,7 @@ export function createTestClient() {
|
||||||
isUserIgnored: jest.fn().mockReturnValue(false),
|
isUserIgnored: jest.fn().mockReturnValue(false),
|
||||||
getCapabilities: jest.fn().mockResolvedValue({}),
|
getCapabilities: jest.fn().mockResolvedValue({}),
|
||||||
supportsExperimentalThreads: () => false,
|
supportsExperimentalThreads: () => false,
|
||||||
|
getRoomUpgradeHistory: jest.fn().mockReturnValue([]),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue