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 @@ -2,16 +2,15 @@ import * as React from 'react'; -import { setPeerDeviceListsActionType } from '../actions/aux-user-actions.js'; import { useFindUserIdentities, findUserIdentitiesActionTypes, } from '../actions/user-actions.js'; -import { useGetDeviceListsForUsers } from '../hooks/peer-list-hooks.js'; +import { useGetAndUpdateDeviceListsForUsers } from '../hooks/peer-list-hooks.js'; import { usersWithMissingDeviceListSelector } from '../selectors/user-selectors.js'; import { getMessageForException } from '../utils/errors.js'; import { useDispatchActionPromise } from '../utils/redux-promise-utils.js'; -import { useDispatch, useSelector } from '../utils/redux-utils.js'; +import { useSelector } from '../utils/redux-utils.js'; import { relyingOnAuthoritativeKeyserver, usingCommServicesAccessToken, @@ -71,8 +70,7 @@ const usersWithMissingDeviceList = useSelector( usersWithMissingDeviceListSelector, ); - const getDeviceListsForUsers = useGetDeviceListsForUsers(); - const dispatch = useDispatch(); + const getAndUpdateDeviceListsForUsers = useGetAndUpdateDeviceListsForUsers(); React.useEffect(() => { if ( !usingCommServicesAccessToken || @@ -82,24 +80,16 @@ } void (async () => { try { - const { deviceLists, usersPlatformDetails } = - await getDeviceListsForUsers(usersWithMissingDeviceList); - if (Object.keys(deviceLists).length === 0) { - return; - } - dispatch({ - type: setPeerDeviceListsActionType, - payload: { deviceLists, usersPlatformDetails }, - }); + await getAndUpdateDeviceListsForUsers(usersWithMissingDeviceList); } catch (e) { console.log( - `Error setting peer device list: ${ + `Error getting and setting peer device list: ${ getMessageForException(e) ?? 'unknown' }`, ); } })(); - }, [dispatch, getDeviceListsForUsers, usersWithMissingDeviceList]); + }, [getAndUpdateDeviceListsForUsers, usersWithMissingDeviceList]); } export { UserInfosHandler }; 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 @@ -74,6 +74,27 @@ ); } +function useGetAndUpdateDeviceListsForUsers(): ( + userIDs: $ReadOnlyArray, +) => Promise { + const getDeviceListsForUsers = useGetDeviceListsForUsers(); + const dispatch = useDispatch(); + return React.useCallback( + async (userIDs: $ReadOnlyArray) => { + const { deviceLists, usersPlatformDetails } = + await getDeviceListsForUsers(userIDs); + if (Object.keys(deviceLists).length === 0) { + return; + } + dispatch({ + type: setPeerDeviceListsActionType, + payload: { deviceLists, usersPlatformDetails }, + }); + }, + [dispatch, getDeviceListsForUsers], + ); +} + function useBroadcastDeviceListUpdates(): ( deviceIDs: $ReadOnlyArray, signedDeviceList?: SignedDeviceList, @@ -116,4 +137,5 @@ useCreateInitialPeerList, useGetDeviceListsForUsers, useBroadcastDeviceListUpdates, + useGetAndUpdateDeviceListsForUsers, };