diff --git a/lib/actions/link-actions.js b/lib/actions/link-actions.js new file mode 100644 --- /dev/null +++ b/lib/actions/link-actions.js @@ -0,0 +1,33 @@ +// @flow + +import type { + InviteLinkVerificationRequest, + InviteLinkVerificationResponse, +} from '../types/link-types.js'; +import type { CallServerEndpoint } from '../utils/call-server-endpoint.js'; + +const verifyInviteLinkActionTypes = Object.freeze({ + started: 'VERIFY_INVITE_LINK_STARTED', + success: 'VERIFY_INVITE_LINK_SUCCESS', + failed: 'VERIFY_INVITE_LINK_FAILED', +}); +const verifyInviteLink = + ( + callServerEndpoint: CallServerEndpoint, + ): (( + request: InviteLinkVerificationRequest, + ) => Promise) => + async request => { + const response = await callServerEndpoint('verify_invite_link', request); + if (response.status === 'valid' || response.status === 'already_joined') { + return { + status: response.status, + community: response.community, + }; + } + return { + status: response.status, + }; + }; + +export { verifyInviteLinkActionTypes, verifyInviteLink }; diff --git a/lib/types/redux-types.js b/lib/types/redux-types.js --- a/lib/types/redux-types.js +++ b/lib/types/redux-types.js @@ -33,6 +33,7 @@ SetCalendarDeletedFilterPayload, } from './filter-types.js'; import type { LifecycleState } from './lifecycle-state-types.js'; +import type { InviteLinkVerificationResponse } from './link-types.js'; import type { LoadingStatus, LoadingInfo } from './loading-types.js'; import type { UpdateMultimediaMessageMediaPayload } from './media-types.js'; import type { MessageReportCreationResult } from './message-report-types.js'; @@ -988,6 +989,22 @@ +error: true, +payload: Error, +loadingInfo: LoadingInfo, + } + | { + +type: 'VERIFY_INVITE_LINK_STARTED', + +loadingInfo?: LoadingInfo, + +payload?: void, + } + | { + +type: 'VERIFY_INVITE_LINK_SUCCESS', + +payload: InviteLinkVerificationResponse, + +loadingInfo: LoadingInfo, + } + | { + +type: 'VERIFY_INVITE_LINK_FAILED', + +error: true, + +payload: Error, + +loadingInfo: LoadingInfo, }; export type ActionPayload = ?(Object | Array<*> | $ReadOnlyArray<*> | string);