diff --git a/lib/keyserver-conn/keyserver-call-infos.js b/lib/keyserver-conn/keyserver-call-infos.js --- a/lib/keyserver-conn/keyserver-call-infos.js +++ b/lib/keyserver-conn/keyserver-call-infos.js @@ -11,7 +11,7 @@ +urlPrefix: $PropertyType, }>; -export type KeyserverCallInfo = { +type KeyserverCallInfo = { +cookie: ?string, +urlPrefix: string, +sessionID: ?string, diff --git a/lib/utils/keyserver-call.js b/lib/utils/keyserver-call.js --- a/lib/utils/keyserver-call.js +++ b/lib/utils/keyserver-call.js @@ -10,7 +10,6 @@ import { useKeyserverCallInfos, type KeyserverInfoPartial, - type KeyserverCallInfo, } from '../keyserver-conn/keyserver-call-infos.js'; import type { Endpoint } from '../types/endpoints.js'; import type { Dispatch } from '../types/redux-types.js'; @@ -30,78 +29,6 @@ allKeyserverIDs: $ReadOnlyArray, ) => Args => Promise; -type BindCallKeyserverSelector = ( - keyserverCall: ActionFunc, -) => Args => Promise; -function useBindCallKeyserverEndpointSelector( - dispatch: Dispatch, - currentUserInfo: ?CurrentUserInfo, - keyserverCallInfos: { +[keyserverID: string]: KeyserverCallInfo }, -): BindCallKeyserverSelector { - const { createCallSingleKeyserverEndpointSelector } = - useCallKeyserverEndpointContext(); - const getCallSingleKeyserverEndpointSelector: typeof createCallSingleKeyserverEndpointSelector = - React.useMemo( - () => _memoize(createCallSingleKeyserverEndpointSelector), - [createCallSingleKeyserverEndpointSelector], - ); - return React.useMemo( - () => - _memoize( - ( - keyserverCall: ActionFunc, - ): (Args => Promise) => { - const callKeyserverEndpoint = ( - endpoint: Endpoint, - requests: { +[keyserverID: string]: ?{ +[string]: mixed } }, - options?: ?CallServerEndpointOptions, - ) => { - const makeCallToSingleKeyserver = (keyserverID: string) => { - const { - cookie, - urlPrefix, - sessionID, - isSocketConnected, - lastCommunicatedPlatformDetails, - } = keyserverCallInfos[keyserverID]; - - const boundCallServerEndpoint = - getCallSingleKeyserverEndpointSelector(keyserverID)({ - dispatch, - currentUserInfo, - cookie, - urlPrefix, - sessionID, - isSocketConnected, - lastCommunicatedPlatformDetails, - }); - - return boundCallServerEndpoint( - endpoint, - requests[keyserverID], - options, - ); - }; - - const promises: { [string]: Promise } = {}; - for (const keyserverID in requests) { - promises[keyserverID] = makeCallToSingleKeyserver(keyserverID); - } - return promiseAll(promises); - }; - const keyserverIDs = Object.keys(keyserverCallInfos); - return keyserverCall(callKeyserverEndpoint, keyserverIDs); - }, - ), - [ - dispatch, - currentUserInfo, - keyserverCallInfos, - getCallSingleKeyserverEndpointSelector, - ], - ); -} - export type KeyserverCallParamOverride = Partial<{ +dispatch: Dispatch, +currentUserInfo: ?CurrentUserInfo, @@ -132,17 +59,63 @@ } = baseCombinedInfo; const keyserverCallInfos = useKeyserverCallInfos(keyserverInfoPartials); - const bindCallKeyserverEndpointToAction = - useBindCallKeyserverEndpointSelector( - dispatch, - currentUserInfo, - keyserverCallInfos, + const { createCallSingleKeyserverEndpointSelector } = + useCallKeyserverEndpointContext(); + const getCallSingleKeyserverEndpointSelector: typeof createCallSingleKeyserverEndpointSelector = + React.useMemo( + () => _memoize(createCallSingleKeyserverEndpointSelector), + [createCallSingleKeyserverEndpointSelector], ); - return React.useMemo( - () => bindCallKeyserverEndpointToAction(keyserverCall), - [bindCallKeyserverEndpointToAction, keyserverCall], - ); + return React.useMemo(() => { + const callKeyserverEndpoint = ( + endpoint: Endpoint, + requests: { +[keyserverID: string]: ?{ +[string]: mixed } }, + options?: ?CallServerEndpointOptions, + ) => { + const makeCallToSingleKeyserver = (keyserverID: string) => { + const { + cookie, + urlPrefix, + sessionID, + isSocketConnected, + lastCommunicatedPlatformDetails, + } = keyserverCallInfos[keyserverID]; + + const boundCallServerEndpoint = getCallSingleKeyserverEndpointSelector( + keyserverID, + )({ + dispatch, + currentUserInfo, + cookie, + urlPrefix, + sessionID, + isSocketConnected, + lastCommunicatedPlatformDetails, + }); + + return boundCallServerEndpoint( + endpoint, + requests[keyserverID], + options, + ); + }; + + const promises: { [string]: Promise } = {}; + for (const keyserverID in requests) { + promises[keyserverID] = makeCallToSingleKeyserver(keyserverID); + } + return promiseAll(promises); + }; + const keyserverIDs = Object.keys(keyserverCallInfos); + return keyserverCall(callKeyserverEndpoint, keyserverIDs); + }, [ + dispatch, + currentUserInfo, + keyserverCallInfos, + getCallSingleKeyserverEndpointSelector, + keyserverCall, + ]); } export { useKeyserverCall };