Add mDirect list atom
This commit is contained in:
parent
56a134c85c
commit
582250c419
1 changed files with 20 additions and 0 deletions
20
src/app/state/mDirectList.ts
Normal file
20
src/app/state/mDirectList.ts
Normal 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);
|
||||||
|
};
|
||||||
|
};
|
Loading…
Reference in a new issue