mirror of https://git.lenooby09.tech/LeNooby09/social-app.git
1import React from 'react'
2import {
3 BSKY_LABELER_DID,
4 ModerationCause,
5 ModerationCauseSource,
6} from '@atproto/api'
7import {msg} from '@lingui/macro'
8import {useLingui} from '@lingui/react'
9import {getDefinition, getLabelStrings} from './useLabelInfo'
10import {useLabelDefinitions} from '#/state/preferences'
11import {useGlobalLabelStrings} from './useGlobalLabelStrings'
12
13import {Props as SVGIconProps} from '#/components/icons/common'
14import {Warning_Stroke2_Corner0_Rounded as Warning} from '#/components/icons/Warning'
15import {CircleInfo_Stroke2_Corner0_Rounded as CircleInfo} from '#/components/icons/CircleInfo'
16import {EyeSlash_Stroke2_Corner0_Rounded as EyeSlash} from '#/components/icons/EyeSlash'
17import {CircleBanSign_Stroke2_Corner0_Rounded as CircleBanSign} from '#/components/icons/CircleBanSign'
18
19export interface ModerationCauseDescription {
20 icon: React.ComponentType<SVGIconProps>
21 name: string
22 description: string
23 source?: string
24 sourceType?: ModerationCauseSource['type']
25}
26
27export function useModerationCauseDescription(
28 cause: ModerationCause | undefined,
29): ModerationCauseDescription {
30 const {_, i18n} = useLingui()
31 const {labelDefs, labelers} = useLabelDefinitions()
32 const globalLabelStrings = useGlobalLabelStrings()
33
34 return React.useMemo(() => {
35 if (!cause) {
36 return {
37 icon: Warning,
38 name: _(msg`Content Warning`),
39 description: _(
40 msg`Moderator has chosen to set a general warning on the content.`,
41 ),
42 }
43 }
44 if (cause.type === 'blocking') {
45 if (cause.source.type === 'list') {
46 return {
47 icon: CircleBanSign,
48 name: _(msg`User Blocked by "${cause.source.list.name}"`),
49 description: _(
50 msg`You have blocked this user. You cannot view their content.`,
51 ),
52 }
53 } else {
54 return {
55 icon: CircleBanSign,
56 name: _(msg`User Blocked`),
57 description: _(
58 msg`You have blocked this user. You cannot view their content.`,
59 ),
60 }
61 }
62 }
63 if (cause.type === 'blocked-by') {
64 return {
65 icon: CircleBanSign,
66 name: _(msg`User Blocking You`),
67 description: _(
68 msg`This user has blocked you. You cannot view their content.`,
69 ),
70 }
71 }
72 if (cause.type === 'block-other') {
73 return {
74 icon: CircleBanSign,
75 name: _(msg`Content Not Available`),
76 description: _(
77 msg`This content is not available because one of the users involved has blocked the other.`,
78 ),
79 }
80 }
81 if (cause.type === 'muted') {
82 if (cause.source.type === 'list') {
83 return {
84 icon: EyeSlash,
85 name: _(msg`Muted by "${cause.source.list.name}"`),
86 description: _(msg`You have muted this user`),
87 }
88 } else {
89 return {
90 icon: EyeSlash,
91 name: _(msg`Account Muted`),
92 description: _(msg`You have muted this account.`),
93 }
94 }
95 }
96 if (cause.type === 'mute-word') {
97 return {
98 icon: EyeSlash,
99 name: _(msg`Post Hidden by Muted Word`),
100 description: _(
101 msg`You've chosen to hide a word or tag within this post.`,
102 ),
103 }
104 }
105 if (cause.type === 'hidden') {
106 return {
107 icon: EyeSlash,
108 name: _(msg`Post Hidden by You`),
109 description: _(msg`You have hidden this post`),
110 }
111 }
112 if (cause.type === 'label') {
113 const def = cause.labelDef || getDefinition(labelDefs, cause.label)
114 const strings = getLabelStrings(i18n.locale, globalLabelStrings, def)
115 const labeler = labelers.find(l => l.creator.did === cause.label.src)
116 let source =
117 labeler?.creator.displayName ||
118 (labeler?.creator.handle ? '@' + labeler?.creator.handle : undefined)
119 if (!source) {
120 if (cause.label.src === BSKY_LABELER_DID) {
121 source = 'Bluesky Moderation Service'
122 } else {
123 source = cause.label.src
124 }
125 }
126 if (def.identifier === 'porn' || def.identifier === 'sexual') {
127 strings.name = 'Adult Content'
128 }
129
130 return {
131 icon:
132 def.identifier === '!no-unauthenticated'
133 ? EyeSlash
134 : def.severity === 'alert'
135 ? Warning
136 : CircleInfo,
137 name: strings.name,
138 description: strings.description,
139 source,
140 sourceType: cause.source.type,
141 }
142 }
143 // should never happen
144 return {
145 icon: CircleInfo,
146 name: '',
147 description: ``,
148 }
149 }, [labelDefs, labelers, globalLabelStrings, cause, _, i18n.locale])
150}