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 @@ -1,4 +1,5 @@ // @flow +import * as React from 'react'; import type { FetchInviteLinksResponse, @@ -10,9 +11,9 @@ DisableInviteLinkPayload, } from '../types/link-types.js'; import { extractKeyserverIDFromID } from '../utils/action-utils.js'; -import type { CallServerEndpoint } from '../utils/call-server-endpoint.js'; import { useKeyserverCall } from '../utils/keyserver-call.js'; import type { CallKeyserverEndpoint } from '../utils/keyserver-call.js'; +import { ashoatKeyserverID } from '../utils/validation-utils.js'; const verifyInviteLinkActionTypes = Object.freeze({ started: 'VERIFY_INVITE_LINK_STARTED', @@ -21,12 +22,21 @@ }); const verifyInviteLink = ( - callServerEndpoint: CallServerEndpoint, - ): (( - request: InviteLinkVerificationRequest, - ) => Promise) => - async request => { - const response = await callServerEndpoint('verify_invite_link', request); + callKeyserverEndpoint: CallKeyserverEndpoint, + ): ((input: { + +request: InviteLinkVerificationRequest, + +keyserverID: string, + }) => Promise) => + async input => { + const { request, keyserverID } = input; + const requests = { + [keyserverID]: request, + }; + const responses = await callKeyserverEndpoint( + 'verify_invite_link', + requests, + ); + const response = responses[keyserverID]; if (response.status === 'valid' || response.status === 'already_joined') { return { status: response.status, @@ -38,6 +48,34 @@ }; }; +function useVerifyInviteLink(keyserverOverride?: { + +keyserverID: string, + +keyserverURL: string, +}): ( + request: InviteLinkVerificationRequest, +) => Promise { + const keyserverID = keyserverOverride?.keyserverID ?? ashoatKeyserverID; + let paramOverride = null; + if (keyserverOverride) { + paramOverride = { + keyserverInfos: { + [keyserverOverride.keyserverURL]: { + urlPrefix: keyserverOverride.keyserverURL, + }, + }, + }; + } + const callVerifyInviteLink = useKeyserverCall( + verifyInviteLink, + paramOverride, + ); + return React.useCallback( + (request: InviteLinkVerificationRequest) => + callVerifyInviteLink({ request, keyserverID }), + [callVerifyInviteLink, keyserverID], + ); +} + const fetchPrimaryInviteLinkActionTypes = Object.freeze({ started: 'FETCH_PRIMARY_INVITE_LINKS_STARTED', success: 'FETCH_PRIMARY_INVITE_LINKS_SUCCESS', @@ -137,7 +175,7 @@ export { verifyInviteLinkActionTypes, - verifyInviteLink, + useVerifyInviteLink, fetchPrimaryInviteLinkActionTypes, useFetchPrimaryInviteLinks, createOrUpdatePublicLinkActionTypes, diff --git a/native/navigation/deep-links-context-provider.react.js b/native/navigation/deep-links-context-provider.react.js --- a/native/navigation/deep-links-context-provider.react.js +++ b/native/navigation/deep-links-context-provider.react.js @@ -6,7 +6,7 @@ import { Linking, Platform } from 'react-native'; import { - verifyInviteLink, + useVerifyInviteLink, verifyInviteLinkActionTypes, } from 'lib/actions/link-actions.js'; import { @@ -16,10 +16,7 @@ } from 'lib/facts/links.js'; import { isLoggedIn } from 'lib/selectors/user-selectors.js'; import type { SetState } from 'lib/types/hook-types.js'; -import { - useDispatchActionPromise, - useServerCall, -} from 'lib/utils/action-utils.js'; +import { useDispatchActionPromise } from 'lib/utils/action-utils.js'; import { InviteLinkModalRouteName, @@ -84,7 +81,7 @@ const loggedIn = useSelector(isLoggedIn); const dispatchActionPromise = useDispatchActionPromise(); - const validateLink = useServerCall(verifyInviteLink); + const validateLink = useVerifyInviteLink(); const navigation = useNavigation(); React.useEffect(() => { void (async () => { diff --git a/web/invite-links/invite-link-handler.react.js b/web/invite-links/invite-link-handler.react.js --- a/web/invite-links/invite-link-handler.react.js +++ b/web/invite-links/invite-link-handler.react.js @@ -3,15 +3,12 @@ import * as React from 'react'; import { - verifyInviteLink, + useVerifyInviteLink, verifyInviteLinkActionTypes, } from 'lib/actions/link-actions.js'; import { useModalContext } from 'lib/components/modal-provider.react.js'; import { isLoggedIn } from 'lib/selectors/user-selectors.js'; -import { - useDispatchActionPromise, - useServerCall, -} from 'lib/utils/action-utils.js'; +import { useDispatchActionPromise } from 'lib/utils/action-utils.js'; import { useDispatch } from 'lib/utils/redux-utils.js'; import AcceptInviteModal from './accept-invite-modal.react.js'; @@ -24,7 +21,7 @@ const dispatchActionPromise = useDispatchActionPromise(); const dispatch = useDispatch(); - const validateLink = useServerCall(verifyInviteLink); + const validateLink = useVerifyInviteLink(); const { pushModal } = useModalContext(); React.useEffect(() => { if (!inviteSecret || !loggedIn) {