Add cross signin status hook
Signed-off-by: Ajay Bura <ajbura@gmail.com>
This commit is contained in:
parent
c423ba853a
commit
d978776993
1 changed files with 25 additions and 0 deletions
25
src/app/hooks/useCrossSigninStatus.js
Normal file
25
src/app/hooks/useCrossSigninStatus.js
Normal 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;
|
||||
}
|
Loading…
Reference in a new issue