diff --git a/lib/actions/link-actions.js b/lib/actions/link-actions.js --- a/lib/actions/link-actions.js +++ b/lib/actions/link-actions.js @@ -49,35 +49,41 @@ }; }; -function useVerifyInviteLink(keyserverOverride?: { - +keyserverID: string, - +keyserverURL: string, -}): ( +function useVerifyInviteLink(): ( request: InviteLinkVerificationRequest, + keyserverOverride?: ?{ + +keyserverID: string, + +keyserverURL: string, + }, ) => Promise { - const keyserverID = keyserverOverride?.keyserverID ?? ashoatKeyserverID; - const isKeyserverKnown = useSelector( - state => !!state.keyserverStore.keyserverInfos[keyserverID], - ); - - let paramOverride = null; - if (keyserverOverride && !isKeyserverKnown) { - paramOverride = { - keyserverInfos: { - [keyserverOverride.keyserverID]: { - urlPrefix: keyserverOverride.keyserverURL, - }, - }, - }; - } - const callVerifyInviteLink = useKeyserverCall( - verifyInviteLink, - paramOverride, + const callVerifyInviteLink = useKeyserverCall(verifyInviteLink); + const keyserverInfos = useSelector( + state => state.keyserverStore.keyserverInfos, ); return React.useCallback( - (request: InviteLinkVerificationRequest) => - callVerifyInviteLink({ request, keyserverID }), - [callVerifyInviteLink, keyserverID], + ( + request: InviteLinkVerificationRequest, + keyserverOverride?: ?{ + +keyserverID: string, + +keyserverURL: string, + }, + ) => { + const keyserverID = keyserverOverride?.keyserverID ?? ashoatKeyserverID; + const isKeyserverKnown = !!keyserverInfos[keyserverID]; + + let paramOverride = null; + if (keyserverOverride && !isKeyserverKnown) { + paramOverride = { + keyserverInfos: { + [keyserverOverride.keyserverID]: { + urlPrefix: keyserverOverride.keyserverURL, + }, + }, + }; + } + return callVerifyInviteLink({ request, keyserverID }, paramOverride); + }, + [callVerifyInviteLink, keyserverInfos], ); } 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 @@ -90,7 +90,7 @@ Return, >( keyserverCall: ActionFunc, -) => Args => Promise = createSelector( +) => (Args, ?KeyserverCallParamOverride) => Promise = createSelector( (state: BindKeyserverCallParams) => state.dispatch, (state: BindKeyserverCallParams) => state.currentUserInfo, (state: BindKeyserverCallParams) => state.keyserverInfos, @@ -102,49 +102,59 @@ return _memoize( ( keyserverCall: ActionFunc, - ): (Args => Promise) => { - const callKeyserverEndpoint = ( - endpoint: Endpoint, - requests: { +[keyserverID: string]: ?{ +[string]: mixed } }, - options?: ?CallServerEndpointOptions, - ) => { - const bindCallKeyserverEndpoint = (keyserverID: string) => { - const { - cookie, - urlPrefix, - sessionID, - connection, - lastCommunicatedPlatformDetails, - } = keyserverInfos[keyserverID]; + ): ((Args, ?KeyserverCallParamOverride) => Promise) => { + const callKeyserverEndpoint = + (overrides?: ?KeyserverCallParamOverride) => + ( + endpoint: Endpoint, + requests: { +[keyserverID: string]: ?{ +[string]: mixed } }, + options?: ?CallServerEndpointOptions, + ) => { + const bindCallKeyserverEndpoint = (keyserverID: string) => { + const { + cookie, + urlPrefix, + sessionID, + connection, + lastCommunicatedPlatformDetails, + } = { + ...keyserverInfos[keyserverID], + ...overrides?.keyserverInfos?.[keyserverID], + }; - const boundCallServerEndpoint = createBoundServerCallsSelector( - keyserverID, - )({ - dispatch, - currentUserInfo, - cookie, - urlPrefix, - sessionID, - connectionStatus: connection?.status ?? 'disconnected', - lastCommunicatedPlatformDetails, - keyserverID, - }); + const boundCallServerEndpoint = createBoundServerCallsSelector( + keyserverID, + )({ + dispatch, + currentUserInfo, + cookie, + urlPrefix, + sessionID, + connectionStatus: connection?.status ?? 'disconnected', + lastCommunicatedPlatformDetails, + keyserverID, + }); - return boundCallServerEndpoint( - endpoint, - requests[keyserverID], - options, - ); - }; + return boundCallServerEndpoint( + endpoint, + requests[keyserverID], + options, + ); + }; - const promises: { [string]: Promise } = {}; - for (const keyserverID in requests) { - promises[keyserverID] = bindCallKeyserverEndpoint(keyserverID); - } - return promiseAll(promises); - }; + const promises: { [string]: Promise } = {}; + for (const keyserverID in requests) { + promises[keyserverID] = bindCallKeyserverEndpoint(keyserverID); + } + return promiseAll(promises); + }; const keyserverIDs = Object.keys(keyserverInfos); - return keyserverCall(callKeyserverEndpoint, keyserverIDs); + return (args: Args, overrides?: ?KeyserverCallParamOverride) => { + return keyserverCall( + callKeyserverEndpoint(overrides), + keyserverIDs, + )(args); + }; }, ); }, @@ -155,7 +165,7 @@ function useKeyserverCall( keyserverCall: ActionFunc, paramOverride?: ?KeyserverCallParamOverride, -): Args => Promise { +): (Args, ?KeyserverCallParamOverride) => Promise { const dispatch = useDispatch(); const keyserverInfos = useSelector( state => state.keyserverStore.keyserverInfos,