Skip to content

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

TypeScript fluxerfluxerapp

feat(app): read verification config, drop card age check

Hampusc656ca917698
diff --git a/fluxer_app/src/features/app/state/InstanceSnapshotStore.ts b/fluxer_app/src/features/app/state/InstanceSnapshotStore.ts
index 43eb8ebdb..65e03b9da 100644
--- a/fluxer_app/src/features/app/state/InstanceSnapshotStore.ts
+++ b/fluxer_app/src/features/app/state/InstanceSnapshotStore.ts
@@ -119,6 +119,7 @@ export function runtimeSnapshotFromDiscovery(document: InstanceDiscoveryDocument
appPublic: discovery.appPublic,
agePolicy: discovery.agePolicy,
domainMigration: discovery.domainMigration,
+ notice: discovery.notice ?? null,
});
}
@@ -156,9 +157,15 @@ function sameOriginApiEndpoint(origin: string): string {
return `${origin}${SAME_ORIGIN_API_PATH}`;
}
-function adoptsDocumentOrigin(apiEndpoint: string): boolean {
+function adoptsDocumentOrigin(apiEndpoint: string): boolean | 'when-api-routed' {
const origin = browserDocumentOrigin();
- return origin !== null && documentServesItsOwnApi() && apiEndpoint === sameOriginApiEndpoint(origin);
+ if (origin === null) {
+ return false;
+ }
+ if (documentServesItsOwnApi() && apiEndpoint === sameOriginApiEndpoint(origin)) {
+ return true;
+ }
+ return apiEndpoint === normalizeInstanceEndpoint(origin, InstanceEndpointKind.API) ? 'when-api-routed' : false;
}
export function resolveDiscoveryApiEndpoint(input: string): string {
diff --git a/fluxer_app/src/features/app/state/RuntimeConfig.ts b/fluxer_app/src/features/app/state/RuntimeConfig.ts
index 9e91aa9bb..ee7d09f2e 100644
--- a/fluxer_app/src/features/app/state/RuntimeConfig.ts
+++ b/fluxer_app/src/features/app/state/RuntimeConfig.ts
@@ -30,11 +30,23 @@ import {discoveryEnabledOf, isDiscoveryAvailable} from '@app/features/app/utils/
import DeveloperOptions from '@app/features/devtools/state/DeveloperOptions';
import {Logger} from '@app/features/platform/utils/AppLogger';
import {getElectronAPI} from '@app/features/ui/utils/NativeUtils';
+import {
+ type EffectiveVerificationBasis,
+ type EmailCodeAvailability,
+ type EmailDeliveryState,
+ EmailDeliveryStates,
+ type GuildJoinGate,
+ GuildJoinGates,
+ type InteractionTierMode,
+ InteractionTierModes,
+ VerificationBases,
+} from '@fluxer/constants/src/AccountConfigConstants';
import {
type AccountIdentityMode,
AccountIdentityModes,
type TagStyle,
} from '@fluxer/constants/src/AccountIdentityConstants';
+import {resolveEffectiveVerificationBasis, resolveEmailCodeAvailability} from '@fluxer/constants/src/AccountTierRules';
import {API_CODE_VERSION} from '@fluxer/constants/src/AppConstants';
import {InstanceDiscoveryUnreachableError} from '@fluxer/instance_bootstrap/src/Discovery';
import {InstanceEndpointKind, normalizeInstanceEndpoint} from '@fluxer/instance_bootstrap/src/EndpointNormalization';
@@ -43,6 +55,7 @@ import type {
InstanceAppPublic,
InstanceCommunity,
InstanceFeatures,
+ InstanceNotice,
InstanceServices,
InstanceSso as InstanceSsoConfig,
} from '@fluxer/instance_bootstrap/src/Types';
@@ -52,13 +65,39 @@ import {makeAutoObservable, observableRef} from 'mobx';
const logger = new Logger('RuntimeConfig');
+function emailFeaturesForIdentity(
+ mode: AccountIdentityMode,
+ features: InstanceFeatures,
+): Pick<
+ InstanceFeatures,
+ 'emails_enabled' | 'email_delivery_state' | 'verification_basis' | 'identifier_first' | 'email_codes'
+> {
+ if (mode !== AccountIdentityModes.USERNAME) {
+ const wasUsernameMode = features.email_delivery_state === EmailDeliveryStates.OFF_USERNAME_MODE;
+ return {
+ emails_enabled: features.emails_enabled,
+ email_delivery_state: wasUsernameMode ? undefined : features.email_delivery_state,
+ verification_basis: wasUsernameMode ? undefined : features.verification_basis,
+ ...(features.identifier_first === undefined ? {} : {identifier_first: features.identifier_first}),
+ ...(features.email_codes === undefined ? {} : {email_codes: features.email_codes}),
+ };
+ }
+ return {
+ identifier_first: false,
+ email_codes: false,
+ emails_enabled: false,
+ email_delivery_state: EmailDeliveryStates.OFF_USERNAME_MODE,
+ verification_basis: VerificationBases.LOCAL_CREDENTIAL,
+ };
+}
+
export {
runtimeConfigSnapshotsAreSameInstance,
runtimeInstanceKey,
} from '@app/features/app/state/InstanceSnapshotStore';
export type {InstanceSsoConfig, RuntimeConfigSnapshot};
-export interface ApplyRuntimeConfigSnapshotRequest {
+interface ApplyRuntimeConfigSnapshotRequest {
snapshot: RuntimeConfigSnapshot;
signal: AbortSignal | null;
}
@@ -625,9 +664,9 @@ class RuntimeConfig {
const current = this.requireActiveSnapshot();
this.replaceActiveFeatures({
...current.features,
+ ...emailFeaturesForIdentity(mode, current.features),
account_identity: mode,
tag_style: tagStyle,
- emails_enabled: mode === AccountIdentityModes.USERNAME ? false : current.features.emails_enabled,
});
}
@@ -642,6 +681,7 @@ class RuntimeConfig {
...runtime.snapshot,
features: resolution.snapshot.features,
appPublic: resolution.snapshot.appPublic,
+ notice: resolution.snapshot.notice,
});
this.activeRuntime = {...runtime, snapshot: usable};
this.lifecycleGeneration = nextLifecycleGeneration(this.lifecycleGeneration);
@@ -682,10 +722,9 @@ class RuntimeConfig {
premium_enabled: !config.self_hosted || config.policy.premium_mode === 'mirror',
stripe_enabled: config.billing.billing_active,
stripe_serviceable: config.billing.stripe_serviceable,
+ ...emailFeaturesForIdentity(config.account_identity.mode, current.features),
account_identity: config.account_identity.mode,
tag_style: config.account_identity.tag_style,
- emails_enabled:
- config.account_identity.mode === AccountIdentityModes.USERNAME ? false : current.features.emails_enabled,
},
registration: {
mode: config.registration.mode,
@@ -697,6 +736,7 @@ class RuntimeConfig {
? config.policy.single_community_guild_id
: null,
direct_messages_disabled: config.policy.direct_messages_disabled,
+ friends_disabled: config.policy.friends_disabled,
guild_create_access: config.policy.guild_create_access,
},
services: {
@@ -705,6 +745,7 @@ class RuntimeConfig {
bluesky_enabled: config.policy.services_resolved.bluesky_enabled,
},
appPublic,
+ notice: config.notice,
};
const usable = this.requireUsableSnapshot(snapshot);
const runtime = this.requireActiveRuntime();
@@ -747,10 +788,6 @@ class RuntimeConfig {
return this.features.stripe_serviceable;
}
- get premiumInfoUrl(): string | null {
- return this.appPublic.branding.premium_info_url ?? null;
- }
-
get emailsEnabled(): boolean {
return this.features.emails_enabled;
}
@@ -767,44 +804,54 @@ class RuntimeConfig {
return accountIdentityOf(this.features);
}
- get usesUsernameSignIn(): boolean {
- return usesUsernameSignIn(this.features);
+ get emailDeliveryState(): EmailDeliveryState {
+ if (this.features.email_delivery_state !== undefined) return this.features.email_delivery_state;
+ if (this.usesUsernameSignIn) return EmailDeliveryStates.OFF_USERNAME_MODE;
+ return this.emailsEnabled ? EmailDeliveryStates.ON : EmailDeliveryStates.OFF_DISABLED;
}
- get tagStyle(): TagStyle {
- return tagStyleOf(this.features);
+ get verificationBasis(): EffectiveVerificationBasis {
+ return (
+ this.features.verification_basis ??
+ resolveEffectiveVerificationBasis({
+ identityMode: this.accountIdentity,
+ basis: VerificationBases.AUTO,
+ deliveryState: this.emailDeliveryState,
+ })
+ );
}
- get usesUniqueUsernames(): boolean {
- return usesUniqueUsernames(this.features);
+ get interactionTier(): InteractionTierMode {
+ return this.features.interaction_tier ?? InteractionTierModes.LEGACY;
}
- get productName(): string {
- return this.appPublic.branding.product_name;
+ get guildJoinGate(): GuildJoinGate {
+ return this.features.guild_join_gate ?? GuildJoinGates.ALWAYS;
}
- get iconUrl(): string | null {
- return this.appPublic.branding.icon_url;
- }
-
- get symbolUrl(): string | null {
- return this.appPublic.branding.symbol_url;
+ emailCodeAvailabilityFor(account: {hasEmail: boolean; emailVerified: boolean}): EmailCodeAvailability {
+ return resolveEmailCodeAvailability({
+ identityMode: this.accountIdentity,
+ deliveryState: this.emailDeliveryState,
+ hasEmail: account.hasEmail,
+ emailVerified: account.emailVerified,
+ });
}
- get logoUrl(): string | null {
- return this.appPublic.branding.logo_url;
+ get usesUsernameSignIn(): boolean {
+ return usesUsernameSignIn(this.features);
}
- get wordmarkUrl(): string | null {
- return this.appPublic.branding.wordmark_url;
+ get tagStyle(): TagStyle {
+ return tagStyleOf(this.features);
}
- get faviconUrl(): string | null {
- return this.appPublic.branding.favicon_url;
+ get usesUniqueUsernames(): boolean {
+ return usesUniqueUsernames(this.features);
}
- get themeColor(): string | null {
- return this.appPublic.branding.theme_color;
+ get productName(): string {
+ return this.appPublic.branding.product_name;
}
get termsUrl(): string | null {
@@ -841,6 +888,18 @@ class RuntimeConfig {
return this.community.direct_messages_disabled;
}
+ get friendsDisabled(): boolean {
+ return this.community.friends_disabled ?? this.community.direct_messages_disabled;
+ }
+
+ get dmPickerAvailable(): boolean {
+ return !this.directMessagesDisabled && !this.friendsDisabled;
+ }
+
+ get instanceNotice(): InstanceNotice | null {
+ return this.activeRuntime?.snapshot.notice ?? null;
+ }
+
get gifEnabled(): boolean {
return this.services.gif_enabled;
}
diff --git a/fluxer_app/src/features/app/state/RuntimeConfigSnapshot.ts b/fluxer_app/src/features/app/state/RuntimeConfigSnapshot.ts
index 38f50079f..a9147d816 100644
--- a/fluxer_app/src/features/app/state/RuntimeConfigSnapshot.ts
+++ b/fluxer_app/src/features/app/state/RuntimeConfigSnapshot.ts
@@ -1,15 +1,25 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
import type {GifProvider} from '@app/features/app/state/GifProviderConfig';
-import {AccountIdentityModes, TagStyles} from '@fluxer/constants/src/AccountIdentityConstants';
+import {
+ EmailDeliveryStates,
+ GuildJoinGates,
+ InstantAccountAvailability,
+ InteractionTierModes,
+ VerificationBases,
+} from '@fluxer/constants/src/AccountConfigConstants';
+import {
+ type AccountIdentityLockReason,
+ AccountIdentityLockReasons,
+ AccountIdentityModes,
+ TagStyles,
+} from '@fluxer/constants/src/AccountIdentityConstants';
import {LIMIT_KEYS, type LimitKey} from '@fluxer/constants/src/LimitConfigMetadata';
import {
ACCOUNT_DELETION_GRACE_PERIOD_HOURS_MAX,
ACCOUNT_DELETION_GRACE_PERIOD_HOURS_MIN,
AGE_POLICY_GEOS_MAX,
LIMIT_RULES_MAX,
- MAX_BACKGROUND_GATEWAY_CONNECTIONS_MAX,
- MAX_BACKGROUND_GATEWAY_CONNECTIONS_MIN,
parseInstanceDomainMigration,
} from '@fluxer/instance_bootstrap/src/Discovery';
import {InstanceEndpointKind, normalizeInstanceEndpoint} from '@fluxer/instance_bootstrap/src/EndpointNormalization';
@@ -23,6 +33,7 @@ import {
type InstanceCommunity,
type InstanceDomainMigration,
type InstanceFeatures,
+ type InstanceNotice,
type InstanceRegistration,
type InstanceServices,
type InstanceSso,
@@ -62,6 +73,7 @@ export interface RuntimeConfigSnapshot extends RuntimeConfigIdentity {
readonly appPublic: InstanceAppPublic;
readonly agePolicy: InstanceAgePolicy | null;
readonly domainMigration: InstanceDomainMigration | null;
+ readonly notice: InstanceNotice | null;
}
export class InvalidRuntimeConfigSnapshotError extends Error {
@@ -173,6 +185,15 @@ function readLiteral<TValue extends string>(
return matched;
}
+function readKnownLiteral<TValue extends string>(
+ source: Record<string, unknown>,
+ key: string,
+ values: Record<string, TValue>,
+): TValue | undefined {
+ const value = source[key];
+ return Object.values(values).find((candidate) => candidate === value);
+}
+
function readEndpoint(source: Record<string, unknown>, key: string, path: string, kind: InstanceEndpointKind): string {
const normalized = normalizeInstanceEndpoint(source[key], kind);
if (normalized === null || normalized.startsWith('/')) {
@@ -247,9 +268,17 @@ function readFeatures(value: unknown): InstanceFeatures {
if (desktopModulesEnabled !== undefined) {
features.desktop_modules_enabled = desktopModulesEnabled;
}
- const discoveryEnabled = readOptionalBoolean(source, 'discovery_enabled', 'features.discovery_enabled');
- if (discoveryEnabled !== undefined) {
- features.discovery_enabled = discoveryEnabled;
+ for (const key of [
+ 'identifier_first',
+ 'instant_accounts',
+ 'email_codes',
+ 'date_of_birth_step',
+ 'discovery_enabled',
+ ] as const) {
+ const value = readOptionalBoolean(source, key, `features.${key}`);
+ if (value !== undefined) {
+ features[key] = value;
+ }
}
const deletionGracePeriod = readOptionalBoundedInteger(
source,
@@ -272,16 +301,23 @@ function readFeatures(value: unknown): InstanceFeatures {
if (source.tag_style !== undefined) {
features.tag_style = readLiteral(source, 'tag_style', 'features.tag_style', Object.values(TagStyles));
}
- const maxBackgroundConnections = readOptionalBoundedInteger(
+ const instantAccountAvailability = readKnownLiteral(
source,
- 'max_background_gateway_connections',
- 'features.max_background_gateway_connections',
- MAX_BACKGROUND_GATEWAY_CONNECTIONS_MIN,
- MAX_BACKGROUND_GATEWAY_CONNECTIONS_MAX,
+ 'instant_account_availability',
+ InstantAccountAvailability,
);
- if (maxBackgroundConnections !== undefined) {
- features.max_background_gateway_connections = maxBackgroundConnections;
- }
+ if (instantAccountAvailability !== undefined) features.instant_account_availability = instantAccountAvailability;
+ const interactionTier = readKnownLiteral(source, 'interaction_tier', InteractionTierModes);
+ if (interactionTier !== undefined) features.interaction_tier = interactionTier;
+ const guildJoinGate = readKnownLiteral(source, 'guild_join_gate', GuildJoinGates);
+ if (guildJoinGate !== undefined) features.guild_join_gate = guildJoinGate;
+ const emailDeliveryState = readKnownLiteral(source, 'email_delivery_state', EmailDeliveryStates);
+ if (emailDeliveryState !== undefined) features.email_delivery_state = emailDeliveryState;
+ const verificationBasis = readKnownLiteral(source, 'verification_basis', {
+ CONFIRMED_EMAIL: VerificationBases.CONFIRMED_EMAIL,
+ LOCAL_CREDENTIAL: VerificationBases.LOCAL_CREDENTIAL,
+ });
+ if (verificationBasis !== undefined) features.verification_basis = verificationBasis;
return features;
}
@@ -294,6 +330,7 @@ function readSso(value: unknown): InstanceSso | null {
enabled: readBoolean(source, 'enabled', 'sso.enabled'),
enforced: readBoolean(source, 'enforced', 'sso.enforced'),
display_name: readNullableNonEmptyString(source, 'display_name', 'sso.display_name'),
+ button_label: readOptionalText(source, 'button_label'),
redirect_uri: readEndpoint(source, 'redirect_uri', 'sso.redirect_uri', InstanceEndpointKind.SERVICE),
};
const available = readOptionalBoolean(source, 'available', 'sso.available');
@@ -317,7 +354,7 @@ function readRegistration(value: unknown): InstanceRegistration {
function readCommunity(value: unknown): InstanceCommunity {
const source = readRecord(value, 'community');
- return {
+ const community: InstanceCommunity = {
single_community: readBoolean(source, 'single_community', 'community.single_community'),
single_community_guild_id: readNullableNonEmptyString(
source,
@@ -327,6 +364,11 @@ function readCommunity(value: unknown): InstanceCommunity {
direct_messages_disabled: readBoolean(source, 'direct_messages_disabled', 'community.direct_messages_disabled'),
guild_create_access: readOptionalBoolean(source, 'guild_create_access', 'community.guild_create_access') ?? true,
};
+ const friendsDisabled = readOptionalBoolean(source, 'friends_disabled', 'community.friends_disabled');
+ if (friendsDisabled !== undefined) {
+ community.friends_disabled = friendsDisabled;
+ }
+ return community;
}
function readServices(value: unknown): InstanceServices {
@@ -398,6 +440,14 @@ function readLimits(value: unknown): LimitConfigSnapshot {
return snapshot;
}
+function readOptionalLockReason(source: Record<string, unknown>): AccountIdentityLockReason | null | undefined {
+ if (!Object.hasOwn(source, 'account_identity_lock_reason')) {
+ return undefined;
+ }
+ const value = source.account_identity_lock_reason;
+ return Object.values(AccountIdentityLockReasons).find((reason) => reason === value) ?? null;
+}
+
function readAppPublic(value: unknown): InstanceAppPublic {
const source = readRecord(value, 'appPublic');
const branding = readRecord(source.branding, 'appPublic.branding');
@@ -410,6 +460,7 @@ function readAppPublic(value: unknown): InstanceAppPublic {
'appPublic.setup.account_identity_locked',
);
const setupTokenRequired = readOptionalBoolean(setup, 'setup_token_required', 'appPublic.setup.setup_token_required');
+ const accountIdentityLockReason = readOptionalLockReason(setup);
return {
branding: {
product_name: readNonEmptyString(branding, 'product_name', 'appPublic.branding.product_name'),
@@ -418,6 +469,9 @@ function readAppPublic(value: unknown): InstanceAppPublic {
logo_url: readNullableAbsoluteHttpUrl(branding, 'logo_url', 'appPublic.branding.logo_url'),
wordmark_url: readNullableAbsoluteHttpUrl(branding, 'wordmark_url', 'appPublic.branding.wordmark_url'),
favicon_url: readNullableAbsoluteHttpUrl(branding, 'favicon_url', 'appPublic.branding.favicon_url'),
+ favicon_dark_url: Object.hasOwn(branding, 'favicon_dark_url')
+ ? readNullableAbsoluteHttpUrl(branding, 'favicon_dark_url', 'appPublic.branding.favicon_dark_url')
+ : null,
theme_color: normalizeThemeColor(branding.theme_color),
status_page_url: readOptionalText(branding, 'status_page_url'),
status_page_incident_history_url: readOptionalText(branding, 'status_page_incident_history_url'),
@@ -425,11 +479,17 @@ function readAppPublic(value: unknown): InstanceAppPublic {
premium_info_url: Object.hasOwn(branding, 'premium_info_url')
? readNullableAbsoluteHttpUrl(branding, 'premium_info_url', 'appPublic.branding.premium_info_url')
: null,
+ sign_in_backdrop_url: Object.hasOwn(branding, 'sign_in_backdrop_url')
+ ? readNullableAbsoluteHttpUrl(branding, 'sign_in_backdrop_url', 'appPublic.branding.sign_in_backdrop_url')
+ : null,
+ custom_css: readOptionalText(branding, 'custom_css'),
+ upload_limit_message: readOptionalText(branding, 'upload_limit_message'),
},
setup: {
configured: readBoolean(setup, 'configured', 'appPublic.setup.configured'),
admin_url: readNullableAbsoluteHttpUrl(setup, 'admin_url', 'appPublic.setup.admin_url'),
...(accountIdentityLocked === undefined ? {} : {account_identity_locked: accountIdentityLocked}),
+ ...(accountIdentityLockReason === undefined ? {} : {account_identity_lock_reason: accountIdentityLockReason}),
...(setupTokenRequired === undefined ? {} : {setup_token_required: setupTokenRequired}),
},
legal: {
@@ -457,11 +517,6 @@ function readAgePolicyGeo(value: unknown, index: number): InstanceAgePolicyGeo {
country_code: readNonEmptyString(source, 'country_code', `${path}.country_code`),
region_code: readNullableNonEmptyString(source, 'region_code', `${path}.region_code`),
action: readLiteral(source, 'action', `${path}.action`, AGE_POLICY_ACTIONS),
- card_verification_available: readBoolean(
- source,
- 'card_verification_available',
- `${path}.card_verification_available`,
- ),
};
}
@@ -476,6 +531,31 @@ function readAgePolicy(value: unknown): InstanceAgePolicy | null {
return {geos: source.geos.map(readAgePolicyGeo)};
}
+function readNullableDateTime(source: Record<string, unknown>, key: string, path: string): string | null {
+ const value = source[key];
+ if (value === null) {
+ return null;
+ }
+ if (typeof value !== 'string' || !Number.isFinite(Date.parse(value))) {
+ invalid(path, 'must be null or a date-time string');
+ }
+ return value;
+}
+
+function readNotice(value: unknown): InstanceNotice | null {
+ if (value === undefined || value === null) {
+ return null;
+ }
+ const source = readRecord(value, 'notice');
+ return {
+ id: readNonEmptyString(source, 'id', 'notice.id'),
+ message: readNonEmptyString(source, 'message', 'notice.message'),
+ url: readNullableAbsoluteHttpUrl(source, 'url', 'notice.url'),
+ starts_at: readNullableDateTime(source, 'starts_at', 'notice.starts_at'),
+ ends_at: readNullableDateTime(source, 'ends_at', 'notice.ends_at'),
+ };
+}
+
export function requireRuntimeConfigSnapshot(value: unknown): RuntimeConfigSnapshot {
const source = readRecord(value, 'root');
return {
@@ -504,5 +584,6 @@ export function requireRuntimeConfigSnapshot(value: unknown): RuntimeConfigSnaps
appPublic: readAppPublic(source.appPublic),
agePolicy: readAgePolicy(source.agePolicy),
domainMigration: parseInstanceDomainMigration(source.domainMigration),
+ notice: readNotice(source.notice),
};
}