Add mDirect list atom

This commit is contained in:
Ajay Bura 2022-12-27 20:15:52 +05:30
parent 56a134c85c
commit 582250c419

View file

@ -0,0 +1,20 @@
import { atom } from 'jotai';
import { ClientEvent, MatrixEvent } from 'matrix-js-sdk';
import { mx } from '../../client/mx';
import { AccountDataEvent } from '../../types/matrix/accountData';
import { getAccountData, getMDirects } from '../utils/room';
export const mDirectAtom = atom(new Set<string>());
mDirectAtom.onMount = (setAtom) => {
const mDirectEvent = getAccountData(mx(), AccountDataEvent.Direct);
if (mDirectEvent) setAtom(getMDirects(mDirectEvent));
const handleAccountData = (event: MatrixEvent) => {
setAtom(getMDirects(event));
};
mx().on(ClientEvent.AccountData, handleAccountData);
return () => {
mx().removeListener(ClientEvent.AccountData, handleAccountData);
};
};