Add special handling of the mod authorities
This commit is contained in:
@@ -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,52 +219,57 @@ let ProfileHeaderLabeler = ({
|
|||||||
/>
|
/>
|
||||||
</View>
|
</View>
|
||||||
) : undefined}
|
) : undefined}
|
||||||
<View style={[a.flex_row, a.gap_xs, a.align_center, a.pt_lg]}>
|
{!isModAuthority(profile.did) && (
|
||||||
<Button
|
<View style={[a.flex_row, a.gap_xs, a.align_center, a.pt_lg]}>
|
||||||
testID="toggleLikeBtn"
|
<Button
|
||||||
size="small"
|
testID="toggleLikeBtn"
|
||||||
color="secondary"
|
size="small"
|
||||||
variant="solid"
|
color="secondary"
|
||||||
shape="round"
|
variant="solid"
|
||||||
label={_(msg`Like this feed`)}
|
shape="round"
|
||||||
disabled={!hasSession || isLikePending || isUnlikePending}
|
label={_(msg`Like this feed`)}
|
||||||
onPress={onToggleLiked}>
|
disabled={!hasSession || isLikePending || isUnlikePending}
|
||||||
{likeUri ? (
|
onPress={onToggleLiked}>
|
||||||
<HeartFilled fill={t.palette.negative_400} />
|
{likeUri ? (
|
||||||
) : (
|
<HeartFilled fill={t.palette.negative_400} />
|
||||||
<Heart fill={t.atoms.text_contrast_medium.color} />
|
) : (
|
||||||
)}
|
<Heart fill={t.atoms.text_contrast_medium.color} />
|
||||||
</Button>
|
|
||||||
|
|
||||||
{typeof likeCount === 'number' && (
|
|
||||||
<Link
|
|
||||||
to={{
|
|
||||||
screen: 'ProfileLabelerLikedBy',
|
|
||||||
params: {
|
|
||||||
name: labeler.creator.handle || labeler.creator.did,
|
|
||||||
},
|
|
||||||
}}
|
|
||||||
size="tiny"
|
|
||||||
label={_(
|
|
||||||
msg`Liked by ${likeCount} ${pluralize(likeCount, 'user')}`,
|
|
||||||
)}>
|
|
||||||
{({hovered, focused, pressed}) => (
|
|
||||||
<Text
|
|
||||||
style={[
|
|
||||||
a.font_bold,
|
|
||||||
a.text_sm,
|
|
||||||
t.atoms.text_contrast_medium,
|
|
||||||
(hovered || focused || pressed) &&
|
|
||||||
t.atoms.text_contrast_high,
|
|
||||||
]}>
|
|
||||||
<Trans>
|
|
||||||
Liked by {likeCount} {pluralize(likeCount, 'user')}
|
|
||||||
</Trans>
|
|
||||||
</Text>
|
|
||||||
)}
|
)}
|
||||||
</Link>
|
</Button>
|
||||||
)}
|
|
||||||
</View>
|
{typeof likeCount === 'number' && (
|
||||||
|
<Link
|
||||||
|
to={{
|
||||||
|
screen: 'ProfileLabelerLikedBy',
|
||||||
|
params: {
|
||||||
|
name: labeler.creator.handle || labeler.creator.did,
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
size="tiny"
|
||||||
|
label={_(
|
||||||
|
msg`Liked by ${likeCount} ${pluralize(
|
||||||
|
likeCount,
|
||||||
|
'user',
|
||||||
|
)}`,
|
||||||
|
)}>
|
||||||
|
{({hovered, focused, pressed}) => (
|
||||||
|
<Text
|
||||||
|
style={[
|
||||||
|
a.font_bold,
|
||||||
|
a.text_sm,
|
||||||
|
t.atoms.text_contrast_medium,
|
||||||
|
(hovered || focused || pressed) &&
|
||||||
|
t.atoms.text_contrast_high,
|
||||||
|
]}>
|
||||||
|
<Trans>
|
||||||
|
Liked by {likeCount} {pluralize(likeCount, 'user')}
|
||||||
|
</Trans>
|
||||||
|
</Text>
|
||||||
|
)}
|
||||||
|
</Link>
|
||||||
|
)}
|
||||||
|
</View>
|
||||||
|
)}
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</View>
|
</View>
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user