Add invite list atom
This commit is contained in:
parent
582250c419
commit
6b559404b2
1 changed files with 32 additions and 0 deletions
32
src/app/state/inviteList.ts
Normal file
32
src/app/state/inviteList.ts
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
import { atom } from 'jotai';
|
||||||
|
import { mx } from '../../client/mx';
|
||||||
|
import { Membership } from '../../types/matrix/room';
|
||||||
|
import { isDirectInvite, isRoom, isSpace, isUnsupportedRoom } from '../utils/room';
|
||||||
|
import { mDirectAtom } from './mDirectList';
|
||||||
|
import { atomRoomsWithMemberships } from './utils';
|
||||||
|
|
||||||
|
export const allInvitesAtom = atom<string[]>([]);
|
||||||
|
allInvitesAtom.onMount = (setAtom) => atomRoomsWithMemberships(setAtom, mx(), [Membership.Invite]);
|
||||||
|
|
||||||
|
export const spaceInvitesAtom = atom((get) =>
|
||||||
|
get(allInvitesAtom).filter((roomId) => isSpace(mx().getRoom(roomId)))
|
||||||
|
);
|
||||||
|
|
||||||
|
export const roomInvitesAtom = atom((get) =>
|
||||||
|
get(allInvitesAtom).filter(
|
||||||
|
(roomId) =>
|
||||||
|
isRoom(mx().getRoom(roomId)) &&
|
||||||
|
!(get(mDirectAtom).has(roomId) || isDirectInvite(mx().getRoom(roomId), mx().getUserId()))
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
export const directInvitesAtom = atom((get) =>
|
||||||
|
get(allInvitesAtom).filter(
|
||||||
|
(roomId) =>
|
||||||
|
get(mDirectAtom).has(roomId) || isDirectInvite(mx().getRoom(roomId), mx().getUserId())
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
export const unsupportedInvitesAtom = atom((get) =>
|
||||||
|
get(allInvitesAtom).filter((roomId) => isUnsupportedRoom(mx().getRoom(roomId)))
|
||||||
|
);
|
Loading…
Reference in a new issue