forked from
jollywhoppers.com/witchsky.app
Bluesky app fork with some witchin' additions 馃挮
1import {type StyleProp, View, type ViewStyle} from 'react-native'
2import {type AppBskyFeedDefs, type ComAtprotoLabelDefs} from '@atproto/api'
3import {msg} from '@lingui/core/macro'
4import {useLingui} from '@lingui/react'
5import {Plural, Trans} from '@lingui/react/macro'
6
7import {useSession} from '#/state/session'
8import {atoms as a} from '#/alf'
9import {
10 Button,
11 ButtonIcon,
12 type ButtonSize,
13 ButtonText,
14} from '#/components/Button'
15import {CircleInfo_Stroke2_Corner0_Rounded as CircleInfo} from '#/components/icons/CircleInfo'
16import {
17 LabelsOnMeDialog,
18 useLabelsOnMeDialogControl,
19} from '#/components/moderation/LabelsOnMeDialog'
20
21export function LabelsOnMe({
22 type,
23 labels,
24 size,
25 style,
26}: {
27 type: 'account' | 'content'
28 labels: ComAtprotoLabelDefs.Label[] | undefined
29 size?: ButtonSize
30 style?: StyleProp<ViewStyle>
31}) {
32 const {_} = useLingui()
33 const {currentAccount} = useSession()
34 const control = useLabelsOnMeDialogControl()
35
36 if (!labels || !currentAccount) {
37 return null
38 }
39 labels = labels.filter(
40 l =>
41 !l.val.startsWith('!') &&
42 !(l.val === 'bot' && l.src === currentAccount.did) &&
43 !(l.val === 'pet' && l.src === currentAccount.did),
44 )
45 if (!labels.length) {
46 return null
47 }
48
49 return (
50 <View style={[a.flex_row, style]}>
51 <LabelsOnMeDialog control={control} labels={labels} type={type} />
52
53 <Button
54 variant="solid"
55 color="secondary"
56 size={size || 'small'}
57 label={_(msg`View information about these labels`)}
58 onPress={() => {
59 control.open()
60 }}>
61 <ButtonIcon position="left" icon={CircleInfo} />
62 <ButtonText style={[a.leading_snug]}>
63 {type === 'account' ? (
64 <Trans>
65 <Plural
66 value={labels.length}
67 one="# label has"
68 other="# labels have"
69 />{' '}
70 been placed on this account
71 </Trans>
72 ) : (
73 <Trans>
74 <Plural
75 value={labels.length}
76 one="# label has"
77 other="# labels have"
78 />{' '}
79 been placed on this content
80 </Trans>
81 )}
82 </ButtonText>
83 </Button>
84 </View>
85 )
86}
87
88export function LabelsOnMyPost({
89 post,
90 style,
91}: {
92 post: AppBskyFeedDefs.PostView
93 style?: StyleProp<ViewStyle>
94}) {
95 const {currentAccount} = useSession()
96 if (post.author.did !== currentAccount?.did) {
97 return null
98 }
99 return (
100 <LabelsOnMe type="content" labels={post.labels} size="tiny" style={style} />
101 )
102}