From 280690cf3c7618b3873e87750c1ee826a942d46b Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Fri, 28 Aug 2020 10:59:52 +0100 Subject: [PATCH] use useIsEncrypted hook in UserInfo --- src/components/views/right_panel/UserInfo.js | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/src/components/views/right_panel/UserInfo.js b/src/components/views/right_panel/UserInfo.js index 71ee86a1ea..518bb133ce 100644 --- a/src/components/views/right_panel/UserInfo.js +++ b/src/components/views/right_panel/UserInfo.js @@ -45,6 +45,7 @@ import EncryptionPanel from "./EncryptionPanel"; import { useAsyncMemo } from '../../../hooks/useAsyncMemo'; import { verifyUser, legacyVerifyUser, verifyDevice } from '../../../verification'; import {Action} from "../../../dispatcher/actions"; +import {useIsEncrypted} from "../../../hooks/useIsEncrypted"; const _disambiguateDevices = (devices) => { const names = Object.create(null); @@ -124,18 +125,6 @@ async function openDMForUser(matrixClient, userId) { createRoom(createRoomOptions); } -function useIsEncrypted(cli, room) { - const [isEncrypted, setIsEncrypted] = useState(room ? cli.isRoomEncrypted(room.roomId) : undefined); - - const update = useCallback((event) => { - if (event.getType() === "m.room.encryption") { - setIsEncrypted(cli.isRoomEncrypted(room.roomId)); - } - }, [cli, room]); - useEventEmitter(room ? room.currentState : undefined, "RoomState.events", update); - return isEncrypted; -} - function useHasCrossSigningKeys(cli, member, canVerify, setUpdating) { return useAsyncMemo(async () => { if (!canVerify) { @@ -1485,7 +1474,7 @@ const UserInfoHeader = ({onClose, member, e2eStatus}) => { const UserInfo = ({user, groupId, roomId, onClose, phase=RightPanelPhases.RoomMemberInfo, ...props}) => { const cli = useContext(MatrixClientContext); - // Load room if we are given a room id and memoize it + // Load room if we are given a room id and memoize it - this can be undefined for User Info/Group Member Info const room = useMemo(() => roomId ? cli.getRoom(roomId) : null, [cli, roomId]); // fetch latest room member if we have a room, so we don't show historical information, falling back to user const member = useMemo(() => room ? (room.getMember(user.userId) || user) : user, [room, user]);