Skip to content

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

TypeScript fluxerfluxerapp

feat(app): gate sends, reports, gifts, communities on setup

Hampus0c9b4e47ee99
diff --git a/fluxer_app/src/features/channel/components/GiftEmbed.module.css b/fluxer_app/src/features/channel/components/GiftEmbed.module.css
index d757d74e3..61ad32342 100644
--- a/fluxer_app/src/features/channel/components/GiftEmbed.module.css
+++ b/fluxer_app/src/features/channel/components/GiftEmbed.module.css
@@ -143,13 +143,3 @@
width: 100%;
border-radius: 0.375rem;
}
-
-@keyframes pulse {
- 0%,
- 100% {
- opacity: 1;
- }
- 50% {
- opacity: 0.5;
- }
-}
diff --git a/fluxer_app/src/features/channel/components/GiftEmbed.tsx b/fluxer_app/src/features/channel/components/GiftEmbed.tsx
index df09d1df5..646f0e5d6 100644
--- a/fluxer_app/src/features/channel/components/GiftEmbed.tsx
+++ b/fluxer_app/src/features/channel/components/GiftEmbed.tsx
@@ -1,6 +1,5 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
-import {openClaimAccountModal} from '@app/features/auth/components/modals/ClaimAccountModal';
import styles from '@app/features/channel/components/GiftEmbed.module.css';
import * as GiftCommands from '@app/features/gift/commands/GiftCommands';
import Gifts from '@app/features/gift/state/Gifts';
@@ -18,7 +17,10 @@ import {Logger} from '@app/features/platform/utils/AppLogger';
import {ComponentBus} from '@app/features/platform/utils/ComponentBus';
import {Button} from '@app/features/ui/button/Button';
import Users from '@app/features/user/state/Users';
+import {getAccountGatePresentation} from '@app/features/user/utils/AccountGatePresentation';
+import {canPerform} from '@app/features/user/utils/AccountGates';
import * as NicknameUtils from '@app/features/user/utils/NicknameUtils';
+import {TierGatedActions} from '@fluxer/constants/src/AccountTierConstants';
import {msg} from '@lingui/core/macro';
import {useLingui} from '@lingui/react/macro';
import {GiftIcon, QuestionIcon} from '@phosphor-icons/react';
@@ -33,10 +35,6 @@ const ALREADY_REDEEMED_DESCRIPTOR = msg({
message: 'Already redeemed',
comment: 'Status pill on a gift code embed when the gift has already been claimed.',
});
-const CLAIM_YOUR_ACCOUNT_TO_REDEEM_THIS_GIFT_DESCRIPTOR = msg({
- message: 'Claim your account to redeem this gift.',
- comment: 'Helper text on a gift code embed for guest accounts. Prompts account claim before redeeming.',
-});
const CLICK_TO_CLAIM_YOUR_GIFT_DESCRIPTOR = msg({
message: 'Click to claim your gift!',
comment: 'Call-to-action text on a redeemable gift code embed. Tone can be friendly.',
@@ -45,10 +43,6 @@ const GIFT_CLAIMED_DESCRIPTOR = msg({
message: 'Gift claimed',
comment: 'Toast confirmation shown after successfully claiming a gift from the gift code embed.',
});
-const CLAIM_ACCOUNT_TO_REDEEM_DESCRIPTOR = msg({
- message: 'Claim account to redeem',
- comment: 'Button label on a gift code embed for guest accounts. Opens the account claim flow.',
-});
const CLAIM_GIFT_DESCRIPTOR = msg({
message: 'Claim gift',
comment: 'Primary button label on a redeemable gift code embed.',
@@ -77,7 +71,7 @@ export const GiftEmbed = observer(function GiftEmbed({code}: GiftEmbedProps) {
const giftState = Gifts.getGift(code, target);
const gift = giftState?.data;
const creator = Users.getUser(gift?.created_by?.id ?? '');
- const isUnclaimed = !(Users.currentUser?.isClaimed() ?? false);
+ const giftRedeemGate = canPerform(Users.currentUser, TierGatedActions.GIFT_REDEEM);
useEffect(() => {
if (!giftState) {
void GiftCommands.fetchWithCoalescing(code, target).catch(() => {});
@@ -99,9 +93,10 @@ export const GiftEmbed = observer(function GiftEmbed({code}: GiftEmbedProps) {
}
const durationText = getGiftDurationText(i18n, gift);
const creatorTag = creator ? NicknameUtils.getDisplayName(creator) : '';
+ const gatePresentation = giftRedeemGate.allowed ? null : getAccountGatePresentation(i18n, giftRedeemGate);
const handleRedeem = async () => {
- if (isUnclaimed) {
- openClaimAccountModal({force: true});
+ if (gatePresentation) {
+ gatePresentation.onAction();
return;
}
try {
@@ -117,11 +112,9 @@ export const GiftEmbed = observer(function GiftEmbed({code}: GiftEmbedProps) {
) : undefined;
const helpText = gift.redeemed
? i18n._(ALREADY_REDEEMED_DESCRIPTOR)
- : isUnclaimed
- ? i18n._(CLAIM_YOUR_ACCOUNT_TO_REDEEM_THIS_GIFT_DESCRIPTOR)
- : i18n._(CLICK_TO_CLAIM_YOUR_GIFT_DESCRIPTOR);
+ : (gatePresentation?.description ?? i18n._(CLICK_TO_CLAIM_YOUR_GIFT_DESCRIPTOR));
const footer =
- gift.redeemed && !isUnclaimed ? (
+ gift.redeemed && gatePresentation === null ? (
<Button variant="primary" fitContainer matchSkeletonHeight disabled data-flx="channel.gift-embed.button">
{i18n._(GIFT_CLAIMED_DESCRIPTOR)}
</Button>
@@ -131,12 +124,12 @@ export const GiftEmbed = observer(function GiftEmbed({code}: GiftEmbedProps) {
fitContainer
matchSkeletonHeight
onClick={handleRedeem}
- disabled={gift.redeemed || isUnclaimed}
+ disabled={gift.redeemed}
data-flx="channel.gift-embed.button.redeem"
>
{(() => {
if (gift.redeemed) return i18n._(GIFT_CLAIMED_DESCRIPTOR);
- if (isUnclaimed) return i18n._(CLAIM_ACCOUNT_TO_REDEEM_DESCRIPTOR);
+ if (gatePresentation) return gatePresentation.actionLabel;
return i18n._(CLAIM_GIFT_DESCRIPTOR);
})()}
</Button>
diff --git a/fluxer_app/src/features/channel/components/VerificationBarrier.tsx b/fluxer_app/src/features/channel/components/VerificationBarrier.tsx
index 64549a04e..64e0839c4 100644
--- a/fluxer_app/src/features/channel/components/VerificationBarrier.tsx
+++ b/fluxer_app/src/features/channel/components/VerificationBarrier.tsx
@@ -1,13 +1,12 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
import {
+ AccountGateBarrier,
AccountTooNewBarrier,
DefaultBarrier,
NotMemberLongEnoughBarrier,
SendMessageDisabledBarrier,
TimeoutBarrier,
- UnclaimedAccountBarrier,
- UnverifiedEmailBarrier,
} from '@app/features/channel/components/barriers/BarrierComponents';
import type {Channel} from '@app/features/channel/models/Channel';
import GuildVerification, {VerificationFailureReason} from '@app/features/guild/state/GuildVerification';
@@ -24,10 +23,15 @@ export const VerificationBarrier = observer(({channel}: Props) => {
return null;
}
switch (verificationStatus.reason) {
- case VerificationFailureReason.UNCLAIMED_ACCOUNT:
- return <UnclaimedAccountBarrier data-flx="channel.verification-barrier.unclaimed-account-barrier" />;
- case VerificationFailureReason.UNVERIFIED_EMAIL:
- return <UnverifiedEmailBarrier data-flx="channel.verification-barrier.unverified-email-barrier" />;
+ case VerificationFailureReason.ACCOUNT_GATE:
+ return verificationStatus.accountGate ? (
+ <AccountGateBarrier
+ gate={verificationStatus.accountGate}
+ data-flx="channel.verification-barrier.account-gate-barrier"
+ />
+ ) : (
+ <DefaultBarrier data-flx="channel.verification-barrier.default-barrier" />
+ );
case VerificationFailureReason.ACCOUNT_TOO_NEW:
return (
<AccountTooNewBarrier
diff --git a/fluxer_app/src/features/channel/components/barriers/BarrierComponents.tsx b/fluxer_app/src/features/channel/components/barriers/BarrierComponents.tsx
index d3dc66042..4324a86ce 100644
--- a/fluxer_app/src/features/channel/components/barriers/BarrierComponents.tsx
+++ b/fluxer_app/src/features/channel/components/barriers/BarrierComponents.tsx
@@ -2,30 +2,30 @@
import {getActiveInstanceProductName} from '@app/features/app/state/ActiveInstanceProductName';
import RuntimeConfig from '@app/features/app/state/RuntimeConfig';
-import {openClaimAccountModal} from '@app/features/auth/components/modals/ClaimAccountModal';
-import {useVerifyEmailAction} from '@app/features/auth/hooks/useVerifyEmailAction';
import styles from '@app/features/channel/components/barriers/BarrierComponents.module.css';
import {openChannelFollowModal} from '@app/features/channel/components/modals/ChannelFollowModal';
import wrapperStyles from '@app/features/channel/components/textarea/InputWrapper.module.css';
import textareaStyles from '@app/features/channel/components/textarea/TextareaInput.module.css';
import {FOLLOW_DESCRIPTOR} from '@app/features/channel/utils/ChannelFollowUtils';
-import {CLAIM_ACCOUNT_DESCRIPTOR} from '@app/features/i18n/utils/CommonMessageDescriptors';
import {getCachedNumberFormat} from '@app/features/i18n/utils/IntlCache';
import {unblockUser} from '@app/features/relationship/utils/RelationshipActionUtils';
import {remFromPx} from '@app/features/theme/layout/RemFromPx';
import {Button} from '@app/features/ui/button/Button';
import {openMessagingPausedHelpModal} from '@app/features/user/components/modals/MessagingPausedHelpModal';
+import {
+ type AccountGate,
+ getAccountGatePresentation,
+ useAccountGateAction,
+} from '@app/features/user/utils/AccountGatePresentation';
import {ACCOUNT_LIMITED_NOTICE_DESCRIPTOR} from '@app/features/user/utils/AccountLimitUtils';
import {TEXT_DID_NOT_GO_THROUGH_DESCRIPTOR} from '@app/features/user/utils/MessagingPausedHelpEmail';
import {msg} from '@lingui/core/macro';
import {Trans, useLingui} from '@lingui/react/macro';
import {
ClockIcon,
- EnvelopeSimpleIcon,
InfoIcon,
MegaphoneSimpleIcon,
ProhibitIcon,
- ShieldWarningIcon,
TimerIcon,
WarningCircleIcon,
} from '@phosphor-icons/react';
@@ -136,57 +136,32 @@ const CountdownTimer = observer(({initialTime}: {initialTime: number}) => {
</div>
);
});
-export const UnclaimedAccountBarrier = observer(() => {
+export const AccountGateBarrier = observer(({gate}: {gate: AccountGate}) => {
const {i18n} = useLingui();
+ const presentation = getAccountGatePresentation(i18n, gate);
+ const action = useAccountGateAction(gate);
return (
<BarrierBase
- message={<Trans>You need to claim your account to send messages in this community.</Trans>}
- icon={
- <ShieldWarningIcon
- size={remFromPx(18)}
- weight="fill"
- data-flx="channel.barriers.barrier-components.unclaimed-account-barrier.shield-warning-icon"
- />
- }
- action={
- <Button
- small={true}
- onClick={() => {
- openClaimAccountModal({force: true});
- }}
- data-flx="channel.barriers.barrier-components.unclaimed-account-barrier.button.action"
- >
- {i18n._(CLAIM_ACCOUNT_DESCRIPTOR)}
- </Button>
- }
- data-flx="channel.barriers.barrier-components.unclaimed-account-barrier.barrier-base"
- />
- );
-});
-export const UnverifiedEmailBarrier = observer(() => {
- const verifyEmailAction = useVerifyEmailAction();
- return (
- <BarrierBase
- message={<Trans>You need to verify your email to send messages in this community.</Trans>}
+ message={presentation.description}
icon={
- <EnvelopeSimpleIcon
+ <presentation.Icon
size={remFromPx(18)}
weight="fill"
- data-flx="channel.barriers.barrier-components.unverified-email-barrier.envelope-simple-icon"
+ data-flx="channel.barriers.barrier-components.account-gate-barrier.icon"
/>
}
action={
<Button
small={true}
- onClick={verifyEmailAction.onClick}
- disabled={verifyEmailAction.submitting}
- submitting={verifyEmailAction.submitting}
- data-flx="channel.barriers.barrier-components.unverified-email-barrier.button.action"
+ onClick={action.onClick}
+ disabled={action.submitting}
+ submitting={action.submitting}
+ data-flx="channel.barriers.barrier-components.account-gate-barrier.button.action"
>
- {verifyEmailAction.text}
+ {action.text}
</Button>
}
- data-flx="channel.barriers.barrier-components.unverified-email-barrier.barrier-base"
+ data-flx="channel.barriers.barrier-components.account-gate-barrier.barrier-base"
/>
);
});
@@ -400,30 +375,3 @@ export const BlockedUserBarrier = observer(({userId, username, onAction}: Blocke
/>
);
});
-export const UnclaimedDMBarrier = observer(() => {
- const {i18n} = useLingui();
- return (
- <BarrierBase
- message={<Trans>You need to claim your account to send direct messages.</Trans>}
- icon={
- <ShieldWarningIcon
- size={remFromPx(18)}
- weight="fill"
- data-flx="channel.barriers.barrier-components.unclaimed-dm-barrier.shield-warning-icon"
- />
- }
- action={
- <Button
- small={true}
- onClick={() => {
- openClaimAccountModal({force: true});
- }}
- data-flx="channel.barriers.barrier-components.unclaimed-dm-barrier.button.action"
- >
- {i18n._(CLAIM_ACCOUNT_DESCRIPTOR)}
- </Button>
- }
- data-flx="channel.barriers.barrier-components.unclaimed-dm-barrier.barrier-base"
- />
- );
-});
diff --git a/fluxer_app/src/features/guild/components/modals/AddGuildModal.module.css b/fluxer_app/src/features/guild/components/modals/AddGuildModal.module.css
index 33d0c0d93..fe2f878d7 100644
--- a/fluxer_app/src/features/guild/components/modals/AddGuildModal.module.css
+++ b/fluxer_app/src/features/guild/components/modals/AddGuildModal.module.css
@@ -214,21 +214,3 @@
align-items: center;
gap: 0.5rem;
}
-
-.verificationNotice {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: 0.75rem;
- padding: 1.5rem 1rem;
- text-align: center;
- color: var(--text-primary-muted);
-}
-
-.verificationNotice > svg {
- color: var(--text-primary-muted);
-}
-
-.verificationNotice > p {
- margin: 0;
-}
diff --git a/fluxer_app/src/features/guild/components/modals/add_guild_modal/GuildCreateShared.tsx b/fluxer_app/src/features/guild/components/modals/add_guild_modal/GuildCreateShared.tsx
index 8169413bc..c14385d19 100644
--- a/fluxer_app/src/features/guild/components/modals/add_guild_modal/GuildCreateShared.tsx
+++ b/fluxer_app/src/features/guild/components/modals/add_guild_modal/GuildCreateShared.tsx
@@ -6,8 +6,6 @@ import {ExternalLink} from '@app/features/app/components/shared/ExternalLink';
import {AVATAR_RECOMMENDED_SIZE_LABEL, STATIC_IMAGE_FORMATS} from '@app/features/app/config/I18nDisplayConstants';
import RuntimeConfig from '@app/features/app/state/RuntimeConfig';
import {GlobalLimits} from '@app/features/app/utils/GlobalLimits';
-import {openClaimAccountModal} from '@app/features/auth/components/modals/ClaimAccountModal';
-import {useVerifyEmailAction} from '@app/features/auth/hooks/useVerifyEmailAction';
import {AssetCropModal, AssetType} from '@app/features/expressions/components/modals/AssetCropModal';
import {openAssetSourceModal} from '@app/features/expressions/components/modals/AssetSourceModal';
import {isAnimatedFile} from '@app/features/expressions/utils/AnimatedImageUtils';
@@ -27,17 +25,18 @@ import {
import {openFilePicker} from '@app/features/messaging/utils/FilePickerUtils';
import {formatFileSize} from '@app/features/messaging/utils/FileUtils';
import {readBlobAsDataUrl} from '@app/features/platform/utils/BlobDataUrl';
-import {remFromPx} from '@app/features/theme/layout/RemFromPx';
import {Button} from '@app/features/ui/button/Button';
import * as ModalCommands from '@app/features/ui/commands/ModalCommands';
import {modal} from '@app/features/ui/commands/ModalCommands';
import {Input} from '@app/features/ui/components/form/FormInput';
import Users from '@app/features/user/state/Users';
+import {AccountGateSlate} from '@app/features/user/utils/AccountGatePresentation';
+import {canPerform} from '@app/features/user/utils/AccountGates';
+import {TierGatedActions} from '@fluxer/constants/src/AccountTierConstants';
import {getAcceptString} from '@fluxer/constants/src/AssetFormatPolicy';
import type {I18n, MessageDescriptor} from '@lingui/core';
import {ph} from '@lingui/core/macro';
import {Trans, useLingui} from '@lingui/react/macro';
-import {EnvelopeSimpleIcon} from '@phosphor-icons/react';
import type React from 'react';
import {useCallback, useState} from 'react';
import type {UseFormReturn} from 'react-hook-form';
@@ -148,57 +147,14 @@ export function useGuildCreateIconField({
return {previewIconUrl, iconName, handleOpenIconUpload, handleClearIcon};
}
-const GuildCreateVerifyEmailButton = ({dataFlx}: {dataFlx: string}) => {
- const verifyEmailAction = useVerifyEmailAction();
+export function renderGuildCreateAccountGate(dataFlx: string): React.ReactNode {
+ const gate = canPerform(Users.currentUser, TierGatedActions.GUILD_CREATE);
+ if (gate.allowed) return null;
return (
- <Button
- onClick={verifyEmailAction.onClick}
- disabled={verifyEmailAction.submitting}
- submitting={verifyEmailAction.submitting}
- data-flx={`${dataFlx}.button.push`}
- >
- {verifyEmailAction.text}
- </Button>
+ <div className={styles.formContainer} data-flx={`${dataFlx}.form-container`}>
+ <AccountGateSlate gate={gate} data-flx={`${dataFlx}.account-gate-slate`} />
+ </div>
);
-};
-
-export function renderGuildCreateAccountGate(dataFlx: string): React.ReactNode {
- const currentUser = Users.currentUser;
- if (currentUser != null && !currentUser.isClaimed()) {
- return (
- <div className={styles.formContainer} data-flx={`${dataFlx}.form-container`}>
- <div className={styles.verificationNotice} data-flx={`${dataFlx}.verification-notice`}>
- <EnvelopeSimpleIcon size={remFromPx(32)} weight="fill" data-flx={`${dataFlx}.envelope-simple-icon`} />
- <p data-flx={`${dataFlx}.p`}>
- <Trans>You need to claim your account before you can create a community.</Trans>
- </p>
- <Button
- onClick={() => openClaimAccountModal({force: true})}
- data-flx={`${dataFlx}.button.open-claim-account-modal`}
- >
- <Trans>Claim your account</Trans>
- </Button>
- </div>
- </div>
- );
- }
- if (currentUser?.verified === false) {
- return (
- <div className={styles.formContainer} data-flx={`${dataFlx}.form-container--2`}>
- <div className={styles.verificationNotice} data-flx={`${dataFlx}.verification-notice--2`}>
- <EnvelopeSimpleIcon size={remFromPx(32)} weight="fill" data-flx={`${dataFlx}.envelope-simple-icon--2`} />
- <p data-flx={`${dataFlx}.p--2`}>
- <Trans>You need to verify your email address before you can create a community.</Trans>
- </p>
- <GuildCreateVerifyEmailButton
- dataFlx={dataFlx}
- data-flx="guild.add-guild-modal.guild-create-shared.render-guild-create-account-gate.guild-create-verify-email-button"
- />
- </div>
- </div>
- );
- }
- return null;
}
interface GuildCreateFieldsOptions extends ReturnType<typeof useGuildCreateIconField> {
diff --git a/fluxer_app/src/features/guild/components/modals/add_guild_modal/shared.ts b/fluxer_app/src/features/guild/components/modals/add_guild_modal/shared.ts
index 22ea5438c..33cb5f432 100644
--- a/fluxer_app/src/features/guild/components/modals/add_guild_modal/shared.ts
+++ b/fluxer_app/src/features/guild/components/modals/add_guild_modal/shared.ts
@@ -87,7 +87,7 @@ export function handleGuildCreationError(error: unknown): never {
throw new DOMException('Guild create skipped', 'AbortError');
}
if (failureCode(error) === APIErrorCodes.UNCLAIMED_ACCOUNT_CANNOT_CREATE_GUILDS) {
- openClaimAccountModal({force: true});
+ openClaimAccountModal();
}
throw error;
}
diff --git a/fluxer_app/src/features/guild/state/GuildVerification.ts b/fluxer_app/src/features/guild/state/GuildVerification.ts
index c1cc4f60a..53c996224 100644
--- a/fluxer_app/src/features/guild/state/GuildVerification.ts
+++ b/fluxer_app/src/features/guild/state/GuildVerification.ts
@@ -4,6 +4,9 @@ import type {Guild} from '@app/features/guild/models/Guild';
import Guilds from '@app/features/guild/state/Guilds';
import GuildMembers from '@app/features/member/state/GuildMembers';
import Users from '@app/features/user/state/Users';
+import {type AccountGateResult, canPerform} from '@app/features/user/utils/AccountGates';
+import {TierGatedActions} from '@fluxer/constants/src/AccountTierConstants';
+import type {TierGateDenial} from '@fluxer/constants/src/AccountTierRules';
import {
GuildFeatures,
GuildOperations,
@@ -16,8 +19,7 @@ import {makeAutoObservable} from 'mobx';
const FIVE_MINUTES_MS = 5 * 60 * 1000;
const TEN_MINUTES_MS = 10 * 60 * 1000;
export const VerificationFailureReason = {
- UNCLAIMED_ACCOUNT: 'UNCLAIMED_ACCOUNT',
- UNVERIFIED_EMAIL: 'UNVERIFIED_EMAIL',
+ ACCOUNT_GATE: 'ACCOUNT_GATE',
ACCOUNT_TOO_NEW: 'ACCOUNT_TOO_NEW',
NOT_MEMBER_LONG_ENOUGH: 'NOT_MEMBER_LONG_ENOUGH',
SEND_MESSAGE_DISABLED: 'SEND_MESSAGE_DISABLED',
@@ -30,6 +32,12 @@ interface VerificationStatus {
canAccess: boolean;
reason?: VerificationFailureReason;
verificationEndsAt?: number;
+ accountGate?: TierGateDenial;
+}
+
+function accountGateStatus(gate: AccountGateResult): VerificationStatus | null {
+ if (gate.allowed) return null;
+ return {canAccess: false, reason: VerificationFailureReason.ACCOUNT_GATE, accountGate: gate};
}
class GuildVerification {
@@ -119,7 +127,7 @@ class GuildVerification {
private computeVerificationStatus(guild: Guild): VerificationStatus {
const user = Users.getCurrentUser();
if (!user) {
- return {canAccess: false, reason: VerificationFailureReason.UNCLAIMED_ACCOUNT};
+ return accountGateStatus(canPerform(null, TierGatedActions.MESSAGE)) ?? {canAccess: false};
}
const member = GuildMembers.getMember(guild.id, user.id);
const now = Date.now();
@@ -136,6 +144,10 @@ class GuildVerification {
if ((guild.disabledOperations & GuildOperations.SEND_MESSAGE) !== 0) {
return {canAccess: false, reason: VerificationFailureReason.SEND_MESSAGE_DISABLED};
}
+ if (user.reportsAccountTier) {
+ const messageGate = accountGateStatus(canPerform(user, TierGatedActions.MESSAGE));
+ if (messageGate) return messageGate;
+ }
if (user.id === guild.ownerId) {
return {canAccess: true};
}
@@ -149,14 +161,8 @@ class GuildVerification {
if (member && member.roles.size > 0) {
return {canAccess: true};
}
- if (!user.isClaimed()) {
- return {canAccess: false, reason: VerificationFailureReason.UNCLAIMED_ACCOUNT};
- }
- if (verificationLevel >= GuildVerificationLevel.LOW) {
- if (!user.verified) {
- return {canAccess: false, reason: VerificationFailureReason.UNVERIFIED_EMAIL};
- }
- }
+ const verificationGate = accountGateStatus(canPerform(user, TierGatedActions.GUILD_VERIFICATION));
+ if (verificationGate) return verificationGate;
if (verificationLevel >= GuildVerificationLevel.MEDIUM) {
const verificationEndsAt = user.createdAt.getTime() + FIVE_MINUTES_MS;
if (verificationEndsAt > now) {
diff --git a/fluxer_app/src/features/messaging/commands/ReactionCommands.tsx b/fluxer_app/src/features/messaging/commands/ReactionCommands.tsx
index 90503fbfa..d8b2bfcd0 100644
--- a/fluxer_app/src/features/messaging/commands/ReactionCommands.tsx
+++ b/fluxer_app/src/features/messaging/commands/ReactionCommands.tsx
@@ -6,6 +6,7 @@ import {FeatureTemporarilyDisabledModal} from '@app/features/app/components/aler
import {showGenericErrorModal} from '@app/features/app/components/alerts/GenericErrorModalCommands';
import {Endpoints} from '@app/features/app/constants/Endpoints';
import Authentication from '@app/features/auth/state/Authentication';
+import {promptForAccountTier} from '@app/features/auth/utils/AccountTierPrompt';
import ForumPosts from '@app/features/forum/state/ForumPosts';
import GatewaySessions from '@app/features/gateway/transport/GatewaySessionPool';
import MessageReactions from '@app/features/messaging/state/MessageReactions';
@@ -58,6 +59,9 @@ type ReactionOptimisticType =
const checkReactionResponse = (i18n: I18n, error: HttpError): boolean => {
const errorCode = failureCode(error);
+ if (promptForAccountTier(error)) {
+ return true;
+ }
if (error.status === 403) {
if (errorCode === APIErrorCodes.FEATURE_TEMPORARILY_DISABLED) {
logger.debug('Feature temporarily disabled, not retrying');
diff --git a/fluxer_app/src/features/messaging/state/MessageQueue.tsx b/fluxer_app/src/features/messaging/state/MessageQueue.tsx
index 0354879f9..318ce47de 100644
--- a/fluxer_app/src/features/messaging/state/MessageQueue.tsx
+++ b/fluxer_app/src/features/messaging/state/MessageQueue.tsx
@@ -5,6 +5,7 @@ import {showDmActionErrorModal} from '@app/features/app/components/alerts/DmActi
import {FeatureTemporarilyDisabledModal} from '@app/features/app/components/alerts/FeatureTemporarilyDisabledModal';
import {Endpoints} from '@app/features/app/constants/Endpoints';
import RuntimeConfig from '@app/features/app/state/RuntimeConfig';
+import {describeAccountTierBlock, promptForAccountTier} from '@app/features/auth/utils/AccountTierPrompt';
import DeveloperOptions from '@app/features/devtools/state/DeveloperOptions';
import {createSystemMessage} from '@app/features/devtools/utils/CommandUtils';
import * as DraftCommands from '@app/features/messaging/commands/DraftCommands';
@@ -55,6 +56,7 @@ import * as ModalCommands from '@app/features/ui/commands/ModalCommands';
import {modal} from '@app/features/ui/commands/ModalCommands';
import {formatUserSettingsPath} from '@app/features/user/components/settings_utils/SettingsConstants';
import PrivacyPreferences from '@app/features/user/state/PrivacyPreferences';
+import {accountGateReason} from '@app/features/user/utils/AccountGatePresentation';
import {Queue} from '@app/lib/list/ListQueue';
import {APIErrorCodes} from '@fluxer/constants/src/ApiErrorCodes';
import type {
@@ -125,23 +127,23 @@ interface SendMessagePayload extends BaseMessagePayload {
tts?: boolean;
}
-export type MessageQueuePayload = SendMessagePayload;
+type MessageQueuePayload = SendMessagePayload;
type MessageQueueCompletion<TResult> = {
retry: RetryError | null;
result?: TResult;
error?: unknown;
};
-export interface RetryError {
+interface RetryError {
retryAfter?: number;
}
-export interface ApiErrorBody {
+interface ApiErrorBody {
code?: number | string;
message?: string;
}
-export interface PreparedSendAttachments {
+interface PreparedSendAttachments {
attachments?: Array<ApiAttachmentMetadata>;
files?: Array<File>;
}
@@ -251,7 +253,7 @@ class PresignedUploadFallbackUnavailableError extends Error {
}
}
-export class MessageQueue extends Queue<MessageQueuePayload, RestResponse<Message> | undefined> {
+class MessageQueue extends Queue<MessageQueuePayload, RestResponse<Message> | undefined> {
private readonly maxSize: number;
private readonly abortControllers = new Map<string, AbortController>();
private readonly textareaAttachmentUploads = new Map<number, TextareaAttachmentUpload>();
@@ -1062,6 +1064,12 @@ export class MessageQueue extends Queue<MessageQueuePayload, RestResponse<Messag
MessageCommands.createOptimistic(channelId, systemMessage.toJSON());
return;
}
+ const tierBlock = describeAccountTierBlock(error);
+ if (tierBlock !== null && promptForAccountTier(error)) {
+ const tierMessage = accountGateReason(i18n, tierBlock);
+ MessageCommands.createOptimistic(channelId, createSystemMessage(channelId, tierMessage).toJSON());
+ return;
+ }
const unclaimedErrorCode = getUnclaimedAccountErrorCode(error);
if (unclaimedErrorCode) {
const systemMessage = createSystemMessage(
diff --git a/fluxer_app/src/features/moderation/components/report_flow/ReportFlowCopy.ts b/fluxer_app/src/features/moderation/components/report_flow/ReportFlowCopy.ts
index 37cfb48ae..f56416e46 100644
--- a/fluxer_app/src/features/moderation/components/report_flow/ReportFlowCopy.ts
+++ b/fluxer_app/src/features/moderation/components/report_flow/ReportFlowCopy.ts
@@ -113,15 +113,6 @@ export const FINISH_ACCOUNT_SETUP_FIRST_DESCRIPTOR = msg({
message: 'Finish account setup first',
comment: 'Report flow: title of the notice on the summary screen when the account cannot send reports yet.',
});
-export const CLAIM_AND_VERIFY_TO_REPORT_DESCRIPTOR = msg({
- message: 'Claim your account and verify your email to send reports.',
- comment: 'Report flow: body of the notice on the summary screen when the account cannot send reports yet.',
-});
-export const CLAIM_TO_REPORT_DESCRIPTOR = msg({
- message: 'Claim your account to send reports.',
- comment:
- 'Report flow: body of the notice on the summary screen when the account cannot send reports yet, on an instance where people sign in with a username.',
-});
export const FINISH_ACCOUNT_SETUP_DESCRIPTOR = msg({
message: 'Finish account setup',
comment: 'Report flow: button in the account notice that opens the account setup screen.',
diff --git a/fluxer_app/src/features/moderation/components/report_flow/ReportFlowModal.tsx b/fluxer_app/src/features/moderation/components/report_flow/ReportFlowModal.tsx
index 194e92790..9d0420749 100644
--- a/fluxer_app/src/features/moderation/components/report_flow/ReportFlowModal.tsx
+++ b/fluxer_app/src/features/moderation/components/report_flow/ReportFlowModal.tsx
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
import * as Modal from '@app/features/app/components/dialogs/Modal';
-import RuntimeConfig from '@app/features/app/state/RuntimeConfig';
import Authentication from '@app/features/auth/state/Authentication';
import Channels from '@app/features/channel/state/Channels';
import {
@@ -18,8 +17,6 @@ import {type ReportFlowSubmissionTarget, submitReportFlow} from '@app/features/m
import {
ALREADY_REPORTED_MESSAGE_DESCRIPTOR,
ALREADY_REPORTED_PROFILE_DESCRIPTOR,
- CLAIM_AND_VERIFY_TO_REPORT_DESCRIPTOR,
- CLAIM_TO_REPORT_DESCRIPTOR,
FINISH_ACCOUNT_SETUP_DESCRIPTOR,
FINISH_ACCOUNT_SETUP_FIRST_DESCRIPTOR,
FLOW_OUTDATED_DESCRIPTOR,
@@ -61,7 +58,7 @@ import {
} from '@app/features/moderation/components/report_flow/ReportFlowWalk';
import ReportFlows from '@app/features/moderation/state/ReportFlows';
import {REPORT_USER_PROFILE_DESCRIPTOR} from '@app/features/moderation/utils/ModerationMessageDescriptors';
-import {canSubmitReport, showReportRestrictionDialog} from '@app/features/moderation/utils/ReportVerificationGate';
+import {reportGate, showReportRestrictionDialog} from '@app/features/moderation/utils/ReportVerificationGate';
import {HttpError} from '@app/features/platform/types/EndpointError';
import {failureCode, failureMessage} from '@app/features/platform/utils/ResponseInspection';
import Relationships from '@app/features/relationship/state/Relationships';
@@ -72,6 +69,7 @@ import {Spinner} from '@app/features/ui/components/Spinner';
import {SteppedCarousel} from '@app/features/ui/stepped_carousel/SteppedCarousel';
import {openExternalUrl} from '@app/features/ui/utils/NativeUtils';
import type {User} from '@app/features/user/models/User';
+import {accountGateReason} from '@app/features/user/utils/AccountGatePresentation';
import {APIErrorCodes} from '@fluxer/constants/src/ApiErrorCodes';
import {HttpStatus} from '@fluxer/constants/src/HttpConstants';
import type {ReportFlowOption, ReportFlowResponse} from '@fluxer/schema/src/domains/report/ReportFlowSchemas';
@@ -144,6 +142,12 @@ function getContextGuildId(context: ReportFlowContext): string | null | undefine
return Channels.getChannel(context.message.channelId)?.guildId ?? context.message.guildId;
}
+const REPORT_TIER_CODES: ReadonlySet<string> = new Set([
+ APIErrorCodes.ACCOUNT_VERIFICATION_REQUIRED,
+ APIErrorCodes.REPORT_EMAIL_VERIFICATION_REQUIRED,
+ APIErrorCodes.UNCLAIMED_ACCOUNT_CANNOT_SUBMIT_REPORTS,
+]);
+
function isTerminalSubmitFailure(code: string | undefined): boolean {
return (
code === APIErrorCodes.CONFLICT ||
@@ -168,6 +172,7 @@ function describeSubmitFailure(i18n: I18n, context: ReportFlowContext, error: un
}
if (
code === APIErrorCodes.REPORT_BANNED ||
+ (code !== undefined && REPORT_TIER_CODES.has(code)) ||
code === APIErrorCodes.UNKNOWN_MESSAGE ||
code === APIErrorCodes.UNKNOWN_USER ||
code?.startsWith('CANNOT_REPORT_')
@@ -214,7 +219,7 @@ export const ReportFlowModal: React.FC<ReportFlowModalProps> = observer(({contex
const user = getReportedUser(context);
return user !== null && !Relationships.isBlocked(user.id) ? user : null;
});
- const accountReady = canSubmitReport();
+ const accountGate = reportGate();
if (loadState?.status === 'loaded' && session?.flow !== loadState.flow) {
const keepWalk = session !== null && session.flow.revision_hash === loadState.flow.revision_hash;
setSession({
@@ -286,10 +291,7 @@ export const ReportFlowModal: React.FC<ReportFlowModalProps> = observer(({contex
}, [targetType, locale]);
const handleSubmit = useCallback(async () => {
if (session === null || session.walk.phase !== 'summary') return;
- if (!canSubmitReport()) {
- showReportRestrictionDialog();
- return;
- }
+ if (showReportRestrictionDialog()) return;
setSubmitting(true);
setSubmitNote(null);
const submission = submitReportFlow(toSubmissionTarget(context), session.flow, session.walk.steps);
@@ -306,13 +308,7 @@ export const ReportFlowModal: React.FC<ReportFlowModalProps> = observer(({contex
void ReportFlows.restart(targetType, SURFACE, locale);
return;
}
- if (
- code === APIErrorCodes.REPORT_EMAIL_VERIFICATION_REQUIRED ||
- code === APIErrorCodes.UNCLAIMED_ACCOUNT_CANNOT_SUBMIT_REPORTS
- ) {
- showReportRestrictionDialog();
- return;
- }
+ if (code !== undefined && REPORT_TIER_CODES.has(code) && showReportRestrictionDialog()) return;
setSubmitClosed(isTerminalSubmitFailure(code));
setSubmitNote(describeSubmitFailure(i18n, context, error));
} finally {
@@ -410,7 +406,7 @@ export const ReportFlowModal: React.FC<ReportFlowModalProps> = observer(({contex
preview={preview}
data-flx="moderation.report-flow.report-flow-modal.render-body.report-flow-summary"
/>
- {!accountReady && (
+ {!accountGate.allowed && (
<div
className={styles.accountNotice}
data-flx="moderation.report-flow.report-flow-modal.render-body.account-notice"
@@ -425,11 +421,7 @@ export const ReportFlowModal: React.FC<ReportFlowModalProps> = observer(({contex
className={styles.accountNoticeText}
data-flx="moderation.report-flow.report-flow-modal.render-body.account-notice-text"
>
- {i18n._(
- RuntimeConfig.usesUsernameSignIn
- ? CLAIM_TO_REPORT_DESCRIPTOR
- : CLAIM_AND_VERIFY_TO_REPORT_DESCRIPTOR,
- )}
+ {accountGateReason(i18n, accountGate)}
</span>
<div
className={styles.accountNoticeActions}
@@ -564,7 +556,7 @@ export const ReportFlowModal: React.FC<ReportFlowModalProps> = observer(({contex
variant="danger"
onClick={handleSubmit}
submitting={submitting || walk?.phase === 'thanks'}
- disabled={!accountReady}
+ disabled={!accountGate.allowed}
data-flx="moderation.report-flow.report-flow-modal.render-footer.button.submit"
>
{i18n._(SUBMIT_REPORT_DESCRIPTOR)}
@@ -575,17 +567,10 @@ export const ReportFlowModal: React.FC<ReportFlowModalProps> = observer(({contex
case 'notice':
case 'thanks':
return (
- <Modal.Footer
- stretchButtons
- data-flx="moderation.report-flow.report-flow-modal.render-footer.modal-footer--4"
- >
- <Button
- onClick={closeModal}
- data-flx="moderation.report-flow.report-flow-modal.render-footer.button.close-modal--2"
- >
- {i18n._(DONE_DESCRIPTOR)}
- </Button>
- </Modal.Footer>
+ <Modal.DismissFooter
+ label={i18n._(DONE_DESCRIPTOR)}
+ data-flx="moderation.report-flow.report-flow-modal.render-footer.dismiss-footer"
+ />
);
}
};
diff --git a/fluxer_app/src/features/moderation/utils/ReportVerificationGate.tsx b/fluxer_app/src/features/moderation/utils/ReportVerificationGate.tsx
index c160ccc7b..4ad30d774 100644
--- a/fluxer_app/src/features/moderation/utils/ReportVerificationGate.tsx
+++ b/fluxer_app/src/features/moderation/utils/ReportVerificationGate.tsx
@@ -2,36 +2,35 @@
import {UserSettingsModal} from '@app/features/app/components/dialogs/LoadableSettingsModals';
import {openClaimAccountModal} from '@app/features/auth/components/modals/ClaimAccountModal';
+import {promptForAccountGate} from '@app/features/auth/utils/AccountTierPrompt';
import * as ModalCommands from '@app/features/ui/commands/ModalCommands';
import {modal} from '@app/features/ui/commands/ModalCommands';
import Users from '@app/features/user/state/Users';
+import {type AccountGateResult, canPerform} from '@app/features/user/utils/AccountGates';
+import {AccountTiers, TierGatedActions} from '@fluxer/constants/src/AccountTierConstants';
-export function canSubmitReport(): boolean {
- const user = Users.currentUser;
- if (!user) return false;
- if (!user.isClaimed()) return false;
- if (!user.verified) return false;
- return true;
+export function reportGate(): AccountGateResult {
+ return canPerform(Users.currentUser, TierGatedActions.REPORT);
}
-export function showReportRestrictionDialog(): void {
- const user = Users.currentUser;
- if (!user) return;
- if (!user.isClaimed()) {
- openClaimAccountModal({force: true});
- return;
+export function showReportRestrictionDialog(): boolean {
+ const gate = reportGate();
+ if (gate.allowed) return false;
+ if (promptForAccountGate(gate)) return true;
+ if (gate.tier === AccountTiers.UNCLAIMED) {
+ openClaimAccountModal();
+ return true;
}
- if (!user.verified) {
- ModalCommands.push(
- modal(
- () => (
- <UserSettingsModal
- initialTab="account_security"
- data-flx="moderation.report-verification-gate.show-report-restriction-dialog.user-settings-modal"
- />
- ),
- 'user-settings',
+ ModalCommands.push(
+ modal(
+ () => (
+ <UserSettingsModal
+ initialTab="account_security"
+ data-flx="moderation.report-verification-gate.show-report-restriction-dialog.user-settings-modal"
+ />
),
- );
- }
+ 'user-settings',
+ ),
+ );
+ return true;
}