Add cross signin status hook

Signed-off-by: Ajay Bura <ajbura@gmail.com>
This commit is contained in:
Ajay Bura 2022-03-31 14:40:38 +05:30
parent c423ba853a
commit d978776993

View file

@ -0,0 +1,25 @@
/* eslint-disable import/prefer-default-export */
import { useState, useEffect } from 'react';
import initMatrix from '../../client/initMatrix';
import { hasCrossSigninAccountData } from '../../util/matrixUtil';
export function useCrossSigninStatus() {
const mx = initMatrix.matrixClient;
const [isCSEnabled, setIsCSEnbaled] = useState(hasCrossSigninAccountData());
useEffect(() => {
if (isCSEnabled) return null;
const handleAccountData = (event) => {
if (event.getType() === 'm.cross_signing.master') {
setIsCSEnbaled(true);
}
};
mx.on('accountData', handleAccountData);
return () => {
mx.removeListener('accountData', handleAccountData);
};
}, [isCSEnabled === false]);
return isCSEnabled;
}