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,8 @@ Return, >( keyserverCall: ActionFunc, -) => Args => Promise = createSelector( + paramOverride?: ?KeyserverCallParamOverride, +) => (Args, ?KeyserverCallParamOverride) => Promise = createSelector( (state: BindKeyserverCallParams) => state.dispatch, (state: BindKeyserverCallParams) => state.currentUserInfo, (state: BindKeyserverCallParams) => state.keyserverInfos, @@ -102,6 +103,7 @@ return _memoize( ( keyserverCall: ActionFunc, + paramOverride?: ?KeyserverCallParamOverride, ): (Args => Promise) => { const callKeyserverEndpoint = ( endpoint: Endpoint, @@ -115,7 +117,10 @@ sessionID, connection, lastCommunicatedPlatformDetails, - } = keyserverInfos[keyserverID]; + } = { + ...keyserverInfos[keyserverID], + ...paramOverride, + }; const boundCallServerEndpoint = createBoundServerCallsSelector( keyserverID, @@ -155,7 +160,7 @@ function useKeyserverCall( keyserverCall: ActionFunc, paramOverride?: ?KeyserverCallParamOverride, -): Args => Promise { +): (Args, ?KeyserverCallParamOverride) => Promise { const dispatch = useDispatch(); const keyserverInfos = useSelector( state => state.keyserverStore.keyserverInfos, @@ -168,7 +173,7 @@ ...paramOverride, }); return React.useMemo( - () => bindCallKeyserverEndpointToAction(keyserverCall), + overrides => bindCallKeyserverEndpointToAction(keyserverCall, overrides), [bindCallKeyserverEndpointToAction, keyserverCall], ); }