diff --git a/lib/hooks/invite-links.js b/lib/hooks/invite-links.js --- a/lib/hooks/invite-links.js +++ b/lib/hooks/invite-links.js @@ -129,7 +129,26 @@ joinThreadActionTypes, ); -export type LinkStatus = 'invalid' | 'valid' | 'timed_out'; +export type LinkStatus = 'invalid' | 'valid' | 'timed_out' | 'already_joined'; + +const inviteLinkTexts: { + +[LinkStatus]: { +header: string, +message: string }, +} = { + invalid: { + header: 'Invite invalid', + message: + 'This invite link may be expired. Please try again with another invite' + + ' link.', + }, + ['timed_out']: { + header: 'Timeout', + message: 'The request has timed out.', + }, + ['already_joined']: { + header: 'Already a member', + message: 'You are already a member of this community.', + }, +}; type AcceptInviteLinkParams = { +verificationResponse: InviteLinkVerificationResponse, @@ -152,12 +171,6 @@ setLinkStatus, } = params; - React.useEffect(() => { - if (verificationResponse.status === 'already_joined') { - onFinish(); - } - }, [onFinish, verificationResponse.status]); - const dispatch = useDispatch(); const callJoinThread = useJoinThread(); @@ -318,4 +331,4 @@ ); } -export { useInviteLinksActions, useAcceptInviteLink }; +export { useInviteLinksActions, useAcceptInviteLink, inviteLinkTexts }; 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 @@ -146,9 +146,6 @@ validateLinkPromise, ); result = await validateLinkPromise; - if (result.status === 'already_joined') { - return; - } } catch (e) { console.log(e); result = { diff --git a/native/navigation/invite-link-modal.react.js b/native/navigation/invite-link-modal.react.js --- a/native/navigation/invite-link-modal.react.js +++ b/native/navigation/invite-link-modal.react.js @@ -3,7 +3,10 @@ import * as React from 'react'; import { View, Text, ActivityIndicator } from 'react-native'; -import { useAcceptInviteLink } from 'lib/hooks/invite-links.js'; +import { + inviteLinkTexts, + useAcceptInviteLink, +} from 'lib/hooks/invite-links.js'; import type { LinkStatus } from 'lib/hooks/invite-links.js'; import type { KeyserverOverride } from 'lib/shared/invite-links'; import type { InviteLinkVerificationResponse } from 'lib/types/link-types.js'; @@ -32,7 +35,10 @@ const styles = useStyles(unboundStyles); const { invitationDetails, secret, keyserverOverride } = props.route.params; const [linkStatus, setLinkStatus] = React.useState( - invitationDetails.status === 'valid' ? 'valid' : 'invalid', + invitationDetails.status === 'valid' || + invitationDetails.status === 'already_joined' + ? invitationDetails.status + : 'invalid', ); const navContext = React.useContext(NavContext); @@ -63,16 +69,14 @@ ); } - const headerText = linkStatus === 'invalid' ? 'Invite invalid' : 'Timeout'; - const message = - linkStatus === 'invalid' - ? 'This invite link may be expired. Please try again with another ' + - 'invite link.' - : 'The request has timed out.'; return ( <> - {headerText} - {message} + + {inviteLinkTexts[linkStatus].header} + + + {inviteLinkTexts[linkStatus].message} + ); }, [ diff --git a/web/invite-links/accept-invite-modal.react.js b/web/invite-links/accept-invite-modal.react.js --- a/web/invite-links/accept-invite-modal.react.js +++ b/web/invite-links/accept-invite-modal.react.js @@ -4,7 +4,10 @@ import ModalOverlay from 'lib/components/modal-overlay.react.js'; import { useModalContext } from 'lib/components/modal-provider.react.js'; -import { useAcceptInviteLink } from 'lib/hooks/invite-links.js'; +import { + inviteLinkTexts, + useAcceptInviteLink, +} from 'lib/hooks/invite-links.js'; import type { LinkStatus } from 'lib/hooks/invite-links.js'; import type { KeyserverOverride } from 'lib/shared/invite-links.js'; import { type InviteLinkVerificationResponse } from 'lib/types/link-types.js'; @@ -23,7 +26,10 @@ function AcceptInviteModal(props: Props): React.Node { const { verificationResponse, inviteSecret, keyserverOverride } = props; const [linkStatus, setLinkStatus] = React.useState( - verificationResponse.status === 'valid' ? 'valid' : 'invalid', + verificationResponse.status === 'valid' || + verificationResponse.status === 'already_joined' + ? verificationResponse.status + : 'invalid', ); const { popModal } = useModalContext(); const calendarQuery = useSelector(nonThreadCalendarQuery); @@ -61,17 +67,13 @@ ); } else { - const header = linkStatus === 'invalid' ? 'Invite invalid' : 'Timeout'; - const message = - linkStatus === 'invalid' - ? 'This invite link may be expired. Please try again with another ' + - 'invite link.' - : 'The request has timed out.'; content = ( <>
-
{header}
-
{message}
+
+ {inviteLinkTexts[linkStatus].header} +
+
{inviteLinkTexts[linkStatus].message}