import {View} from 'react-native' import {type $Typed, ComAtprotoLabelDefs} from '@atproto/api' import {Trans, useLingui} from '@lingui/react/macro' import {type NativeStackScreenProps} from '@react-navigation/native-stack' import {useQueryClient} from '@tanstack/react-query' import {type CommonNavigatorParams} from '#/lib/routes/types' import {RQKEY_ROOT as POST_FEED_RQKEY_ROOT} from '#/state/queries/post-feed' import { useProfileQuery, useProfileUpdateMutation, } from '#/state/queries/profile' import {postThreadQueryKeyRoot} from '#/state/queries/usePostThread/types' import {useSession} from '#/state/session' import {UserAvatar} from '#/view/com/util/UserAvatar' import {atoms as a, platform, useTheme} from '#/alf' import {BotBadge} from '#/components/BotBadge' import * as Toggle from '#/components/forms/Toggle' import {Bot_Filled as RobotIcon} from '#/components/icons/Bot' import * as Layout from '#/components/Layout' import {Text} from '#/components/Typography' import {useSimpleVerificationState} from '#/components/verification' import {VerificationCheck} from '#/components/verification/VerificationCheck' import {useAnalytics} from '#/analytics' import * as bsky from '#/types/bsky' type Props = NativeStackScreenProps< CommonNavigatorParams, 'AutomationLabelSettings' > export function AutomationLabelSettingsScreen({}: Props) { const t = useTheme() const ax = useAnalytics() const {t: l} = useLingui() const queryClient = useQueryClient() const {currentAccount} = useSession() const {data: profile} = useProfileQuery({did: currentAccount?.did}) const updateProfile = useProfileUpdateMutation() const verification = useSimpleVerificationState({profile}) const isBotLabeled = profile?.labels?.some(l => l.val === 'bot' && l.src === profile.did) ?? false const canToggle = profile && !updateProfile.isPending const onToggle = () => { if (!profile) { return } let wasAdded = false ax.metric('bot:label:toggle', {state: isBotLabeled ? 'remove' : 'add'}) updateProfile.mutate( { profile, updates: existing => { const labels: $Typed = bsky.validate( existing.labels, ComAtprotoLabelDefs.validateSelfLabels, ) ? existing.labels : { $type: 'com.atproto.label.defs#selfLabels', values: [], } const hasLabel = labels.values.some(l => l.val === 'bot') if (hasLabel) { wasAdded = false labels.values = labels.values.filter(l => l.val !== 'bot') } else { wasAdded = true labels.values.push({val: 'bot'}) } if (labels.values.length === 0) { delete existing.labels } else { existing.labels = labels } return existing }, checkCommitted: res => { const exists = !!res.data.labels?.some(l => l.val === 'bot') return exists === wasAdded }, }, { onSuccess() { queryClient.invalidateQueries({queryKey: [POST_FEED_RQKEY_ROOT]}) queryClient.invalidateQueries({queryKey: [postThreadQueryKeyRoot]}) }, }, ) } return ( Automation Label {profile && ( {profile.displayName || profile.handle} {verification.isVerified && ( )} @{profile.handle} )} Add automation label to account This label lets the world know that this account is automated. If turned on, this label appears next to the account's name on their profile and posts. It can be turned on or off at any time. Show automation label ) }