Skip to content

A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.

TypeScript fluxerfluxerapp

feat(app): invite previews, 18+ notice and account setup prompt

Hampusebeb2f5ddbc4
diff --git a/fluxer_app/src/features/invite/commands/InviteCommands.tsx b/fluxer_app/src/features/invite/commands/InviteCommands.tsx
index 2ec77b62c..69179a2f0 100644
--- a/fluxer_app/src/features/invite/commands/InviteCommands.tsx
+++ b/fluxer_app/src/features/invite/commands/InviteCommands.tsx
@@ -2,13 +2,14 @@
import modalI18n from '@app/app/I18n';
import {FeatureTemporarilyDisabledModal} from '@app/features/app/components/alerts/FeatureTemporarilyDisabledModal';
-import {GenericErrorModal} from '@app/features/app/components/alerts/GenericErrorModal';
import {showGenericErrorModal} from '@app/features/app/components/alerts/GenericErrorModalCommands';
import {Endpoints} from '@app/features/app/constants/Endpoints';
-import RuntimeConfig from '@app/features/app/state/RuntimeConfig';
import Authentication from '@app/features/auth/state/Authentication';
+import {promptForAccountTier} from '@app/features/auth/utils/AccountTierPrompt';
+import {openGuildWhenAvailable} from '@app/features/guild/commands/GuildVisitCommands';
import {GuildAtCapacityModal} from '@app/features/guild/components/alerts/GuildAtCapacityModal';
import {MaxGuildsModal} from '@app/features/guild/components/alerts/MaxGuildsModal';
+import Guilds from '@app/features/guild/state/Guilds';
import {TRY_AGAIN_IN_A_MOMENT_DESCRIPTOR} from '@app/features/i18n/utils/CommonMessageDescriptors';
import {InvitesDisabledModal} from '@app/features/invite/components/alerts/InvitesDisabledModal';
import {InviteAcceptModal} from '@app/features/invite/components/modals/InviteAcceptModal';
@@ -30,6 +31,7 @@ import {APIErrorCodes} from '@fluxer/constants/src/ApiErrorCodes';
import {ME} from '@fluxer/constants/src/AppConstants';
import {ChannelTypes} from '@fluxer/constants/src/ChannelConstants';
import {GuildFeatures} from '@fluxer/constants/src/GuildConstants';
+import type {GuildVisitStartResponse} from '@fluxer/schema/src/domains/guild/GuildVisitSchemas';
import type {Invite} from '@fluxer/schema/src/domains/invite/InviteSchemas';
import type {I18n} from '@lingui/core';
import {msg} from '@lingui/core/macro';
@@ -70,26 +72,8 @@ const TemporaryInviteRequiresPresenceModal_YOU_MUST_BE_CONNECTED_TO_THE_GATEWAY_
'Modal body shown when the user tries to accept a temporary invite while the realtime connection is offline.',
});
-const ACCOUNT_VERIFICATION_REQUIRED_DESCRIPTOR = msg({
- message: 'Account verification required',
- comment:
- 'Title of the error modal shown when an unclaimed (guest) account tries to accept a community or group DM invite. Auth-related; keep tone plain.',
-});
-const PLEASE_VERIFY_YOUR_ACCOUNT_BY_SETTING_AN_EMAIL_DESCRIPTOR = msg({
- message: 'Add an email and password to your account first.',
- comment:
- 'Body of the error modal shown when an unclaimed (guest) account tries to accept a community invite. Tells the user to complete sign-up first.',
-});
-const ADD_A_USERNAME_AND_PASSWORD_DESCRIPTOR = msg({
- message: 'Add a username and password to your account first.',
- comment:
- 'Body of the error modal shown when an unclaimed (guest) account tries to accept a community invite on an instance where people sign in with a username.',
-});
const logger = new Logger('Invites');
const ACCEPT_INVITE_BODY = {} as Invite;
-const isUnclaimedAccountInviteError = (code?: string): boolean => {
- return code === APIErrorCodes.UNCLAIMED_ACCOUNT_CANNOT_JOIN_GROUP_DMS;
-};
const shouldOpenInviteGuildChannel = (channelType: number): boolean =>
channelType !== ChannelTypes.GUILD_CATEGORY && channelType !== ChannelTypes.GUILD_LINK;
@@ -118,24 +102,12 @@ function removeInviteIfMissing(
}
}
-function showUnclaimedAccountInviteModal(i18n: I18n): void {
- ModalCommands.push(
- modal(() => (
- <GenericErrorModal
- title={i18n._(ACCOUNT_VERIFICATION_REQUIRED_DESCRIPTOR)}
- message={i18n._(
- RuntimeConfig.usesUsernameSignIn
- ? ADD_A_USERNAME_AND_PASSWORD_DESCRIPTOR
- : PLEASE_VERIFY_YOUR_ACCOUNT_BY_SETTING_AN_EMAIL_DESCRIPTOR,
- )}
- data-flx="invite.invite-commands.show-unclaimed-account-invite-modal.generic-error-modal"
- />
- )),
- );
-}
+const ADULTS_ONLY_COMMUNITY_DESCRIPTOR = msg({
+ message: 'This community is for adults only.',
+ comment: 'Error dialog text when someone who is not an adult tries to open a community marked 18+.',
+});
function showGuildInviteAcceptFailure(
- i18n: I18n,
invite: Invite | null,
errorCode: string | undefined,
responseErr: HttpError | null,
@@ -183,6 +155,12 @@ function showGuildInviteAcceptFailure(
modalI18n._(TemporaryInviteRequiresPresenceModal_YOU_MUST_BE_CONNECTED_TO_THE_GATEWAY_TO_DESCRIPTOR),
dataFlx: 'app.temporary-invite-requires-presence-modal.confirm-modal',
});
+ } else if (errorCode === APIErrorCodes.GUILD_VISIT_AGE_RESTRICTED) {
+ showGenericErrorModal({
+ title: () => modalI18n._(InviteAcceptFailedModal_FAILED_TO_ACCEPT_INVITE_DESCRIPTOR),
+ message: () => modalI18n._(ADULTS_ONLY_COMMUNITY_DESCRIPTOR),
+ dataFlx: 'invite.invite-commands.show-guild-invite-accept-failure.adults-only-modal',
+ });
} else if (errorCode === APIErrorCodes.USER_BANNED_FROM_GUILD) {
showGenericErrorModal({
title: () => modalI18n._(UserBannedFromGuildModal_YOU_RE_BANNED_DESCRIPTOR),
@@ -195,8 +173,6 @@ function showGuildInviteAcceptFailure(
message: () => modalI18n._(UserIpBannedFromGuildModal_YOUR_IP_ADDRESS_IS_BANNED_FROM_THIS_COMMUNITY_DESCRIPTOR),
dataFlx: 'moderation.user-ip-banned-from-guild-modal.confirm-modal',
});
- } else if (isUnclaimedAccountInviteError(errorCode)) {
- showUnclaimedAccountInviteModal(i18n);
} else if (responseErr?.status && responseErr.status >= 400) {
showGenericErrorModal({
title: () => modalI18n._(InviteAcceptFailedModal_FAILED_TO_ACCEPT_INVITE_DESCRIPTOR),
@@ -275,6 +251,22 @@ export async function acceptAndTransitionToChannel(
NavigationCommands.selectChannel(guildId, targetChannelId);
return;
}
+ if (invite.guild.visits_enabled === true || Guilds.getGuild(guildId)?.visiting === true) {
+ logger.debug(`Visiting guild ${guildId} through invite ${code}`);
+ const visit = await instanceRequest<GuildVisitStartResponse>({
+ method: 'POST',
+ path: Endpoints.INVITE_VISIT(code),
+ target,
+ body: {},
+ }).catch((visitError: unknown) => {
+ if (failureCode(visitError) === APIErrorCodes.GUILD_VISITS_DISABLED) return null;
+ throw visitError;
+ });
+ if (visit !== null) {
+ await openGuildWhenAvailable(visit.body.guild_id, targetChannelId);
+ return;
+ }
+ }
logger.debug(`User not in guild ${guildId}, accepting invite ${code}`);
await accept(code, target);
logger.debug(
@@ -289,7 +281,9 @@ export async function acceptAndTransitionToChannel(
const errorCode = failureCode(error);
logger.error(`Failed to accept invite and transition for code ${code}:`, error);
removeInviteIfMissing(code, target, responseErr, errorCode);
- showGuildInviteAcceptFailure(i18n, invite, errorCode, responseErr);
+ if (!promptForAccountTier(error, () => void acceptAndTransitionToChannel(code, i18n, target))) {
+ showGuildInviteAcceptFailure(invite, errorCode, responseErr);
+ }
throw error;
}
}
diff --git a/fluxer_app/src/features/invite/components/modals/InviteAcceptModal.tsx b/fluxer_app/src/features/invite/components/modals/InviteAcceptModal.tsx
index 7a5e2c93c..4f6dc12dc 100644
--- a/fluxer_app/src/features/invite/components/modals/InviteAcceptModal.tsx
+++ b/fluxer_app/src/features/invite/components/modals/InviteAcceptModal.tsx
@@ -26,6 +26,7 @@ import {
INVITE_NOT_FOUND_DESCRIPTION_DESCRIPTOR,
INVITE_NOT_FOUND_TITLE_DESCRIPTOR,
INVITES_PAUSED_TRY_AGAIN_DESCRIPTOR,
+ PREVIEW_COMMUNITY_DESCRIPTOR,
RAID_INVITES_PAUSED_SHORT_DESCRIPTOR,
} from '@app/features/invite/utils/InviteMessageDescriptors';
import {findInviteOnOtherAccount, type InviteAccountMatch} from '@app/features/invite/utils/InviteOtherAccountLookup';
@@ -33,12 +34,13 @@ import type {InstanceHTTPTarget} from '@app/features/platform/transport/Instance
import {Logger} from '@app/features/platform/utils/AppLogger';
import {Button} from '@app/features/ui/button/Button';
import * as ModalCommands from '@app/features/ui/commands/ModalCommands';
+import Users from '@app/features/user/state/Users';
import * as AvatarUtils from '@app/features/user/utils/AvatarUtils';
import foodPatternUrl from '@app/media/images/i-like-food.svg';
import {msg} from '@lingui/core/macro';
import {useLingui} from '@lingui/react/macro';
import {observer} from 'mobx-react-lite';
-import {useCallback, useEffect, useMemo, useState} from 'react';
+import {type ReactNode, useCallback, useEffect, useMemo, useState} from 'react';
const JOIN_GROUP_DM_DESCRIPTOR = msg({
message: 'Join group DM',
@@ -62,6 +64,10 @@ const OPEN_INVITE_WITH_ACCOUNT_DESCRIPTOR = msg({
comment:
'Button in the invite accept modal that switches to another signed-in account and opens the invite there. instanceName is a server or instance domain.',
});
+const ADULTS_ONLY_COMMUNITY_DESCRIPTOR = msg({
+ message: 'This community is for adults only.',
+ comment: 'Text in the invite dialog when the community is marked 18+ and the person is not an adult.',
+});
const OPEN_INVITE_ON_INSTANCE_DESCRIPTOR = msg({
message: 'Open on {instanceName}',
comment:
@@ -142,7 +148,12 @@ export const InviteAcceptModal = observer(function InviteAcceptModal({code, targ
splash: guild.splash,
});
}, [invite]);
- const isJoinDisabled = isGuildInviteActionDisabled(guildActionState);
+ const adultsOnly =
+ invite != null &&
+ isGuildInvite(invite) &&
+ invite.guild.nsfw === true &&
+ Users.currentUser?.matureContentAllowed === false;
+ const isJoinDisabled = isGuildInviteActionDisabled(guildActionState) || adultsOnly;
const primaryActionType = getGuildInvitePrimaryAction(guildActionState);
const primaryLabel = useMemo(() => {
if (isGroupDM) return i18n._(JOIN_GROUP_DM_DESCRIPTOR);
@@ -151,6 +162,8 @@ export const InviteAcceptModal = observer(function InviteAcceptModal({code, targ
return i18n._(INVITES_PAUSED_DESCRIPTOR);
case GuildInvitePrimaryAction.GoToCommunity:
return i18n._(GO_TO_COMMUNITY_DESCRIPTOR);
+ case GuildInvitePrimaryAction.OpenVisit:
+ return i18n._(PREVIEW_COMMUNITY_DESCRIPTOR);
default:
return i18n._(JOIN_COMMUNITY_DESCRIPTOR);
}
@@ -223,16 +236,32 @@ export const InviteAcceptModal = observer(function InviteAcceptModal({code, targ
</div>
);
}
+ const cardClassName = styles.cardInner;
+ const header = (
+ <InviteHeader invite={inviteForHeader} data-flx="invite.invite-accept-modal.render-body.invite-header--2" />
+ );
+ let restriction: ReactNode;
+ if (adultsOnly) {
+ restriction = (
+ <p className={styles.disabledText} data-flx="invite.invite-accept-modal.render-body.adults-only-text">
+ {i18n._(ADULTS_ONLY_COMMUNITY_DESCRIPTOR)}
+ </p>
+ );
+ } else if (isJoinDisabled) {
+ restriction = (
+ <p className={styles.disabledText} data-flx="invite.invite-accept-modal.render-body.disabled-text">
+ {guildActionState.isRaidDetected
+ ? i18n._(RAID_INVITES_PAUSED_SHORT_DESCRIPTOR, {productName: getActiveInstanceProductName()})
+ : i18n._(INVITES_PAUSED_TRY_AGAIN_DESCRIPTOR)}
+ </p>
+ );
+ } else {
+ restriction = null;
+ }
return (
- <div className={styles.cardInner} data-flx="invite.invite-accept-modal.render-body.card-inner--2">
- <InviteHeader invite={inviteForHeader} data-flx="invite.invite-accept-modal.render-body.invite-header--2" />
- {isJoinDisabled ? (
- <p className={styles.disabledText} data-flx="invite.invite-accept-modal.render-body.disabled-text">
- {guildActionState.isRaidDetected
- ? i18n._(RAID_INVITES_PAUSED_SHORT_DESCRIPTOR, {productName: getActiveInstanceProductName()})
- : i18n._(INVITES_PAUSED_TRY_AGAIN_DESCRIPTOR)}
- </p>
- ) : null}
+ <div className={cardClassName} data-flx="invite.invite-accept-modal.render-body.card-inner--2">
+ {header}
+ {restriction}
<div className={styles.actions} data-flx="invite.invite-accept-modal.render-body.actions--2">
<Button
onClick={handleAccept}
diff --git a/fluxer_app/src/features/invite/utils/GuildInviteActionState.ts b/fluxer_app/src/features/invite/utils/GuildInviteActionState.ts
index e933d4dfc..e3bdb1237 100644
--- a/fluxer_app/src/features/invite/utils/GuildInviteActionState.ts
+++ b/fluxer_app/src/features/invite/utils/GuildInviteActionState.ts
@@ -2,6 +2,7 @@
import Authentication from '@app/features/auth/state/Authentication';
import type {Guild} from '@app/features/guild/models/Guild';
+import Guilds from '@app/features/guild/state/Guilds';
import {isGuildInvite} from '@app/features/invite/types/InviteTypes';
import GuildMembers from '@app/features/member/state/GuildMembers';
import {GuildFeatures} from '@fluxer/constants/src/GuildConstants';
@@ -21,11 +22,13 @@ export interface GuildInviteActionState {
memberCount: number;
isInvitesDisabled: boolean;
isRaidDetected: boolean;
+ visitsEnabled: boolean;
features: Array<string>;
}
export enum GuildInvitePrimaryAction {
JoinCommunity = 'join',
+ OpenVisit = 'visit',
GoToCommunity = 'go',
InvitesDisabled = 'disabled',
}
@@ -51,6 +54,8 @@ export function getGuildInviteActionState(params: {
features,
isInvitesDisabled: features.includes(GuildFeatures.INVITES_DISABLED),
isRaidDetected: features.includes(GuildFeatures.RAID_DETECTED),
+ visitsEnabled:
+ inviteGuild?.visits_enabled === true || (guildId !== null && Guilds.getGuild(guildId)?.visiting === true),
};
}
@@ -61,6 +66,9 @@ export function getGuildInvitePrimaryAction(state: GuildInviteActionState): Guil
if (state.isMember) {
return GuildInvitePrimaryAction.GoToCommunity;
}
+ if (state.visitsEnabled) {
+ return GuildInvitePrimaryAction.OpenVisit;
+ }
return GuildInvitePrimaryAction.JoinCommunity;
}
diff --git a/fluxer_app/src/features/invite/utils/InviteMessageDescriptors.ts b/fluxer_app/src/features/invite/utils/InviteMessageDescriptors.ts
index 662059fa7..64038c9b9 100644
--- a/fluxer_app/src/features/invite/utils/InviteMessageDescriptors.ts
+++ b/fluxer_app/src/features/invite/utils/InviteMessageDescriptors.ts
@@ -49,3 +49,9 @@ export const INVITES_PAUSED_ACCOUNT_ACTIONS_DESCRIPTOR = msg({
'You can still create an account or sign in. If invites are re-enabled later, you can use this same link to join.',
comment: 'Invite page subtext shown when community admins pause invites. Explains that account actions still work.',
});
+export const PREVIEW_COMMUNITY_DESCRIPTOR = msg({
+ message: 'Preview',
+ context: 'invite-preview-button',
+ comment:
+ 'Invite button, a verb: starts previewing the community before joining it. Previewing means reading a community before joining. Joining happens from the bar at the top of the community.',
+});