Update user info for device and trust changes

This ensure the user info panel updates automatically for device and trust
changes.

Fixes https://github.com/vector-im/riot-web/issues/12134`
pull/21833/head
J. Ryan Stinnett 2020-01-29 21:55:27 +00:00
parent d362cc0f41
commit 7a5bf8f102
2 changed files with 22 additions and 12 deletions

View File

@ -77,8 +77,8 @@ export default class DeviceListener {
this._recheck();
}
_onDeviceVerificationChanged = (users) => {
if (!users.includes(MatrixClientPeg.get().getUserId())) return;
_onDeviceVerificationChanged = (userId) => {
if (userId !== MatrixClientPeg.get().getUserId()) return;
this._recheck();
}

View File

@ -1092,22 +1092,32 @@ export const useDevices = (userId) => {
// Listen to changes
useEffect(() => {
let cancel = false;
const onDeviceVerificationChanged = (_userId, device) => {
if (_userId === 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;
setDevices(devices);
});
}
const updateDevices = async () => {
const newDevices = await cli.getStoredDevicesForUser(userId);
if (cancel) return;
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("userTrustStatusChanged", onUserTrustStatusChanged);
// Handle being unmounted
return () => {
cancel = true;
cli.removeListener("crypto.devicesUpdated", onDevicesUpdated);
cli.removeListener("deviceVerificationChanged", onDeviceVerificationChanged);
cli.removeListener("userTrustStatusChanged", onUserTrustStatusChanged);
};
}, [cli, userId]);