diff --git a/assets/app-icons/ios_icon_testflight.icon/icon.json b/assets/app-icons/ios_icon_testflight.icon/icon.json index f24765661..5b6e8f12d 100644 --- a/assets/app-icons/ios_icon_testflight.icon/icon.json +++ b/assets/app-icons/ios_icon_testflight.icon/icon.json @@ -7,7 +7,7 @@ "layers" : [ { "fill" : "none", - "glass" : false, + "glass" : true, "image-name" : "iOS transparent.png", "name" : "iOS transparent" } @@ -28,4 +28,4 @@ ], "squares" : "shared" } -} +} \ No newline at end of file diff --git a/bskyweb/static/.well-known/assetlinks.json b/bskyweb/static/.well-known/assetlinks.json index bd96aeb05..38dbd9760 100644 --- a/bskyweb/static/.well-known/assetlinks.json +++ b/bskyweb/static/.well-known/assetlinks.json @@ -5,7 +5,10 @@ "namespace": "android_app", "package_name": "community.blacksky.app", "sha256_cert_fingerprints": - ["3C:E4:09:29:B4:37:76:3C:47:AE:A8:5B:52:B2:15:54:CC:6E:24:A8:A3:E0:40:BB:34:FF:46:B4:6A:F3:BF:DD", "2B:21:9F:58:BB:AC:F0:F1:D4:F2:95:82:06:9D:1B:93:56:B3:DA:62:2A:23:EB:10:81:3F:D2:12:40:6B:71:E0"] + ["3C:E4:09:29:B4:37:76:3C:47:AE:A8:5B:52:B2:15:54:CC:6E:24:A8:A3:E0:40:BB:34:FF:46:B4:6A:F3:BF:DD", + "2B:21:9F:58:BB:AC:F0:F1:D4:F2:95:82:06:9D:1B:93:56:B3:DA:62:2A:23:EB:10:81:3F:D2:12:40:6B:71:E0", + "24:1A:0B:2D:D4:CF:EA:21:CC:BD:11:A9:34:19:62:42:51:6A:51:E2:5A:F1:A6:46:98:28:2E:4D:4D:20:CF:EB" + ] } } ] diff --git a/eas.json b/eas.json index 38435f509..da491362e 100644 --- a/eas.json +++ b/eas.json @@ -6,11 +6,7 @@ }, "build": { "base": { - "node": "24.15.0", - "env": { - "EXPO_PUBLIC_POSTHOG_API_KEY": "phc_zKqA8hPzEyjPJsGEyNfBPrGbRSsH9SrhebuHh5cY9EAv", - "EXPO_PUBLIC_POSTHOG_HOST": "https://us.i.posthog.com" - } + "node": "24.15.0" }, "development": { "extends": "base", diff --git a/eslint-suppressions.json b/eslint-suppressions.json index b0a7fcd30..67b851348 100644 --- a/eslint-suppressions.json +++ b/eslint-suppressions.json @@ -1391,11 +1391,6 @@ "count": 1 } }, - "src/screens/Settings/AccountSettings.tsx": { - "@typescript-eslint/no-unused-vars": { - "count": 1 - } - }, "src/screens/Settings/AutomationLabelSettings.tsx": { "@typescript-eslint/no-floating-promises": { "count": 2 diff --git a/src/analytics/metrics/client.test.ts b/src/analytics/metrics/client.test.ts index cd38b6a3e..ffd37b0ef 100644 --- a/src/analytics/metrics/client.test.ts +++ b/src/analytics/metrics/client.test.ts @@ -21,8 +21,7 @@ jest.mock('#/logger', () => ({ })) jest.mock('#/env', () => ({ - POSTHOG_API_KEY: 'phc_test_key', - POSTHOG_HOST: 'https://test.posthog.api', + METRICS_API_HOST: 'https://test.metrics.api', IS_WEB: false, })) @@ -31,17 +30,13 @@ type TestEvents = { view: {screen: string} } +type MetricsBody = { + events: Array<{event: string}> +} + describe('MetricsClient', () => { let fetchMock: jest.Mock - type PostHogBody = { - api_key: string - batch: Array<{ - event: string - distinct_id: string - properties: Record - }> - } - let fetchRequests: {body: PostHogBody}[] + let fetchRequests: {body: MetricsBody}[] beforeEach(() => { jest.useFakeTimers({advanceTimers: true}) @@ -51,7 +46,7 @@ describe('MetricsClient', () => { .mockImplementation(async (_url, options: RequestInit) => { const body = JSON.parse( typeof options.body === 'string' ? options.body : '', - ) as PostHogBody + ) as MetricsBody fetchRequests.push({body}) return {ok: true, status: 200} }) @@ -74,12 +69,9 @@ describe('MetricsClient', () => { await jest.advanceTimersByTimeAsync(10_000) expect(fetchRequests).toHaveLength(1) - expect(fetchRequests[0].body.api_key).toBe('phc_test_key') - expect(fetchRequests[0].body.batch).toHaveLength(2) - expect(fetchRequests[0].body.batch[0].event).toBe('click') - expect(fetchRequests[0].body.batch[0].properties.button).toBe('submit') - expect(fetchRequests[0].body.batch[0].distinct_id).toBeDefined() - expect(fetchRequests[0].body.batch[1].event).toBe('view') + expect(fetchRequests[0].body.events).toHaveLength(2) + expect(fetchRequests[0].body.events[0].event).toBe('click') + expect(fetchRequests[0].body.events[1].event).toBe('view') }) it('flushes when maxBatchSize is exceeded', async () => { @@ -100,7 +92,7 @@ describe('MetricsClient', () => { await jest.advanceTimersByTimeAsync(0) expect(fetchRequests).toHaveLength(1) - expect(fetchRequests[0].body.batch).toHaveLength(6) + expect(fetchRequests[0].body.events).toHaveLength(6) }) it('retries failed events once on 500 response', async () => { @@ -110,7 +102,7 @@ describe('MetricsClient', () => { requestCount++ const body = JSON.parse( typeof options.body === 'string' ? options.body : '', - ) as PostHogBody + ) as MetricsBody if (requestCount === 1) { // First request fails with 500 - "Failed to fetch" triggers isNetworkError @@ -141,8 +133,8 @@ describe('MetricsClient', () => { expect(requestCount).toBe(2) expect(fetchRequests).toHaveLength(1) - expect(fetchRequests[0].body.batch).toHaveLength(1) - expect(fetchRequests[0].body.batch[0].event).toBe('click') + expect(fetchRequests[0].body.events).toHaveLength(1) + expect(fetchRequests[0].body.events[0].event).toBe('click') }) it('does not retry more than once', async () => { diff --git a/src/analytics/metrics/client.ts b/src/analytics/metrics/client.ts index 775bbe8fb..7e6beea0f 100644 --- a/src/analytics/metrics/client.ts +++ b/src/analytics/metrics/client.ts @@ -11,45 +11,9 @@ type Event>> = { metadata: Record } -const TRACKING_ENDPOINT = env.POSTHOG_HOST + '/batch/' +const TRACKING_ENDPOINT = env.METRICS_API_HOST + '/t' const logger = Logger.create(Logger.Context.Metric, {}) -/** - * Transform an internal metrics event into a PostHog capture event. - * - * PostHog requires a `distinct_id` (we key on the device id) and a flat-ish - * `properties` bag. We spread the event payload and metadata into properties, - * hoisting the `base` metadata (deviceId, sessionId, platform, appVersion, ...) - * to the top level so it is queryable in PostHog. - */ -function toPostHogEvent>>( - e: Event, -) { - const metadata = e.metadata ?? {} - const base = - typeof metadata.base === 'object' && metadata.base !== null - ? (metadata.base as Record) - : {} - const distinctId = - typeof base.deviceId === 'string' - ? base.deviceId - : typeof base.sessionId === 'string' - ? base.sessionId - : 'unknown' - return { - event: e.event as string, - distinct_id: distinctId, - timestamp: new Date(e.time).toISOString(), - properties: { - ...e.payload, - ...metadata, - ...base, - distinct_id: distinctId, - source: e.source, - }, - } -} - export class MetricsClient>> { maxBatchSize = 100 @@ -103,16 +67,8 @@ export class MetricsClient>> { } private async sendBatch(events: Event[], isRetry: boolean = false) { - // No API key configured - PostHog reporting is disabled. Drop the batch - // rather than queueing it forever. - if (!env.POSTHOG_API_KEY) return - try { - const body = JSON.stringify({ - api_key: env.POSTHOG_API_KEY, - historical_migration: false, - batch: events.map(toPostHogEvent), - }) + const body = JSON.stringify({events}) if (env.IS_WEB && 'navigator' in globalThis && navigator.sendBeacon) { const success = navigator.sendBeacon( TRACKING_ENDPOINT, diff --git a/src/components/dialogs/BirthDateSettings.tsx b/src/components/dialogs/BirthDateSettings.tsx new file mode 100644 index 000000000..918aae454 --- /dev/null +++ b/src/components/dialogs/BirthDateSettings.tsx @@ -0,0 +1,207 @@ +import {useCallback, useMemo, useState} from 'react' +import {View} from 'react-native' +import {Trans, useLingui} from '@lingui/react/macro' + +import {useCleanError} from '#/lib/hooks/useCleanError' +import {isAppPassword} from '#/lib/jwt' +import {getAge, getDateAgo} from '#/lib/strings/time' +import {logger} from '#/logger' +import { + useBirthdateMutation, + useIsBirthdateUpdateAllowed, +} from '#/state/birthdate' +import { + usePreferencesQuery, + type UsePreferencesQueryResponse, +} from '#/state/queries/preferences' +import {useSession} from '#/state/session' +import {ErrorMessage} from '#/view/com/util/error/ErrorMessage' +import {atoms as a, useTheme, web} from '#/alf' +import {Admonition} from '#/components/Admonition' +import {Button, ButtonIcon, ButtonText} from '#/components/Button' +import * as Dialog from '#/components/Dialog' +import {DateField} from '#/components/forms/DateField' +import {SimpleInlineLinkText} from '#/components/Link' +import {Loader} from '#/components/Loader' +import {Span, Text} from '#/components/Typography' +import {IS_IOS, IS_WEB} from '#/env' + +export function BirthDateSettingsDialog({ + control, +}: { + control: Dialog.DialogControlProps +}) { + const t = useTheme() + const {t: l} = useLingui() + const {isLoading, error, data: preferences} = usePreferencesQuery() + const isBirthdateUpdateAllowed = useIsBirthdateUpdateAllowed() + const {currentAccount} = useSession() + const isUsingAppPassword = isAppPassword(currentAccount?.accessJwt || '') + const cleanError = useCleanError() + const defaultErrorMessage = l`We were unable to load your birthdate preferences. Please try again.` + const fetchErrorMessage = useMemo(() => { + if (error) { + const {raw, clean} = cleanError(error) + return clean || raw + } + }, [error, cleanError]) + + return ( + + + {isBirthdateUpdateAllowed ? ( + + + + My birthdate + + + + This information is private and not shared with other users. + + + + {isLoading ? ( + + ) : fetchErrorMessage || !preferences ? ( + + ) : isUsingAppPassword ? ( + + + Hmm, it looks like you're signed in with an{' '} + App Password. To set your + birthdate, you'll need to sign in with your main account + password, or ask whomever controls this account to do so. + + + ) : ( + + )} + + + + + ) : ( + + + + You recently changed your birthdate + + + + There is a limit to how often you can change your birthdate. You + may need to wait a day or two before updating it again. + + + + + + + )} + + ) +} + +function BirthdayInner({ + control, + preferences, +}: { + control: Dialog.DialogControlProps + preferences: UsePreferencesQueryResponse +}) { + const {t: l} = useLingui() + const cleanError = useCleanError() + const [date, setDate] = useState(preferences.birthDate || getDateAgo(18)) + const {isPending, error, mutateAsync: setBirthDate} = useBirthdateMutation() + const hasChanged = date?.getTime() !== preferences.birthDate?.getTime() + const errorMessage = useMemo(() => { + if (error) { + const {raw, clean} = cleanError(error) + return clean || raw + } + }, [error, cleanError]) + + const age = getAge(new Date(date)) + const isUnder13 = age < 13 + const isUnder18 = age >= 13 && age < 18 + + const onSave = useCallback(async () => { + try { + // skip if date is the same + if (hasChanged) { + await setBirthDate({birthDate: date}) + } + control.close() + } catch (error) { + const e = error as Error + logger.error(`setBirthDate failed`, {message: e.message}) + } + }, [date, setBirthDate, control, hasChanged]) + + return ( + + + setDate(new Date(newDate))} + label={l`Birthdate`} + accessibilityHint={l`Enter your birthdate`} + /> + + {isUnder18 && hasChanged && ( + + + The birthdate you've entered means you are under 18 years old. + Certain content and features may be unavailable to you. + + + )} + {isUnder13 && ( + + + You must be at least 13 years old to use Blacksky. Read our{' '} + + Terms of Service + {' '} + for more information. + + + )} + {errorMessage ? ( + + ) : undefined} + + + + + ) +} diff --git a/src/env/common.ts b/src/env/common.ts index dba6199c7..0318842f0 100644 --- a/src/env/common.ts +++ b/src/env/common.ts @@ -91,18 +91,6 @@ export const CHAT_PROXY_DID: Did = export const METRICS_API_HOST: string = process.env.EXPO_PUBLIC_METRICS_API_HOST || 'https://events.bsky.app' -/** - * PostHog project API key. If empty, PostHog reporting is disabled. - */ -export const POSTHOG_API_KEY: string = - process.env.EXPO_PUBLIC_POSTHOG_API_KEY || '' - -/** - * PostHog ingestion host. - */ -export const POSTHOG_HOST: string = - process.env.EXPO_PUBLIC_POSTHOG_HOST || 'https://us.i.posthog.com' - /** * Growthbook API host */ diff --git a/src/lib/age.ts b/src/lib/age.ts new file mode 100644 index 000000000..55a7790af --- /dev/null +++ b/src/lib/age.ts @@ -0,0 +1,29 @@ +import {getAge} from '#/lib/strings/time' + +/** + * Whether the user's self-declared birthdate places them under 18. + * + * Declared age only - we do not perform any third-party age verification. + * Returns false when no birthdate is known: this is a deliberate permissive + * default. Signup already enforces a 13+ minimum, and normal (OAuth) sessions + * reliably expose birthDate via getPreferences; a missing birthdate is a rare + * legacy/app-password case where we prefer not to block otherwise-adult users. + */ +export function isDeclaredUnder18(birthDate?: Date): boolean { + if (!birthDate) return false + return getAge(birthDate) < 18 +} + +/** + * Whether adult content must be blocked for this user. + * + * Phase 1 (current): declared age only - blocked iff the user declares an age + * under 18. This function is the seam for later per-jurisdiction verification: + * a future phase can additionally block unverified users in regions that + * require verified (not merely declared) age, gated behind a feature flag using + * the countryCode/regionCode attributes already set in the analytics/features + * (GrowthBook) provider. Keeping the decision here means callers never change. + */ +export function adultContentAgeBlocked(birthDate?: Date): boolean { + return isDeclaredUnder18(birthDate) +} diff --git a/src/locale/locales/en/messages.po b/src/locale/locales/en/messages.po index 85a809767..fc3925502 100644 --- a/src/locale/locales/en/messages.po +++ b/src/locale/locales/en/messages.po @@ -30,7 +30,7 @@ msgstr "(chat invite link)" msgid "(contains embedded content)" msgstr "" -#: src/screens/Settings/AccountSettings.tsx:87 +#: src/screens/Settings/AccountSettings.tsx:89 msgid "(no email)" msgstr "" @@ -119,7 +119,7 @@ msgstr "" #. placeholder {0}: numUnreadNotifications ?? 0 #: src/view/shell/bottom-bar/BottomBar.tsx:240 #: src/view/shell/bottom-bar/BottomBar.tsx:272 -#: src/view/shell/Drawer.tsx:615 +#: src/view/shell/Drawer.tsx:622 msgid "{0, plural, one {# unread item} other {# unread items}}" msgstr "" @@ -984,7 +984,7 @@ msgstr "" #: src/Navigation.tsx:431 #: src/screens/Login/LoginForm.tsx:105 -#: src/screens/Settings/AccountSettings.tsx:67 +#: src/screens/Settings/AccountSettings.tsx:69 #: src/screens/Settings/Settings.tsx:167 #: src/screens/Settings/Settings.tsx:170 msgid "Account" @@ -1332,7 +1332,7 @@ msgid "Adult Content" msgstr "" #. placeholder {0}: BSKY_APP_HOST.replace(/^https?:\/\//, '').replace( /\/$/, '', ) -#: src/screens/Moderation/index.tsx:377 +#: src/screens/Moderation/index.tsx:414 msgid "Adult content can only be enabled via the Web at <0>{0}." msgstr "Adult content can only be enabled via the Web at <0>{0}." @@ -1349,7 +1349,7 @@ msgstr "" msgid "Adult sexual abuse content" msgstr "" -#: src/screens/Moderation/index.tsx:423 +#: src/screens/Moderation/index.tsx:461 msgid "Advanced" msgstr "" @@ -1897,8 +1897,8 @@ msgstr "Authentication error. Please try signing in again." msgid "Automated account" msgstr "Automated account" -#: src/screens/Settings/AccountSettings.tsx:159 -#: src/screens/Settings/AccountSettings.tsx:162 +#: src/screens/Settings/AccountSettings.tsx:171 +#: src/screens/Settings/AccountSettings.tsx:174 msgid "Automation label" msgstr "Automation label" @@ -2000,10 +2000,19 @@ msgstr "" msgid "Before you can message another user, you must first verify your email." msgstr "" -#: src/view/shell/Drawer.tsx:462 +#: src/view/shell/Drawer.tsx:469 msgid "Begin Discussion" msgstr "Begin Discussion" +#: src/components/dialogs/BirthDateSettings.tsx:163 +msgid "Birthdate" +msgstr "Birthdate" + +#: src/screens/Settings/AccountSettings.tsx:160 +#: src/screens/Settings/AccountSettings.tsx:165 +msgid "Birthday" +msgstr "Birthday" + #: src/screens/PostThread/components/ThreadItemAnchor.tsx:658 msgid "Blacksky cannot confirm the authenticity of the claimed date." msgstr "Blacksky cannot confirm the authenticity of the claimed date." @@ -2127,7 +2136,7 @@ msgstr "Block user and/or leave this conversation" msgid "Blocked" msgstr "" -#: src/screens/Moderation/index.tsx:300 +#: src/screens/Moderation/index.tsx:316 msgid "Blocked accounts" msgstr "" @@ -2467,7 +2476,7 @@ msgstr "" #: src/Navigation.tsx:518 #: src/view/shell/bottom-bar/BottomBar.tsx:237 #: src/view/shell/desktop/LeftNav.tsx:706 -#: src/view/shell/Drawer.tsx:583 +#: src/view/shell/Drawer.tsx:590 msgid "Chat" msgstr "" @@ -2965,7 +2974,7 @@ msgstr "" msgid "Content Blocked" msgstr "" -#: src/screens/Moderation/index.tsx:333 +#: src/screens/Moderation/index.tsx:349 msgid "Content filters" msgstr "" @@ -3497,8 +3506,8 @@ msgstr "Dawn" msgid "Day" msgstr "Day" -#: src/screens/Settings/AccountSettings.tsx:181 -#: src/screens/Settings/AccountSettings.tsx:190 +#: src/screens/Settings/AccountSettings.tsx:193 +#: src/screens/Settings/AccountSettings.tsx:202 #: src/screens/Settings/components/DeactivateAccountDialog.tsx:110 msgid "Deactivate account" msgstr "" @@ -3541,8 +3550,8 @@ msgstr "" msgid "Delete" msgstr "" -#: src/screens/Settings/AccountSettings.tsx:195 -#: src/screens/Settings/AccountSettings.tsx:204 +#: src/screens/Settings/AccountSettings.tsx:207 +#: src/screens/Settings/AccountSettings.tsx:216 msgid "Delete account" msgstr "" @@ -3756,7 +3765,7 @@ msgstr "Disable this invite link?" #: src/lib/moderation/useLabelBehaviorDescription.ts:35 #: src/lib/moderation/useLabelBehaviorDescription.ts:45 #: src/lib/moderation/useLabelBehaviorDescription.ts:71 -#: src/screens/Moderation/index.tsx:367 +#: src/screens/Moderation/index.tsx:383 msgid "Disabled" msgstr "" @@ -3809,7 +3818,7 @@ msgstr "" #: src/view/shell/desktop/RightNav.tsx:116 #: src/view/shell/desktop/RightNav.tsx:117 -#: src/view/shell/Drawer.tsx:469 +#: src/view/shell/Drawer.tsx:476 msgid "Discussion" msgstr "Discussion" @@ -3903,6 +3912,8 @@ msgstr "" #: src/components/contacts/components/InviteInfo.tsx:79 #: src/components/contacts/screens/ViewMatches.tsx:395 #: src/components/contacts/screens/ViewMatches.tsx:412 +#: src/components/dialogs/BirthDateSettings.tsx:193 +#: src/components/dialogs/BirthDateSettings.tsx:200 #: src/components/dialogs/EmailDialog/screens/Verify.tsx:195 #: src/components/dialogs/EmailDialog/screens/Verify.tsx:200 #: src/components/dialogs/LanguageSelectDialog.tsx:327 @@ -4165,7 +4176,7 @@ msgstr "" msgid "Either the creator of this list has blocked you or you have blocked the creator." msgstr "" -#: src/screens/Settings/AccountSettings.tsx:82 +#: src/screens/Settings/AccountSettings.tsx:84 #: src/screens/Signup/StepInfo/index.tsx:195 msgid "Email" msgstr "" @@ -4237,7 +4248,7 @@ msgstr "" msgid "Enable {0} only" msgstr "" -#: src/screens/Moderation/index.tsx:354 +#: src/screens/Moderation/index.tsx:370 msgid "Enable adult content" msgstr "" @@ -4285,7 +4296,7 @@ msgstr "" msgid "Enable trending videos in your Discover feed" msgstr "" -#: src/screens/Moderation/index.tsx:365 +#: src/screens/Moderation/index.tsx:381 msgid "Enabled" msgstr "" @@ -4338,6 +4349,10 @@ msgstr "" msgid "Enter the email you used to create your account. We'll send you a \"reset code\" so you can set a new password." msgstr "" +#: src/components/dialogs/BirthDateSettings.tsx:164 +msgid "Enter your birthdate" +msgstr "Enter your birthdate" + #: src/screens/Login/ForgotPasswordForm.tsx:100 #: src/screens/Signup/StepInfo/index.tsx:215 msgid "Enter your email address" @@ -4515,7 +4530,7 @@ msgstr "" #: src/Navigation.tsx:778 #: src/screens/Search/Shell.tsx:362 #: src/view/shell/desktop/LeftNav.tsx:685 -#: src/view/shell/Drawer.tsx:531 +#: src/view/shell/Drawer.tsx:538 msgid "Explore" msgstr "" @@ -4530,8 +4545,8 @@ msgstr "" msgid "Export my chat data" msgstr "Export my chat data" -#: src/screens/Settings/AccountSettings.tsx:172 -#: src/screens/Settings/AccountSettings.tsx:176 +#: src/screens/Settings/AccountSettings.tsx:184 +#: src/screens/Settings/AccountSettings.tsx:188 msgid "Export my data" msgstr "" @@ -4910,7 +4925,7 @@ msgstr "" msgid "Feed unavailable" msgstr "" -#: src/view/shell/Drawer.tsx:457 +#: src/view/shell/Drawer.tsx:464 msgid "Feedback" msgstr "" @@ -4928,7 +4943,7 @@ msgstr "" #: src/view/screens/Feeds.tsx:504 #: src/view/screens/Profile.tsx:269 #: src/view/shell/desktop/LeftNav.tsx:718 -#: src/view/shell/Drawer.tsx:647 +#: src/view/shell/Drawer.tsx:654 msgid "Feeds" msgstr "" @@ -5329,7 +5344,7 @@ msgstr "" msgid "Germ DM reconnected" msgstr "" -#: src/view/shell/Drawer.tsx:474 +#: src/view/shell/Drawer.tsx:481 msgid "Get help" msgstr "" @@ -5625,8 +5640,8 @@ msgstr "" msgid "Half way there!" msgstr "" -#: src/screens/Settings/AccountSettings.tsx:148 -#: src/screens/Settings/AccountSettings.tsx:153 +#: src/screens/Settings/AccountSettings.tsx:150 +#: src/screens/Settings/AccountSettings.tsx:155 msgid "Handle" msgstr "" @@ -5698,7 +5713,7 @@ msgstr "Held by Blacksky for 7 days to prevent abuse, then deleted" #: src/screens/Settings/Settings.tsx:253 #: src/view/shell/desktop/RightNav.tsx:137 #: src/view/shell/desktop/RightNav.tsx:140 -#: src/view/shell/Drawer.tsx:483 +#: src/view/shell/Drawer.tsx:490 msgid "Help" msgstr "" @@ -5823,6 +5838,10 @@ msgstr "" msgid "Hides the invite friends promo banner" msgstr "Hides the invite friends promo banner" +#: src/components/dialogs/BirthDateSettings.tsx:76 +msgid "Hmm, it looks like you're signed in with an <0>App Password. To set your birthdate, you'll need to sign in with your main account password, or ask whomever controls this account to do so." +msgstr "Hmm, it looks like you're signed in with an <0>App Password. To set your birthdate, you'll need to sign in with your main account password, or ask whomever controls this account to do so." + #: src/view/com/posts/PostFeedErrorMessage.tsx:125 msgid "Hmm, some kind of issue occurred when contacting the feed server. Please let the feed owner know about this issue." msgstr "" @@ -5843,7 +5862,7 @@ msgstr "" msgid "Hmm, we're having trouble finding this feed. It may have been deleted." msgstr "" -#: src/screens/Moderation/index.tsx:58 +#: src/screens/Moderation/index.tsx:61 msgid "Hmmmm, it seems we're having trouble loading this data. See below for more details. If this issue persists, please contact us." msgstr "" @@ -5859,7 +5878,7 @@ msgstr "" #: src/Navigation.tsx:794 #: src/view/shell/bottom-bar/BottomBar.tsx:193 #: src/view/shell/desktop/LeftNav.tsx:675 -#: src/view/shell/Drawer.tsx:557 +#: src/view/shell/Drawer.tsx:564 msgid "Home" msgstr "" @@ -6114,7 +6133,7 @@ msgstr "" msgid "Interaction limited" msgstr "" -#: src/screens/Moderation/index.tsx:240 +#: src/screens/Moderation/index.tsx:256 msgid "Interaction settings" msgstr "" @@ -6671,7 +6690,7 @@ msgstr "" #: src/view/screens/Profile.tsx:262 #: src/view/screens/Profile.tsx:271 #: src/view/shell/desktop/LeftNav.tsx:728 -#: src/view/shell/Drawer.tsx:662 +#: src/view/shell/Drawer.tsx:669 msgid "Lists" msgstr "" @@ -6827,6 +6846,10 @@ msgstr "" msgid "Love GIFs" msgstr "Love GIFs" +#: src/view/screens/SupportStripeCheckout.tsx:44 +msgid "Make a one-time or recurring card contribution on the web. This will open in your browser." +msgstr "Make a one-time or recurring card contribution on the web. This will open in your browser." + #: src/components/dialogs/EmailDialog/index.tsx:39 msgid "Make adjustments to email settings for your account" msgstr "" @@ -6844,7 +6867,7 @@ msgstr "" msgid "Manage saved feeds" msgstr "" -#: src/screens/Moderation/index.tsx:310 +#: src/screens/Moderation/index.tsx:326 msgid "Manage verification settings" msgstr "" @@ -7031,7 +7054,7 @@ msgid "Missing media" msgstr "" #: src/Navigation.tsx:186 -#: src/screens/Moderation/index.tsx:97 +#: src/screens/Moderation/index.tsx:100 msgid "Moderation" msgstr "" @@ -7070,7 +7093,7 @@ msgctxt "toast" msgid "Moderation list updated" msgstr "" -#: src/screens/Moderation/index.tsx:270 +#: src/screens/Moderation/index.tsx:286 msgid "Moderation lists" msgstr "" @@ -7087,7 +7110,7 @@ msgstr "" msgid "Moderation states" msgstr "" -#: src/screens/Moderation/index.tsx:224 +#: src/screens/Moderation/index.tsx:240 msgid "Moderation tools" msgstr "" @@ -7222,7 +7245,7 @@ msgstr "" msgid "Muted" msgstr "Muted" -#: src/screens/Moderation/index.tsx:285 +#: src/screens/Moderation/index.tsx:301 msgid "Muted accounts" msgstr "" @@ -7240,7 +7263,7 @@ msgstr "" msgid "Muted by \"{0}\"" msgstr "" -#: src/screens/Moderation/index.tsx:255 +#: src/screens/Moderation/index.tsx:271 msgid "Muted words & tags" msgstr "" @@ -7252,6 +7275,11 @@ msgstr "" msgid "Mutual group chats" msgstr "Mutual group chats" +#: src/components/dialogs/BirthDateSettings.tsx:54 +#: src/components/dialogs/BirthDateSettings.tsx:58 +msgid "My birthdate" +msgstr "My birthdate" + #: src/screens/StarterPack/Wizard/StepDetails.tsx:77 msgid "My favorite feeds and people - join me!" msgstr "My favorite feeds and people - join me!" @@ -7759,7 +7787,7 @@ msgstr "" #: src/view/screens/Notifications.tsx:128 #: src/view/shell/bottom-bar/BottomBar.tsx:268 #: src/view/shell/desktop/LeftNav.tsx:695 -#: src/view/shell/Drawer.tsx:610 +#: src/view/shell/Drawer.tsx:617 msgid "Notifications" msgstr "" @@ -7777,7 +7805,7 @@ msgid "Number should be a mobile number" msgstr "" #: src/lib/moderation/useLabelBehaviorDescription.ts:14 -#: src/screens/Settings/AccountSettings.tsx:166 +#: src/screens/Settings/AccountSettings.tsx:178 #: src/screens/Settings/NotificationSettings/index.tsx:395 msgid "Off" msgstr "" @@ -7814,7 +7842,7 @@ msgstr "" msgid "Oldest replies first" msgstr "" -#: src/screens/Settings/AccountSettings.tsx:166 +#: src/screens/Settings/AccountSettings.tsx:178 msgid "On" msgstr "On" @@ -8008,7 +8036,7 @@ msgstr "" msgid "Open moderation debug page" msgstr "" -#: src/screens/Moderation/index.tsx:251 +#: src/screens/Moderation/index.tsx:267 msgid "Open muted words and tags settings" msgstr "" @@ -8092,7 +8120,11 @@ msgstr "" msgid "Opens captions and alt text dialog" msgstr "" -#: src/screens/Settings/AccountSettings.tsx:149 +#: src/screens/Settings/AccountSettings.tsx:161 +msgid "Opens change birthday dialog" +msgstr "Opens change birthday dialog" + +#: src/screens/Settings/AccountSettings.tsx:151 msgid "Opens change handle dialog" msgstr "" @@ -8278,8 +8310,8 @@ msgid "Party GIFs" msgstr "Party GIFs" #: src/screens/Deactivated.tsx:219 -#: src/screens/Settings/AccountSettings.tsx:139 -#: src/screens/Settings/AccountSettings.tsx:143 +#: src/screens/Settings/AccountSettings.tsx:141 +#: src/screens/Settings/AccountSettings.tsx:145 #: src/screens/Settings/AppPasswords.tsx:106 #: src/screens/Settings/AppPasswords.tsx:107 #: src/screens/Settings/components/DeactivateAccountDialog.tsx:145 @@ -8839,8 +8871,8 @@ msgstr "" #: src/screens/Settings/AboutSettings.tsx:93 #: src/screens/Settings/AboutSettings.tsx:96 #: src/view/screens/PrivacyPolicy.tsx:25 -#: src/view/shell/Drawer.tsx:833 -#: src/view/shell/Drawer.tsx:834 +#: src/view/shell/Drawer.tsx:840 +#: src/view/shell/Drawer.tsx:841 msgid "Privacy Policy" msgstr "" @@ -8870,7 +8902,7 @@ msgstr "" #: src/view/shell/bottom-bar/BottomBar.tsx:311 #: src/view/shell/desktop/LeftNav.tsx:751 #: src/view/shell/Drawer.tsx:92 -#: src/view/shell/Drawer.tsx:713 +#: src/view/shell/Drawer.tsx:720 msgid "Profile" msgstr "" @@ -9135,7 +9167,7 @@ msgstr "" #: src/screens/Bookmarks/index.tsx:265 #: src/screens/Messages/ConversationSettings/Member.tsx:162 #: src/screens/Messages/ConversationSettings/prompts.tsx:178 -#: src/screens/Moderation/index.tsx:443 +#: src/screens/Moderation/index.tsx:481 #: src/screens/Settings/Settings.tsx:635 #: src/view/com/posts/PostFeedErrorMessage.tsx:221 msgid "Remove" @@ -9272,7 +9304,7 @@ msgstr "" msgid "Remove this feed from your saved feeds" msgstr "" -#: src/screens/Moderation/index.tsx:439 +#: src/screens/Moderation/index.tsx:477 msgid "Remove unavailable moderation services" msgstr "" @@ -9323,7 +9355,7 @@ msgstr "" msgid "Removed from your feeds" msgstr "" -#: src/screens/Moderation/index.tsx:181 +#: src/screens/Moderation/index.tsx:184 msgid "Removed unavailable services" msgstr "" @@ -9768,6 +9800,7 @@ msgstr "Sad GIFs" msgid "Safety tools like spam and bot detection aren't affected. They stay on for everyone." msgstr "Safety tools like spam and bot detection aren't affected. They stay on for everyone." +#: src/components/dialogs/BirthDateSettings.tsx:200 #: src/components/dialogs/lists/CreateOrEditListDialog.tsx:309 #: src/components/dialogs/lists/CreateOrEditListDialog.tsx:324 #: src/components/dialogs/PostInteractionSettingsDialog.tsx:668 @@ -9790,6 +9823,10 @@ msgstr "Safety tools like spam and bot detection aren't affected. They stay on f msgid "Save" msgstr "" +#: src/components/dialogs/BirthDateSettings.tsx:193 +msgid "Save birthdate" +msgstr "Save birthdate" + #: src/components/activity-notifications/SubscribeProfileDialog.tsx:198 #: src/components/activity-notifications/SubscribeProfileDialog.tsx:207 #: src/screens/SavedFeeds.tsx:122 @@ -9843,7 +9880,7 @@ msgid "Save to my feeds" msgstr "" #: src/view/shell/desktop/LeftNav.tsx:738 -#: src/view/shell/Drawer.tsx:688 +#: src/view/shell/Drawer.tsx:695 msgctxt "link to bookmarks screen" msgid "Saved" msgstr "" @@ -10263,7 +10300,7 @@ msgstr "" msgid "Send error report" msgstr "Send error report" -#: src/view/shell/Drawer.tsx:450 +#: src/view/shell/Drawer.tsx:457 msgid "Send feedback" msgstr "" @@ -10350,7 +10387,7 @@ msgstr "" #: src/Navigation.tsx:222 #: src/screens/Settings/Settings.tsx:94 #: src/view/shell/desktop/LeftNav.tsx:761 -#: src/view/shell/Drawer.tsx:726 +#: src/view/shell/Drawer.tsx:733 msgid "Settings" msgstr "" @@ -10795,7 +10832,7 @@ msgstr "" msgid "Some community members can reply" msgstr "Some community members can reply" -#: src/screens/Moderation/index.tsx:432 +#: src/screens/Moderation/index.tsx:470 msgid "Some moderation services in your list are no longer available." msgstr "" @@ -10869,7 +10906,7 @@ msgstr "" msgid "Something went wrong, please try again" msgstr "" -#: src/screens/Moderation/index.tsx:109 +#: src/screens/Moderation/index.tsx:112 #: src/screens/Profile/Sections/Labels.tsx:184 msgid "Something went wrong, please try again." msgstr "" @@ -11158,12 +11195,15 @@ msgstr "Support the Blacksky community through OpenCollective. Your contribution #: src/view/shell/desktop/RightNav.tsx:105 #: src/view/shell/desktop/RightNav.tsx:106 -#: src/view/shell/Drawer.tsx:488 -#: src/view/shell/Drawer.tsx:497 -#: src/view/shell/Drawer.tsx:739 +#: src/view/shell/Drawer.tsx:495 +#: src/view/shell/Drawer.tsx:504 +#: src/view/shell/Drawer.tsx:746 msgid "Support Us" msgstr "Support Us" +#: src/view/screens/SupportStripeCheckout.tsx:41 +#: src/view/screens/SupportStripeCheckout.tsx:50 +#: src/view/screens/SupportStripeCheckout.tsx:56 #: src/view/screens/SupportStripeCheckout.web.tsx:118 msgid "Support with Card" msgstr "Support with Card" @@ -11324,12 +11364,13 @@ msgstr "Temporarily deactivate your account" msgid "Terms" msgstr "" +#: src/components/dialogs/BirthDateSettings.tsx:181 #: src/Navigation.tsx:360 #: src/screens/Settings/AboutSettings.tsx:85 #: src/screens/Settings/AboutSettings.tsx:88 #: src/view/screens/TermsOfService.tsx:25 -#: src/view/shell/Drawer.tsx:826 -#: src/view/shell/Drawer.tsx:828 +#: src/view/shell/Drawer.tsx:833 +#: src/view/shell/Drawer.tsx:835 msgid "Terms of Service" msgstr "" @@ -11396,11 +11437,15 @@ msgstr "" msgid "The author of this thread has hidden this reply." msgstr "" +#: src/components/dialogs/BirthDateSettings.tsx:169 +msgid "The birthdate you've entered means you are under 18 years old. Certain content and features may be unavailable to you." +msgstr "The birthdate you've entered means you are under 18 years old. Certain content and features may be unavailable to you." + #: src/view/com/posts/FeedShutdownMsg.tsx:107 msgid "The Blacksky Trending" msgstr "The Blacksky Trending" -#: src/screens/Moderation/index.tsx:380 +#: src/screens/Moderation/index.tsx:417 msgid "The Blacksky web application" msgstr "The Blacksky web application" @@ -11489,6 +11534,10 @@ msgstr "" msgid "Theme" msgstr "" +#: src/components/dialogs/BirthDateSettings.tsx:106 +msgid "There is a limit to how often you can change your birthdate. You may need to wait a day or two before updating it again." +msgstr "There is a limit to how often you can change your birthdate. You may need to wait a day or two before updating it again." + #: src/screens/Messages/components/InviteLinkDialog.tsx:521 msgid "There is no invite link for this group chat." msgstr "There is no invite link for this group chat." @@ -11815,6 +11864,10 @@ msgstr "" msgid "This image could not be used. Try a different format like .jpg or .png." msgstr "This image could not be used. Try a different format like .jpg or .png." +#: src/components/dialogs/BirthDateSettings.tsx:62 +msgid "This information is private and not shared with other users." +msgstr "This information is private and not shared with other users." + #: src/components/intents/GroupChatJoinDialog.tsx:161 msgid "This invite link has been disabled." msgstr "This invite link has been disabled." @@ -12073,7 +12126,7 @@ msgstr "" msgid "Today" msgstr "" -#: src/screens/Moderation/index.tsx:357 +#: src/screens/Moderation/index.tsx:373 msgid "Toggle to enable or disable adult content" msgstr "" @@ -12506,8 +12559,8 @@ msgstr "Update {0} in Lists" #: src/components/dialogs/EmailDialog/screens/Update.tsx:296 #: src/components/dialogs/EmailDialog/screens/Update.tsx:308 -#: src/screens/Settings/AccountSettings.tsx:123 -#: src/screens/Settings/AccountSettings.tsx:133 +#: src/screens/Settings/AccountSettings.tsx:125 +#: src/screens/Settings/AccountSettings.tsx:135 msgid "Update email" msgstr "" @@ -12526,6 +12579,10 @@ msgstr "Update invite link" msgid "Update to {domain}" msgstr "" +#: src/screens/Moderation/index.tsx:397 +msgid "Update your birthdate" +msgstr "Update your birthdate" + #: src/components/dialogs/EmailDialog/screens/Update.tsx:202 msgid "Update your email" msgstr "" @@ -12727,7 +12784,7 @@ msgstr "" msgid "Verification failed, please try again." msgstr "" -#: src/screens/Moderation/index.tsx:315 +#: src/screens/Moderation/index.tsx:331 msgid "Verification settings" msgstr "" @@ -12788,8 +12845,8 @@ msgid "Verify this account?" msgstr "" #: src/components/dialogs/EmailDialog/screens/Verify.tsx:221 -#: src/screens/Settings/AccountSettings.tsx:97 -#: src/screens/Settings/AccountSettings.tsx:117 +#: src/screens/Settings/AccountSettings.tsx:99 +#: src/screens/Settings/AccountSettings.tsx:119 msgid "Verify your email" msgstr "" @@ -12998,11 +13055,11 @@ msgstr "" msgid "View video" msgstr "" -#: src/screens/Moderation/index.tsx:295 +#: src/screens/Moderation/index.tsx:311 msgid "View your blocked accounts" msgstr "" -#: src/screens/Moderation/index.tsx:235 +#: src/screens/Moderation/index.tsx:251 msgid "View your default post interaction settings" msgstr "" @@ -13011,11 +13068,11 @@ msgstr "" msgid "View your feeds and explore more" msgstr "" -#: src/screens/Moderation/index.tsx:265 +#: src/screens/Moderation/index.tsx:281 msgid "View your moderation lists" msgstr "" -#: src/screens/Moderation/index.tsx:280 +#: src/screens/Moderation/index.tsx:296 msgid "View your muted accounts" msgstr "" @@ -13155,7 +13212,11 @@ msgstr "" msgid "We were unable to determine if you are allowed to upload videos. Please try again." msgstr "" -#: src/screens/Moderation/index.tsx:458 +#: src/components/dialogs/BirthDateSettings.tsx:41 +msgid "We were unable to load your birthdate preferences. Please try again." +msgstr "We were unable to load your birthdate preferences. Please try again." + +#: src/screens/Moderation/index.tsx:496 msgid "We were unable to load your configured labelers at this time." msgstr "" @@ -13672,6 +13733,10 @@ msgstr "You must be 13 years of age or older to create an account." msgid "You must be a chat owner to remove a member." msgstr "You must be a chat owner to remove a member." +#: src/components/dialogs/BirthDateSettings.tsx:177 +msgid "You must be at least 13 years old to use Blacksky. Read our <0>Terms of Service for more information." +msgstr "You must be at least 13 years old to use Blacksky. Read our <0>Terms of Service for more information." + #: src/components/StarterPack/ProfileStarterPacks.tsx:365 msgid "You must be following at least seven other people to generate a starter pack." msgstr "" @@ -13707,6 +13772,11 @@ msgstr "" msgid "You reacted {0} to {target}" msgstr "You reacted {0} to {target}" +#: src/components/dialogs/BirthDateSettings.tsx:92 +#: src/components/dialogs/BirthDateSettings.tsx:102 +msgid "You recently changed your birthdate" +msgstr "You recently changed your birthdate" + #: src/components/dms/MessageItem.tsx:804 msgid "You replied" msgstr "You replied" @@ -13912,6 +13982,10 @@ msgstr "" msgid "Your current handle <0>{0} will automatically remain reserved for you. You can switch back to it at any time from this account." msgstr "" +#: src/screens/Moderation/index.tsx:393 +msgid "Your declared age is under 18, so adult content is turned off and cannot be enabled. If this is a mistake, you can <0>update your birthdate." +msgstr "Your declared age is under 18, so adult content is turned off and cannot be enabled. If this is a mistake, you can <0>update your birthdate." + #: src/lib/strings/errors.ts:56 msgid "Your device clock appears to be incorrect. Please check your system time settings and try again." msgstr "Your device clock appears to be incorrect. Please check your system time settings and try again." diff --git a/src/screens/Moderation/index.tsx b/src/screens/Moderation/index.tsx index a55d5d7ec..15a90ff87 100644 --- a/src/screens/Moderation/index.tsx +++ b/src/screens/Moderation/index.tsx @@ -5,6 +5,7 @@ import {msg} from '@lingui/core/macro' import {useLingui} from '@lingui/react' import {Trans} from '@lingui/react/macro' +import {isDeclaredUnder18} from '#/lib/age' import {getLabelingServiceTitle, isAppLabeler} from '#/lib/moderation' import { type CommonNavigatorParams, @@ -23,6 +24,8 @@ import {isNonConfigurableModerationAuthority} from '#/state/session/additional-m import {atoms as a, useBreakpoints, useTheme, type ViewStyleProp} from '#/alf' import * as Admonition from '#/components/Admonition' import {Button, ButtonIcon, ButtonText} from '#/components/Button' +import * as Dialog from '#/components/Dialog' +import {BirthDateSettingsDialog} from '#/components/dialogs/BirthDateSettings' import {useGlobalDialogsControlContext} from '#/components/dialogs/Context' import {Divider} from '#/components/Divider' import * as Toggle from '#/components/forms/Toggle' @@ -190,12 +193,24 @@ export function ModerationScreenInner({ const {mutateAsync: setAdultContentPref, variables: optimisticAdultContent} = usePreferencesSetAdultContentMutation() + const birthDateDialogControl = Dialog.useDialogControl() + const isDeclaredMinor = isDeclaredUnder18(preferences.birthDate) let adultContentEnabled = !!( (optimisticAdultContent && optimisticAdultContent.enabled) || (!optimisticAdultContent && preferences.moderationPrefs.adultContentEnabled) ) const adultContentUIDisabledOnIOS = IS_IOS && !adultContentEnabled - const adultContentUIDisabled = adultContentUIDisabledOnIOS + let adultContentUIDisabled = adultContentUIDisabledOnIOS + /* + * Declared-under-18 users cannot view or enable adult content, regardless of + * platform or a previously-stored preference. This mirrors the effective gate + * applied in #/state/preferences/moderation-opts. Declared age only - no + * verification vendor. + */ + if (isDeclaredMinor) { + adultContentEnabled = false + adultContentUIDisabled = true + } const onToggleAdultContentEnabled = useCallback( async (selected: boolean) => { @@ -214,6 +229,7 @@ export function ModerationScreenInner({ return ( + - {adultContentUIDisabledOnIOS && ( + {isDeclaredMinor ? ( - Adult content can only be enabled via the Web at{' '} + Your declared age is under 18, so adult content is turned off + and cannot be enabled. If this is a mistake, you can{' '} { evt.preventDefault() - Linking.openURL(`${BSKY_APP_HOST.replace(/\/$/, '')}/`) + birthDateDialogControl.open() return false }}> - {BSKY_APP_HOST.replace(/^https?:\/\//, '').replace( - /\/$/, - '', - )} + update your birthdate . + ) : ( + adultContentUIDisabledOnIOS && ( + + + + Adult content can only be enabled via the Web at{' '} + { + evt.preventDefault() + Linking.openURL(`${BSKY_APP_HOST.replace(/\/$/, '')}/`) + return false + }}> + {BSKY_APP_HOST.replace(/^https?:\/\//, '').replace( + /\/$/, + '', + )} + + . + + + + ) )} {adultContentEnabled && ( diff --git a/src/screens/Settings/AccountSettings.tsx b/src/screens/Settings/AccountSettings.tsx index de4d8d8e4..a30fe662e 100644 --- a/src/screens/Settings/AccountSettings.tsx +++ b/src/screens/Settings/AccountSettings.tsx @@ -12,6 +12,7 @@ import * as SettingsList from '#/screens/Settings/components/SettingsList' import {atoms as a, useTheme} from '#/alf' import {isBotAccount} from '#/components/BotBadge' import {useDialogControl} from '#/components/Dialog' +import {BirthDateSettingsDialog} from '#/components/dialogs/BirthDateSettings' import { EmailDialogScreenID, useEmailDialogControl, @@ -45,6 +46,7 @@ export function AccountSettingsScreen({}: Props) { const exportCarControl = useDialogControl() const deactivateAccountControl = useDialogControl() const deleteAccountControl = useDialogControl() + const birthDateControl = useDialogControl() const isOauth = currentAccount?.isOauthSession === true const isBskyPds = useIsBlackskyPds() @@ -154,6 +156,16 @@ export function AccountSettingsScreen({}: Props) { + birthDateControl.open()}> + + + Birthday + + + @@ -209,6 +221,7 @@ export function AccountSettingsScreen({}: Props) { + diff --git a/src/state/birthdate.ts b/src/state/birthdate.ts new file mode 100644 index 000000000..cf1b82ea5 --- /dev/null +++ b/src/state/birthdate.ts @@ -0,0 +1,66 @@ +import {useMemo} from 'react' +import {useMutation, useQueryClient} from '@tanstack/react-query' + +import {preferencesQueryKey} from '#/state/queries/preferences' +import {useAgent, useSession} from '#/state/session' +import {IS_DEV} from '#/env' +import {account} from '#/storage' + +// 6s in dev, 48h in prod +const BIRTHDATE_DELAY_HOURS = IS_DEV ? 0.001 : 48 + +/** + * Stores the timestamp of the birthday update locally. This is used to + * debounce birthday updates globally. + * + * Use {@link useIsBirthdateUpdateAllowed} to check if an update is allowed. + */ +export function snoozeBirthdateUpdateAllowedForDid(did: string) { + account.set([did, 'birthdateLastUpdatedAt'], new Date().toISOString()) +} + +/** + * Checks if we've already snoozed bday updates. + */ +export function hasSnoozedBirthdateUpdateForDid(did: string) { + return !!account.get([did, 'birthdateLastUpdatedAt']) +} + +/** + * Returns whether a birthdate update is currently allowed, based on the last + * update timestamp stored locally. Rate-limiting discourages toggling the + * declared age back and forth to bypass the adult-content age gate. + */ +export function useIsBirthdateUpdateAllowed() { + const {currentAccount} = useSession() + return useMemo(() => { + if (!currentAccount) return false + const lastUpdated = account.get([ + currentAccount.did, + 'birthdateLastUpdatedAt', + ]) + if (!lastUpdated) return true + const lastUpdatedDate = new Date(lastUpdated) + // eslint-disable-next-line react-hooks/purity + const diffMs = Date.now() - lastUpdatedDate.getTime() + const diffHours = diffMs / (1000 * 60 * 60) + return diffHours >= BIRTHDATE_DELAY_HOURS + }, [currentAccount]) +} + +export function useBirthdateMutation() { + const queryClient = useQueryClient() + const agent = useAgent() + + return useMutation({ + mutationFn: async ({birthDate}: {birthDate: Date}) => { + const bday = birthDate.toISOString() + await agent.setPersonalDetails({birthDate: bday}) + // triggers a refetch, which re-derives the age gate in moderation-opts + await queryClient.invalidateQueries({ + queryKey: preferencesQueryKey, + }) + snoozeBirthdateUpdateAllowedForDid(agent.sessionManager.did!) + }, + }) +} diff --git a/src/state/preferences/moderation-opts.tsx b/src/state/preferences/moderation-opts.tsx index 119c9008d..712d7a42f 100644 --- a/src/state/preferences/moderation-opts.tsx +++ b/src/state/preferences/moderation-opts.tsx @@ -1,6 +1,7 @@ import {createContext, useContext, useMemo} from 'react' import {AtpAgent, type ModerationOpts} from '@atproto/api' +import {adultContentAgeBlocked} from '#/lib/age' import {useHiddenPosts, useLabelDefinitions} from '#/state/preferences' import {DEFAULT_LOGGED_OUT_LABEL_PREFERENCES} from '#/state/queries/preferences/const' import {useSession} from '#/state/session' @@ -30,6 +31,7 @@ export function Provider({children}: React.PropsWithChildren<{}>) { const userDid = currentAccount?.did const moderationPrefs = prefs.data?.moderationPrefs + const birthDate = prefs.data?.birthDate const value = useMemo(() => { if (override) { return override @@ -41,6 +43,15 @@ export function Provider({children}: React.PropsWithChildren<{}>) { userDid, prefs: { ...moderationPrefs, + /* + * Force adult content off for declared-under-18 users regardless of the + * stored preference (which could have been enabled on another client). + * This is the effective gate that hides adult labels everywhere content + * is moderated, not just in the settings UI. See #/lib/age. + */ + adultContentEnabled: adultContentAgeBlocked(birthDate) + ? false + : moderationPrefs.adultContentEnabled, labelers: moderationPrefs.labelers.length ? moderationPrefs.labelers : AtpAgent.appLabelers.map(did => ({ @@ -51,7 +62,7 @@ export function Provider({children}: React.PropsWithChildren<{}>) { }, labelDefs, } - }, [override, userDid, labelDefs, moderationPrefs, hiddenPosts]) + }, [override, userDid, labelDefs, moderationPrefs, hiddenPosts, birthDate]) return ( diff --git a/src/view/screens/SupportStripeCheckout.tsx b/src/view/screens/SupportStripeCheckout.tsx index abeb4205b..425eac224 100644 --- a/src/view/screens/SupportStripeCheckout.tsx +++ b/src/view/screens/SupportStripeCheckout.tsx @@ -1,5 +1,63 @@ +import {useCallback} from 'react' +import {View} from 'react-native' +import {msg} from '@lingui/core/macro' +import {useLingui} from '@lingui/react' +import {Trans} from '@lingui/react/macro' + +import {useBrand} from '#/lib/community/BrandContext' +import {useOpenLink} from '#/lib/hooks/useOpenLink' +import {atoms as a, useTheme} from '#/alf' +import {Button, ButtonText} from '#/components/Button' +import {Text} from '#/components/Typography' + +// Stripe's embedded checkout can't run in React Native, so on native we hand +// card donors off to the hosted web support page in a browser instead. export function SupportStripeCheckout() { - return null + const {_} = useLingui() + const t = useTheme() + const brand = useBrand() + const openLink = useOpenLink() + + const contribute = brand.web.links.contribute + const supportUrl = contribute?.startsWith('http') + ? contribute + : `${brand.web.domains.main.replace(/\/$/, '')}${contribute ?? '/support'}` + + const onPress = useCallback(() => { + void openLink(supportUrl) + }, [openLink, supportUrl]) + + return ( + + + Support with Card + + + + Make a one-time or recurring card contribution on the web. This will + open in your browser. + + + + + ) } export default SupportStripeCheckout diff --git a/src/view/shell/Drawer.tsx b/src/view/shell/Drawer.tsx index 5ebdb1010..17be1d301 100644 --- a/src/view/shell/Drawer.tsx +++ b/src/view/shell/Drawer.tsx @@ -317,10 +317,17 @@ let DrawerContent = ({}: React.PropsWithoutRef<{}>): React.ReactNode => { }, [brand.web.links.community]) const onPressContribute = useCallback(() => { - if (brand.web.links.contribute) { - void Linking.openURL(brand.web.links.contribute) + const contribute = brand.web.links.contribute + if (contribute) { + // `contribute` may be a site-relative path (e.g. "/support"), which + // Linking.openURL can't resolve on native. Resolve it against the brand + // domain first. + const url = contribute.startsWith('http') + ? contribute + : `${brand.web.domains.main.replace(/\/$/, '')}${contribute}` + void Linking.openURL(url) } - }, [brand.web.links.contribute]) + }, [brand.web.links.contribute, brand.web.domains.main]) // rendering // =