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