diff --git a/lib/handlers/user-infos-handler.react.js b/lib/handlers/user-infos-handler.react.js --- a/lib/handlers/user-infos-handler.react.js +++ b/lib/handlers/user-infos-handler.react.js @@ -111,12 +111,20 @@ loggedInToAuthKeyserver, ]); - const usersWithMissingDeviceList = useSelector( + const usersWithMissingDeviceListSelected = useSelector( usersWithMissingDeviceListSelector, ); const getAndUpdateDeviceListsForUsers = useGetAndUpdateDeviceListsForUsers(); const { socketState } = useTunnelbroker(); + + const requestedDeviceListsIDsRef = React.useRef(new Set()); + React.useEffect(() => { + const usersWithMissingDeviceList = + usersWithMissingDeviceListSelected.filter( + id => !requestedDeviceListsIDsRef.current.has(id), + ); + if ( !usingCommServicesAccessToken || usersWithMissingDeviceList.length === 0 || @@ -130,7 +138,16 @@ return; } try { - await getAndUpdateDeviceListsForUsers(usersWithMissingDeviceList, true); + usersWithMissingDeviceList.forEach(id => + requestedDeviceListsIDsRef.current.add(id), + ); + const foundDeviceListIDs = await getAndUpdateDeviceListsForUsers( + usersWithMissingDeviceList, + true, + ); + Object.keys(foundDeviceListIDs).forEach(id => + requestedDeviceListsIDsRef.current.delete(id), + ); } catch (e) { console.log( `Error getting and setting peer device list: ${ @@ -140,10 +157,10 @@ } })(); }, [ + getAndUpdateDeviceListsForUsers, getAuthMetadata, socketState.isAuthorized, - getAndUpdateDeviceListsForUsers, - usersWithMissingDeviceList, + usersWithMissingDeviceListSelected, ]); } diff --git a/lib/hooks/peer-list-hooks.js b/lib/hooks/peer-list-hooks.js --- a/lib/hooks/peer-list-hooks.js +++ b/lib/hooks/peer-list-hooks.js @@ -49,7 +49,7 @@ function useGetAndUpdateDeviceListsForUsers(): ( userIDs: $ReadOnlyArray, broadcastUpdates: ?boolean, -) => Promise { +) => Promise { const getDeviceListsForUsers = useGetDeviceListsForUsers(); const dispatch = useDispatch(); const broadcastDeviceListUpdates = useBroadcastDeviceListUpdates(); @@ -61,7 +61,7 @@ const { deviceLists, usersPlatformDetails } = await getDeviceListsForUsers(userIDs); if (Object.keys(deviceLists).length === 0) { - return; + return {}; } dispatch({ type: setPeerDeviceListsActionType, @@ -69,7 +69,7 @@ }); if (!broadcastUpdates) { - return; + return deviceLists; } const thisDeviceID = await getContentSigningKey(); @@ -83,6 +83,8 @@ ); await broadcastDeviceListUpdates(newDevices); + + return deviceLists; }, [ allPeerDevices,