diff --git a/lib/keyserver-conn/call-keyserver-endpoint-provider.react.js b/lib/keyserver-conn/call-keyserver-endpoint-provider.react.js --- a/lib/keyserver-conn/call-keyserver-endpoint-provider.react.js +++ b/lib/keyserver-conn/call-keyserver-endpoint-provider.react.js @@ -9,6 +9,7 @@ import { setNewSession, type SingleKeyserverActionFunc, + type ActionFunc, } from './keyserver-conn-types.js'; import { canResolveKeyserverSessionInvalidation, @@ -25,6 +26,7 @@ CallSingleKeyserverEndpointOptions, } from '../utils/call-single-keyserver-endpoint.js'; import callSingleKeyserverEndpoint from '../utils/call-single-keyserver-endpoint.js'; +import { promiseAll } from '../utils/promises.js'; import { useSelector, useDispatch } from '../utils/redux-utils.js'; type CreateCallSingleKeyserverEndpointSelector = ( @@ -43,9 +45,14 @@ actionFunc: SingleKeyserverActionFunc, ) => SingleKeyserverActionFuncSelectorParams => F; +type GetBoundKeyserverActionFunc = ( + actionFunc: ActionFunc, +) => Args => Promise; + type CallKeyserverEndpointContextType = { +createCallSingleKeyserverEndpointSelector: CreateCallSingleKeyserverEndpointSelector, +getBoundSingleKeyserverActionFunc: GetBoundSingleKeyserverActionFunc, + +getBoundKeyserverActionFunc: GetBoundKeyserverActionFunc, }; const CallKeyserverEndpointContext: React.Context = @@ -339,14 +346,48 @@ ], ); + // SECTION 4: getBoundKeyserverActionFunc + + const callKeyserverEndpoint = React.useCallback( + ( + endpoint: Endpoint, + requests: { +[keyserverID: string]: ?{ +[string]: mixed } }, + options?: ?CallSingleKeyserverEndpointOptions, + ) => { + const makeCallToSingleKeyserver = (keyserverID: string) => { + const boundCallSingleKeyserverEndpoint = + getCallSingleKeyserverEndpoint(keyserverID); + return boundCallSingleKeyserverEndpoint( + endpoint, + requests[keyserverID], + options, + ); + }; + const promises: { [string]: Promise } = {}; + for (const keyserverID in requests) { + promises[keyserverID] = makeCallToSingleKeyserver(keyserverID); + } + return promiseAll(promises); + }, + [getCallSingleKeyserverEndpoint], + ); + + const getBoundKeyserverActionFunc: GetBoundKeyserverActionFunc = + React.useMemo( + () => _memoize(actionFunc => actionFunc(callKeyserverEndpoint)), + [callKeyserverEndpoint], + ); + const value = React.useMemo( () => ({ createCallSingleKeyserverEndpointSelector, getBoundSingleKeyserverActionFunc, + getBoundKeyserverActionFunc, }), [ createCallSingleKeyserverEndpointSelector, getBoundSingleKeyserverActionFunc, + getBoundKeyserverActionFunc, ], ); 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, }>; -type KeyserverCallInfo = { +export 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 @@ -46,15 +46,26 @@ } = baseCombinedInfo; const keyserverCallInfos = useKeyserverCallInfos(keyserverInfoPartials); - const { createCallSingleKeyserverEndpointSelector } = - useCallKeyserverEndpointContext(); + const { + createCallSingleKeyserverEndpointSelector, + getBoundKeyserverActionFunc, + } = useCallKeyserverEndpointContext(); const getCallSingleKeyserverEndpointSelector: typeof createCallSingleKeyserverEndpointSelector = React.useMemo( () => _memoize(createCallSingleKeyserverEndpointSelector), [createCallSingleKeyserverEndpointSelector], ); + const cachedNonOverridenBoundKeyserverCall = React.useMemo( + () => getBoundKeyserverActionFunc(keyserverCall), + [getBoundKeyserverActionFunc, keyserverCall], + ); + return React.useMemo(() => { + if (!paramOverride) { + return cachedNonOverridenBoundKeyserverCall; + } + const callKeyserverEndpoint = ( endpoint: Endpoint, requests: { +[keyserverID: string]: ?{ +[string]: mixed } }, @@ -96,6 +107,8 @@ const keyserverIDs = Object.keys(keyserverCallInfos); return keyserverCall(callKeyserverEndpoint, keyserverIDs); }, [ + paramOverride, + cachedNonOverridenBoundKeyserverCall, dispatch, currentUserInfo, keyserverCallInfos,