Add special handling of the mod authorities

This commit is contained in:
Paul Frazee
2024-03-10 12:47:20 -07:00
parent f0144e7439
commit 8c4b9aebe2
3 changed files with 85 additions and 51 deletions
+29
View File
@@ -3,6 +3,9 @@ import {
ModerationUI, ModerationUI,
InterpretedLabelValueDefinition, InterpretedLabelValueDefinition,
LABELS, LABELS,
AppBskyLabelerDefs,
BskyAgent,
ModerationOpts,
} from '@atproto/api' } from '@atproto/api'
import {sanitizeDisplayName} from '#/lib/strings/display-names' import {sanitizeDisplayName} from '#/lib/strings/display-names'
@@ -50,3 +53,29 @@ export function lookupLabelValueDefinition(
} }
return def 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)
}
@@ -9,6 +9,7 @@ import {
} from '@atproto/api' } from '@atproto/api'
import {Trans, msg} from '@lingui/macro' import {Trans, msg} from '@lingui/macro'
import {useLingui} from '@lingui/react' import {useLingui} from '@lingui/react'
import {RichText} from '#/components/RichText' import {RichText} from '#/components/RichText'
import {useModalControls} from '#/state/modals' import {useModalControls} from '#/state/modals'
import {usePreferencesQuery} from '#/state/queries/preferences' import {usePreferencesQuery} from '#/state/queries/preferences'
@@ -21,6 +22,7 @@ import {useLikeMutation, useUnlikeMutation} from '#/state/queries/like'
import {logger} from '#/logger' import {logger} from '#/logger'
import {Haptics} from '#/lib/haptics' import {Haptics} from '#/lib/haptics'
import {pluralize} from '#/lib/strings/helpers' import {pluralize} from '#/lib/strings/helpers'
import {isModAuthority} from '#/lib/moderation'
import {atoms as a, useTheme} from '#/alf' import {atoms as a, useTheme} from '#/alf'
import {Button, ButtonText} from '#/components/Button' import {Button, ButtonText} from '#/components/Button'
@@ -172,7 +174,7 @@ let ProfileHeaderLabeler = ({
<Trans>Edit Profile</Trans> <Trans>Edit Profile</Trans>
</ButtonText> </ButtonText>
</Button> </Button>
) : ( ) : !isModAuthority(profile.did) ? (
<> <>
<Button <Button
testID="toggleSubscribeBtn" testID="toggleSubscribeBtn"
@@ -197,7 +199,7 @@ let ProfileHeaderLabeler = ({
</ButtonText> </ButtonText>
</Button> </Button>
</> </>
)} ) : null}
<ProfileHeaderDropdownBtn profile={profile} /> <ProfileHeaderDropdownBtn profile={profile} />
</View> </View>
<View style={[a.flex_col, a.gap_xs, a.pb_md]}> <View style={[a.flex_col, a.gap_xs, a.pb_md]}>
@@ -217,6 +219,7 @@ let ProfileHeaderLabeler = ({
/> />
</View> </View>
) : undefined} ) : undefined}
{!isModAuthority(profile.did) && (
<View style={[a.flex_row, a.gap_xs, a.align_center, a.pt_lg]}> <View style={[a.flex_row, a.gap_xs, a.align_center, a.pt_lg]}>
<Button <Button
testID="toggleLikeBtn" testID="toggleLikeBtn"
@@ -244,7 +247,10 @@ let ProfileHeaderLabeler = ({
}} }}
size="tiny" size="tiny"
label={_( label={_(
msg`Liked by ${likeCount} ${pluralize(likeCount, 'user')}`, msg`Liked by ${likeCount} ${pluralize(
likeCount,
'user',
)}`,
)}> )}>
{({hovered, focused, pressed}) => ( {({hovered, focused, pressed}) => (
<Text <Text
@@ -263,6 +269,7 @@ let ProfileHeaderLabeler = ({
</Link> </Link>
)} )}
</View> </View>
)}
</> </>
)} )}
</View> </View>
+2 -4
View File
@@ -12,7 +12,7 @@ import {useSafeAreaFrame} from 'react-native-safe-area-context'
import {useScrollHandlers} from '#/lib/ScrollContext' import {useScrollHandlers} from '#/lib/ScrollContext'
import {useAnimatedScrollHandler} from '#/lib/hooks/useAnimatedScrollHandler_FIXED' 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 {ListRef} from '#/view/com/util/List'
import {SectionRef} from './types' import {SectionRef} from './types'
import {isNative} from '#/platform/detection' import {isNative} from '#/platform/detection'
@@ -127,9 +127,7 @@ export function ProfileLabelsSectionInner({
}) })
const {labelValues} = labelerInfo.policies const {labelValues} = labelerInfo.policies
const isSubscribed = moderationOpts.prefs.labelers.find( const isSubscribed = isLabelerSubscribed(labelerInfo, moderationOpts)
l => l.did === labelerInfo.creator.did,
)
const labelDefs = React.useMemo(() => { const labelDefs = React.useMemo(() => {
const customDefs = interpretLabelValueDefinitions(labelerInfo) const customDefs = interpretLabelValueDefinitions(labelerInfo)
return labelValues return labelValues