diff --git a/src/lib/moderation.ts b/src/lib/moderation.ts index 2c34881112..6614a2edb8 100644 --- a/src/lib/moderation.ts +++ b/src/lib/moderation.ts @@ -3,6 +3,9 @@ import { ModerationUI, InterpretedLabelValueDefinition, LABELS, + AppBskyLabelerDefs, + BskyAgent, + ModerationOpts, } from '@atproto/api' import {sanitizeDisplayName} from '#/lib/strings/display-names' @@ -50,3 +53,29 @@ export function lookupLabelValueDefinition( } return def } + +export function isModAuthority( + labeler: + | string + | AppBskyLabelerDefs.LabelerView + | AppBskyLabelerDefs.LabelerViewDetailed, +): boolean { + if (typeof labeler === 'string') { + return BskyAgent.modAuthoritiesHeader.includes(labeler) + } + return BskyAgent.modAuthoritiesHeader.includes(labeler.creator.did) +} + +export function isLabelerSubscribed( + labeler: + | string + | AppBskyLabelerDefs.LabelerView + | AppBskyLabelerDefs.LabelerViewDetailed, + modOpts: ModerationOpts, +) { + labeler = typeof labeler === 'string' ? labeler : labeler.creator.did + if (isModAuthority(labeler)) { + return true + } + return modOpts.prefs.labelers.find(l => l.did === labeler) +} diff --git a/src/screens/Profile/Header/ProfileHeaderLabeler.tsx b/src/screens/Profile/Header/ProfileHeaderLabeler.tsx index c7ca56e598..26f8433d26 100644 --- a/src/screens/Profile/Header/ProfileHeaderLabeler.tsx +++ b/src/screens/Profile/Header/ProfileHeaderLabeler.tsx @@ -9,6 +9,7 @@ import { } from '@atproto/api' import {Trans, msg} from '@lingui/macro' import {useLingui} from '@lingui/react' + import {RichText} from '#/components/RichText' import {useModalControls} from '#/state/modals' import {usePreferencesQuery} from '#/state/queries/preferences' @@ -21,6 +22,7 @@ import {useLikeMutation, useUnlikeMutation} from '#/state/queries/like' import {logger} from '#/logger' import {Haptics} from '#/lib/haptics' import {pluralize} from '#/lib/strings/helpers' +import {isModAuthority} from '#/lib/moderation' import {atoms as a, useTheme} from '#/alf' import {Button, ButtonText} from '#/components/Button' @@ -172,7 +174,7 @@ let ProfileHeaderLabeler = ({ Edit Profile - ) : ( + ) : !isModAuthority(profile.did) ? ( <> - )} + ) : null} @@ -217,52 +219,57 @@ let ProfileHeaderLabeler = ({ /> ) : undefined} - - - - {typeof likeCount === 'number' && ( - - {({hovered, focused, pressed}) => ( - - - Liked by {likeCount} {pluralize(likeCount, 'user')} - - + {!isModAuthority(profile.did) && ( + + + + {typeof likeCount === 'number' && ( + + {({hovered, focused, pressed}) => ( + + + Liked by {likeCount} {pluralize(likeCount, 'user')} + + + )} + + )} + + )} )} diff --git a/src/screens/Profile/Sections/Labels.tsx b/src/screens/Profile/Sections/Labels.tsx index 357a0eeb8f..fbb3c6ea29 100644 --- a/src/screens/Profile/Sections/Labels.tsx +++ b/src/screens/Profile/Sections/Labels.tsx @@ -12,7 +12,7 @@ import {useSafeAreaFrame} from 'react-native-safe-area-context' import {useScrollHandlers} from '#/lib/ScrollContext' import {useAnimatedScrollHandler} from '#/lib/hooks/useAnimatedScrollHandler_FIXED' -import {lookupLabelValueDefinition} from '#/lib/moderation' +import {isLabelerSubscribed, lookupLabelValueDefinition} from '#/lib/moderation' import {ListRef} from '#/view/com/util/List' import {SectionRef} from './types' import {isNative} from '#/platform/detection' @@ -127,9 +127,7 @@ export function ProfileLabelsSectionInner({ }) const {labelValues} = labelerInfo.policies - const isSubscribed = moderationOpts.prefs.labelers.find( - l => l.did === labelerInfo.creator.did, - ) + const isSubscribed = isLabelerSubscribed(labelerInfo, moderationOpts) const labelDefs = React.useMemo(() => { const customDefs = interpretLabelValueDefinitions(labelerInfo) return labelValues