From 6b559404b231f49d8d0c57b7ed5b128c8bfaa4d9 Mon Sep 17 00:00:00 2001 From: Ajay Bura <32841439+ajbura@users.noreply.github.com> Date: Tue, 27 Dec 2022 20:16:13 +0530 Subject: [PATCH] Add invite list atom --- src/app/state/inviteList.ts | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/app/state/inviteList.ts diff --git a/src/app/state/inviteList.ts b/src/app/state/inviteList.ts new file mode 100644 index 00000000..82c686c3 --- /dev/null +++ b/src/app/state/inviteList.ts @@ -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([]); +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))) +);