From 2e74f9839246c7dee718ac8bc12c22395ff002b5 Mon Sep 17 00:00:00 2001
From: Hailey <me@haileyok.com>
Date: Wed, 16 Oct 2024 19:17:22 -0700
Subject: Add graphic media self label (#5758)

Co-authored-by: Samuel Newman <mozzius@protonmail.com>
---
 src/components/moderation/ContentHider.tsx | 68 ++++++++++++++++++++++++++++--
 1 file changed, 65 insertions(+), 3 deletions(-)

(limited to 'src/components/moderation/ContentHider.tsx')

diff --git a/src/components/moderation/ContentHider.tsx b/src/components/moderation/ContentHider.tsx
index bf9bae517..67aef67b4 100644
--- a/src/components/moderation/ContentHider.tsx
+++ b/src/components/moderation/ContentHider.tsx
@@ -4,9 +4,12 @@ import {ModerationUI} from '@atproto/api'
 import {msg, Trans} from '@lingui/macro'
 import {useLingui} from '@lingui/react'
 
-import {isJustAMute} from '#/lib/moderation'
+import {ADULT_CONTENT_LABELS, isJustAMute} from '#/lib/moderation'
+import {useGlobalLabelStrings} from '#/lib/moderation/useGlobalLabelStrings'
+import {getDefinition, getLabelStrings} from '#/lib/moderation/useLabelInfo'
 import {useModerationCauseDescription} from '#/lib/moderation/useModerationCauseDescription'
 import {sanitizeDisplayName} from '#/lib/strings/display-names'
+import {useLabelDefinitions} from '#/state/preferences'
 import {atoms as a, useBreakpoints, useTheme, web} from '#/alf'
 import {Button} from '#/components/Button'
 import {
@@ -34,10 +37,68 @@ export function ContentHider({
   const {gtMobile} = useBreakpoints()
   const [override, setOverride] = React.useState(false)
   const control = useModerationDetailsDialogControl()
+  const {labelDefs} = useLabelDefinitions()
+  const globalLabelStrings = useGlobalLabelStrings()
+  const {i18n} = useLingui()
 
   const blur = modui?.blurs[0]
   const desc = useModerationCauseDescription(blur)
 
+  const labelName = React.useMemo(() => {
+    if (!modui?.blurs || !blur) {
+      return undefined
+    }
+    if (
+      blur.type !== 'label' ||
+      (blur.type === 'label' && blur.source.type !== 'user')
+    ) {
+      return desc.name
+    }
+
+    let hasAdultContentLabel = false
+    const selfBlurNames = modui.blurs
+      .filter(cause => {
+        if (cause.type !== 'label') {
+          return false
+        }
+        if (cause.source.type !== 'user') {
+          return false
+        }
+        if (ADULT_CONTENT_LABELS.includes(cause.label.val)) {
+          if (hasAdultContentLabel) {
+            return false
+          }
+          hasAdultContentLabel = true
+        }
+        return true
+      })
+      .slice(0, 2)
+      .map(cause => {
+        if (cause.type !== 'label') {
+          return
+        }
+
+        const def = cause.labelDef || getDefinition(labelDefs, cause.label)
+        if (def.identifier === 'porn' || def.identifier === 'sexual') {
+          return _(msg`Adult Content`)
+        }
+        return getLabelStrings(i18n.locale, globalLabelStrings, def).name
+      })
+
+    if (selfBlurNames.length === 0) {
+      return desc.name
+    }
+    return [...new Set(selfBlurNames)].join(', ')
+  }, [
+    _,
+    modui?.blurs,
+    blur,
+    desc.name,
+    labelDefs,
+    i18n.locale,
+    globalLabelStrings,
+  ])
+
   if (!blur || (ignoreMute && isJustAMute(modui))) {
     return (
       <View testID={testID} style={style}>
@@ -99,8 +160,9 @@ export function ContentHider({
                 web({
                   marginBottom: 1,
                 }),
-              ]}>
-              {desc.name}
+              ]}
+              numberOfLines={2}>
+              {labelName}
             </Text>
             {!modui.noOverride && (
               <Text
-- 
cgit 1.4.1

