This repository has been archived on 2026-10-25. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
Sable/src/app/hooks/useGetRoom.ts
T
hazre 71425f8644 refactor: route matrix-sdk imports through $types boundary
Centralize Matrix SDK imports behind a local compatibility module, migrate matrix subpath imports to the boundary, and switch to the $types alias. Upgrade TypeScript to latest so matrix-js-sdk typings resolve correctly before the next cleanup phase.
2026-02-14 17:24:46 +01:00

30 lines
828 B
TypeScript

import { Room } from '$types/matrix-sdk';
import { useAtomValue } from 'jotai';
import { useCallback, useMemo } from 'react';
import { allRoomsAtom } from '../state/room-list/roomList';
import { useMatrixClient } from './useMatrixClient';
export const useAllJoinedRoomsSet = () => {
const allRooms = useAtomValue(allRoomsAtom);
const allJoinedRooms = useMemo(() => new Set(allRooms), [allRooms]);
return allJoinedRooms;
};
export type GetRoomCallback = (roomId: string) => Room | undefined;
export const useGetRoom = (rooms: Set<string>): GetRoomCallback => {
const mx = useMatrixClient();
const getRoom: GetRoomCallback = useCallback(
(rId: string) => {
if (rooms.has(rId)) {
return mx.getRoom(rId) ?? undefined;
}
return undefined;
},
[mx, rooms]
);
return getRoom;
};