Skip to content

Commit 7a5bf8f

Browse files
committed
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`
1 parent d362cc0 commit 7a5bf8f

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

src/DeviceListener.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ export default class DeviceListener {
7777
this._recheck();
7878
}
7979

80-
_onDeviceVerificationChanged = (users) => {
81-
if (!users.includes(MatrixClientPeg.get().getUserId())) return;
80+
_onDeviceVerificationChanged = (userId) => {
81+
if (userId !== MatrixClientPeg.get().getUserId()) return;
8282
this._recheck();
8383
}
8484

src/components/views/right_panel/UserInfo.js

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,22 +1092,32 @@ export const useDevices = (userId) => {
10921092
// Listen to changes
10931093
useEffect(() => {
10941094
let cancel = false;
1095+
const updateDevices = async () => {
1096+
const newDevices = await cli.getStoredDevicesForUser(userId);
1097+
if (cancel) return;
1098+
setDevices(newDevices);
1099+
};
1100+
const onDevicesUpdated = (users) => {
1101+
if (!users.includes(userId)) return;
1102+
updateDevices();
1103+
};
10951104
const onDeviceVerificationChanged = (_userId, device) => {
1096-
if (_userId === userId) {
1097-
// no need to re-download the whole thing; just update our copy of the list.
1098-
1099-
// Promise.resolve to handle transition from static result to promise; can be removed in future
1100-
Promise.resolve(cli.getStoredDevicesForUser(userId)).then((devices) => {
1101-
if (cancel) return;
1102-
setDevices(devices);
1103-
});
1104-
}
1105+
if (_userId !== userId) return;
1106+
updateDevices();
1107+
};
1108+
const onUserTrustStatusChanged = (_userId, trustStatus) => {
1109+
if (_userId !== userId) return;
1110+
updateDevices();
11051111
};
1112+
cli.on("crypto.devicesUpdated", onDevicesUpdated);
11061113
cli.on("deviceVerificationChanged", onDeviceVerificationChanged);
1114+
cli.on("userTrustStatusChanged", onUserTrustStatusChanged);
11071115
// Handle being unmounted
11081116
return () => {
11091117
cancel = true;
1118+
cli.removeListener("crypto.devicesUpdated", onDevicesUpdated);
11101119
cli.removeListener("deviceVerificationChanged", onDeviceVerificationChanged);
1120+
cli.removeListener("userTrustStatusChanged", onUserTrustStatusChanged);
11111121
};
11121122
}, [cli, userId]);
11131123

0 commit comments

Comments
 (0)