mirror of
https://github.com/element-hq/element-web
synced 2024-11-24 02:05:45 +03:00
update when room encryption is turned on
also don't download devices as long as room is not encrypted
This commit is contained in:
parent
bd2bf4500a
commit
29216ef668
1 changed files with 24 additions and 7 deletions
|
@ -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 {
|
||||||
|
|
Loading…
Reference in a new issue