Merge pull request #3987 from matrix-org/jryans/update-user-info-trust
Update user info for device and trust changes
This commit is contained in:
commit
c851cc6070
3 changed files with 23 additions and 13 deletions
|
@ -77,8 +77,8 @@ export default class DeviceListener {
|
||||||
this._recheck();
|
this._recheck();
|
||||||
}
|
}
|
||||||
|
|
||||||
_onDeviceVerificationChanged = (users) => {
|
_onDeviceVerificationChanged = (userId) => {
|
||||||
if (!users.includes(MatrixClientPeg.get().getUserId())) return;
|
if (userId !== MatrixClientPeg.get().getUserId()) return;
|
||||||
this._recheck();
|
this._recheck();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,7 @@ const EncryptionPanel = ({verificationRequest, member, onClose}) => {
|
||||||
setRequest(verificationRequest);
|
setRequest(verificationRequest);
|
||||||
}, [verificationRequest]);
|
}, [verificationRequest]);
|
||||||
|
|
||||||
const [phase, setPhase] = useState(request.phase);
|
const [phase, setPhase] = useState(request && request.phase);
|
||||||
const changeHandler = useCallback(() => {
|
const changeHandler = useCallback(() => {
|
||||||
// handle transitions -> cancelled for mismatches which fire a modal instead of showing a card
|
// handle transitions -> cancelled for mismatches which fire a modal instead of showing a card
|
||||||
if (request && request.cancelled && MISMATCHES.includes(request.cancellationCode)) {
|
if (request && request.cancelled && MISMATCHES.includes(request.cancellationCode)) {
|
||||||
|
|
|
@ -1092,22 +1092,32 @@ export const useDevices = (userId) => {
|
||||||
// Listen to changes
|
// Listen to changes
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
let cancel = false;
|
let cancel = false;
|
||||||
const onDeviceVerificationChanged = (_userId, device) => {
|
const updateDevices = async () => {
|
||||||
if (_userId === userId) {
|
const newDevices = await cli.getStoredDevicesForUser(userId);
|
||||||
// no need to re-download the whole thing; just update our copy of the list.
|
|
||||||
|
|
||||||
// Promise.resolve to handle transition from static result to promise; can be removed in future
|
|
||||||
Promise.resolve(cli.getStoredDevicesForUser(userId)).then((devices) => {
|
|
||||||
if (cancel) return;
|
if (cancel) return;
|
||||||
setDevices(devices);
|
setDevices(newDevices);
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
const onDevicesUpdated = (users) => {
|
||||||
|
if (!users.includes(userId)) return;
|
||||||
|
updateDevices();
|
||||||
|
};
|
||||||
|
const onDeviceVerificationChanged = (_userId, device) => {
|
||||||
|
if (_userId !== userId) return;
|
||||||
|
updateDevices();
|
||||||
|
};
|
||||||
|
const onUserTrustStatusChanged = (_userId, trustStatus) => {
|
||||||
|
if (_userId !== userId) return;
|
||||||
|
updateDevices();
|
||||||
|
};
|
||||||
|
cli.on("crypto.devicesUpdated", onDevicesUpdated);
|
||||||
cli.on("deviceVerificationChanged", onDeviceVerificationChanged);
|
cli.on("deviceVerificationChanged", onDeviceVerificationChanged);
|
||||||
|
cli.on("userTrustStatusChanged", onUserTrustStatusChanged);
|
||||||
// Handle being unmounted
|
// Handle being unmounted
|
||||||
return () => {
|
return () => {
|
||||||
cancel = true;
|
cancel = true;
|
||||||
|
cli.removeListener("crypto.devicesUpdated", onDevicesUpdated);
|
||||||
cli.removeListener("deviceVerificationChanged", onDeviceVerificationChanged);
|
cli.removeListener("deviceVerificationChanged", onDeviceVerificationChanged);
|
||||||
|
cli.removeListener("userTrustStatusChanged", onUserTrustStatusChanged);
|
||||||
};
|
};
|
||||||
}, [cli, userId]);
|
}, [cli, userId]);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue