@@ -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