mirror of https://git.lenooby09.tech/LeNooby09/social-app.git
1import React from 'react'
2import {View} from 'react-native'
3import {ModerationCause} from '@atproto/api'
4import {msg, Trans} from '@lingui/macro'
5import {useLingui} from '@lingui/react'
6
7import {useModerationCauseDescription} from '#/lib/moderation/useModerationCauseDescription'
8import {makeProfileLink} from '#/lib/routes/links'
9import {listUriToHref} from '#/lib/strings/url-helpers'
10import {isNative} from '#/platform/detection'
11import {useSession} from '#/state/session'
12import {atoms as a, useTheme} from '#/alf'
13import * as Dialog from '#/components/Dialog'
14import {Divider} from '#/components/Divider'
15import {InlineLinkText} from '#/components/Link'
16import {AppModerationCause} from '#/components/Pills'
17import {Text} from '#/components/Typography'
18
19export {useDialogControl as useModerationDetailsDialogControl} from '#/components/Dialog'
20
21export interface ModerationDetailsDialogProps {
22 control: Dialog.DialogOuterProps['control']
23 modcause?: ModerationCause | AppModerationCause
24}
25
26export function ModerationDetailsDialog(props: ModerationDetailsDialogProps) {
27 return (
28 <Dialog.Outer control={props.control}>
29 <Dialog.Handle />
30 <ModerationDetailsDialogInner {...props} />
31 </Dialog.Outer>
32 )
33}
34
35function ModerationDetailsDialogInner({
36 modcause,
37 control,
38}: ModerationDetailsDialogProps & {
39 control: Dialog.DialogOuterProps['control']
40}) {
41 const t = useTheme()
42 const {_} = useLingui()
43 const desc = useModerationCauseDescription(modcause)
44 const {currentAccount} = useSession()
45
46 let name
47 let description
48 if (!modcause) {
49 name = _(msg`Content Warning`)
50 description = _(
51 msg`Moderator has chosen to set a general warning on the content.`,
52 )
53 } else if (modcause.type === 'blocking') {
54 if (modcause.source.type === 'list') {
55 const list = modcause.source.list
56 name = _(msg`User Blocked by List`)
57 description = (
58 <Trans>
59 This user is included in the{' '}
60 <InlineLinkText
61 label={list.name}
62 to={listUriToHref(list.uri)}
63 style={[a.text_sm]}>
64 {list.name}
65 </InlineLinkText>{' '}
66 list which you have blocked.
67 </Trans>
68 )
69 } else {
70 name = _(msg`User Blocked`)
71 description = _(
72 msg`You have blocked this user. You cannot view their content.`,
73 )
74 }
75 } else if (modcause.type === 'blocked-by') {
76 name = _(msg`User Blocks You`)
77 description = _(
78 msg`This user has blocked you. You cannot view their content.`,
79 )
80 } else if (modcause.type === 'block-other') {
81 name = _(msg`Content Not Available`)
82 description = _(
83 msg`This content is not available because one of the users involved has blocked the other.`,
84 )
85 } else if (modcause.type === 'muted') {
86 if (modcause.source.type === 'list') {
87 const list = modcause.source.list
88 name = _(msg`Account Muted by List`)
89 description = (
90 <Trans>
91 This user is included in the{' '}
92 <InlineLinkText
93 label={list.name}
94 to={listUriToHref(list.uri)}
95 style={[a.text_sm]}>
96 {list.name}
97 </InlineLinkText>{' '}
98 list which you have muted.
99 </Trans>
100 )
101 } else {
102 name = _(msg`Account Muted`)
103 description = _(msg`You have muted this account.`)
104 }
105 } else if (modcause.type === 'mute-word') {
106 name = _(msg`Post Hidden by Muted Word`)
107 description = _(msg`You've chosen to hide a word or tag within this post.`)
108 } else if (modcause.type === 'hidden') {
109 name = _(msg`Post Hidden by You`)
110 description = _(msg`You have hidden this post.`)
111 } else if (modcause.type === 'reply-hidden') {
112 const isYou = currentAccount?.did === modcause.source.did
113 name = isYou
114 ? _(msg`Reply Hidden by You`)
115 : _(msg`Reply Hidden by Thread Author`)
116 description = isYou
117 ? _(msg`You hid this reply.`)
118 : _(msg`The author of this thread has hidden this reply.`)
119 } else if (modcause.type === 'label') {
120 name = desc.name
121 description = (
122 <Text emoji style={[t.atoms.text, a.text_md, a.leading_snug]}>
123 {desc.description}
124 </Text>
125 )
126 } else {
127 // should never happen
128 name = ''
129 description = ''
130 }
131
132 return (
133 <Dialog.ScrollableInner label={_(msg`Moderation details`)}>
134 <Text emoji style={[t.atoms.text, a.text_2xl, a.font_bold, a.mb_sm]}>
135 {name}
136 </Text>
137 <Text style={[t.atoms.text, a.text_md, a.leading_snug]}>
138 {description}
139 </Text>
140
141 {modcause?.type === 'label' && (
142 <View style={[a.pt_lg]}>
143 <Divider />
144 <Text style={[t.atoms.text, a.text_md, a.leading_snug, a.mt_lg]}>
145 {modcause.source.type === 'user' ? (
146 <Trans>This label was applied by the author.</Trans>
147 ) : (
148 <Trans>
149 This label was applied by{' '}
150 <InlineLinkText
151 label={desc.source || _(msg`an unknown labeler`)}
152 to={makeProfileLink({did: modcause.label.src, handle: ''})}
153 onPress={() => control.close()}
154 style={a.text_md}>
155 {desc.source || _(msg`an unknown labeler`)}
156 </InlineLinkText>
157 .
158 </Trans>
159 )}
160 </Text>
161 </View>
162 )}
163
164 {isNative && <View style={{height: 40}} />}
165
166 <Dialog.Close />
167 </Dialog.ScrollableInner>
168 )
169}