forked from
jollywhoppers.com/witchsky.app
Bluesky app fork with some witchin' additions 馃挮
1import {View} from 'react-native'
2import {type ComAtprotoLabelDefs} from '@atproto/api'
3import {useLingui} from '@lingui/react/macro'
4
5import {atoms as a, useTheme} from '#/alf'
6import {BotAccountAlert} from '#/components/BotAccountAlert'
7import {Button} from '#/components/Button'
8import {useDialogControl} from '#/components/Dialog'
9import {Bot_Filled as RobotIcon} from '#/components/icons/Bot'
10import {useAnalytics} from '#/analytics'
11import type * as bsky from '#/types/bsky'
12
13export function isBotAccount(profile: {
14 did: string
15 labels?: ComAtprotoLabelDefs.Label[]
16}): boolean {
17 return (
18 profile.labels?.some(l => l.val === 'bot' && l.src === profile.did) ?? false
19 )
20}
21
22export function BotBadge({
23 profile,
24 alwaysShow = false,
25 width,
26}: {
27 profile: bsky.profile.AnyProfileView
28 alwaysShow?: boolean
29 width: number
30}) {
31 const t = useTheme()
32
33 if (!isBotAccount(profile) && !alwaysShow) {
34 return null
35 }
36
37 return (
38 <View>
39 <RobotIcon width={width} fill={t.atoms.text_contrast_medium.color} />
40 </View>
41 )
42}
43
44export function BotBadgeButton({
45 profile,
46 width,
47}: {
48 profile: bsky.profile.AnyProfileView
49 width: number
50}) {
51 const t = useTheme()
52 const ax = useAnalytics()
53 const {t: l} = useLingui()
54 const control = useDialogControl()
55
56 if (!isBotAccount(profile)) {
57 return null
58 }
59
60 return (
61 <>
62 <Button
63 label={l`Automated account`}
64 hitSlop={20}
65 onPress={evt => {
66 evt.preventDefault()
67 ax.metric('bot:badge:click', {})
68 control.open()
69 }}>
70 {({hovered}) => (
71 <View
72 style={[
73 a.justify_end,
74 a.align_end,
75 a.transition_transform,
76 {
77 width: width,
78 height: width,
79 transform: [{scale: hovered ? 1.1 : 1}],
80 },
81 ]}>
82 <RobotIcon
83 width={width}
84 fill={t.atoms.text_contrast_medium.color}
85 />
86 </View>
87 )}
88 </Button>
89 <BotAccountAlert control={control} profile={profile} />
90 </>
91 )
92}