update when room encryption is turned on

also don't download devices as long as room is not encrypted
This commit is contained in:
Bruno Windels 2019-11-13 12:09:20 +01:00
parent bd2bf4500a
commit 29216ef668

View file

@ -64,6 +64,18 @@ const _getE2EStatus = (devices) => {
return hasUnverifiedDevice ? "warning" : "verified"; return hasUnverifiedDevice ? "warning" : "verified";
}; };
function useIsEncrypted(cli, room) {
const [isEncrypted, setIsEncrypted] = useState(cli.isRoomEncrypted(room.roomId));
const update = useCallback((event) => {
if (event.getType() === "m.room.encryption") {
setIsEncrypted(cli.isRoomEncrypted(room.roomId));
}
}, [cli, room]);
useEventEmitter(room.currentState, "RoomState.events", update);
return isEncrypted;
}
const DevicesSection = ({devices, userId, loading}) => { const DevicesSection = ({devices, userId, loading}) => {
const MemberDeviceInfo = sdk.getComponent('rooms.MemberDeviceInfo'); const MemberDeviceInfo = sdk.getComponent('rooms.MemberDeviceInfo');
const Spinner = sdk.getComponent("elements.Spinner"); const Spinner = sdk.getComponent("elements.Spinner");
@ -1005,6 +1017,7 @@ const UserInfo = withLegacyMatrixClient(({matrixClient: cli, user, groupId, room
title={_t('Close')} />; title={_t('Close')} />;
} }
const isRoomEncrypted = useIsEncrypted(cli, room);
// undefined means yet to be loaded, null means failed to load, otherwise list of devices // undefined means yet to be loaded, null means failed to load, otherwise list of devices
const [devices, setDevices] = useState(undefined); const [devices, setDevices] = useState(undefined);
// Download device lists // Download device lists
@ -1029,14 +1042,15 @@ const UserInfo = withLegacyMatrixClient(({matrixClient: cli, user, groupId, room
setDevices(null); setDevices(null);
} }
} }
if (isRoomEncrypted) {
_downloadDeviceList(); _downloadDeviceList();
}
// Handle being unmounted // Handle being unmounted
return () => { return () => {
cancelled = true; cancelled = true;
}; };
}, [cli, user.userId]); }, [cli, user.userId, isRoomEncrypted]);
// Listen to changes // Listen to changes
useEffect(() => { useEffect(() => {
@ -1053,16 +1067,19 @@ const UserInfo = withLegacyMatrixClient(({matrixClient: cli, user, groupId, room
} }
}; };
cli.on("deviceVerificationChanged", onDeviceVerificationChanged); if (isRoomEncrypted) {
cli.on("deviceVerificationChanged", onDeviceVerificationChanged);
}
// Handle being unmounted // Handle being unmounted
return () => { return () => {
cancel = true; cancel = true;
cli.removeListener("deviceVerificationChanged", onDeviceVerificationChanged); if (isRoomEncrypted) {
cli.removeListener("deviceVerificationChanged", onDeviceVerificationChanged);
}
}; };
}, [cli, user.userId]); }, [cli, user.userId, isRoomEncrypted]);
let devicesSection; let devicesSection;
const isRoomEncrypted = _enableDevices && room && cli.isRoomEncrypted(room.roomId);
if (isRoomEncrypted) { if (isRoomEncrypted) {
devicesSection = <DevicesSection loading={devices === undefined} devices={devices} userId={user.userId} />; devicesSection = <DevicesSection loading={devices === undefined} devices={devices} userId={user.userId} />;
} else { } else {