You've already forked matrix-react-sdk
mirror of
https://github.com/matrix-org/matrix-react-sdk.git
synced 2025-07-28 15:22:05 +03:00
null-guard useIsEncrypted
This commit is contained in:
@ -109,14 +109,14 @@ function openDMForUser(matrixClient, userId) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function useIsEncrypted(cli, room) {
|
function useIsEncrypted(cli, room) {
|
||||||
const [isEncrypted, setIsEncrypted] = useState(cli.isRoomEncrypted(room.roomId));
|
const [isEncrypted, setIsEncrypted] = useState(room ? cli.isRoomEncrypted(room.roomId) : undefined);
|
||||||
|
|
||||||
const update = useCallback((event) => {
|
const update = useCallback((event) => {
|
||||||
if (event.getType() === "m.room.encryption") {
|
if (event.getType() === "m.room.encryption") {
|
||||||
setIsEncrypted(cli.isRoomEncrypted(room.roomId));
|
setIsEncrypted(cli.isRoomEncrypted(room.roomId));
|
||||||
}
|
}
|
||||||
}, [cli, room]);
|
}, [cli, room]);
|
||||||
useEventEmitter(room.currentState, "RoomState.events", update);
|
useEventEmitter(room ? room.currentState : undefined, "RoomState.events", update);
|
||||||
return isEncrypted;
|
return isEncrypted;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,6 +28,9 @@ export const useEventEmitter = (emitter, eventName, handler) => {
|
|||||||
|
|
||||||
useEffect(
|
useEffect(
|
||||||
() => {
|
() => {
|
||||||
|
// allow disabling this hook by passing a falsy emitter
|
||||||
|
if (!emitter) return;
|
||||||
|
|
||||||
// Create event listener that calls handler function stored in ref
|
// Create event listener that calls handler function stored in ref
|
||||||
const eventListener = event => savedHandler.current(event);
|
const eventListener = event => savedHandler.current(event);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user