diff --git a/src/components/moderation/LabelsOnMe.tsx b/src/components/moderation/LabelsOnMe.tsx index 84edb9b4b8..85cb1e4a3a 100644 --- a/src/components/moderation/LabelsOnMe.tsx +++ b/src/components/moderation/LabelsOnMe.tsx @@ -4,6 +4,7 @@ import {msg} from '@lingui/core/macro' import {useLingui} from '@lingui/react' import {Plural} from '@lingui/react/macro' +import {filterUserFacingLabels} from '#/lib/moderation' import {useSession} from '#/state/session' import {atoms as a} from '#/alf' import { @@ -34,11 +35,7 @@ export function LabelsOnMe({ if (!labels || !currentAccount) { return null } - labels = labels.filter( - l => - !l.val.startsWith('!') && - !(l.val === 'bot' && l.src === currentAccount.did), - ) + labels = filterUserFacingLabels(labels, currentAccount.did) if (!labels.length) { return null } diff --git a/src/components/moderation/PostAlerts.tsx b/src/components/moderation/PostAlerts.tsx index dc3dd7fab8..daeedcfa6a 100644 --- a/src/components/moderation/PostAlerts.tsx +++ b/src/components/moderation/PostAlerts.tsx @@ -8,7 +8,11 @@ import { import {plural} from '@lingui/core/macro' import {useLingui} from '@lingui/react/macro' -import {getModerationCauseKey, unique} from '#/lib/moderation' +import { + filterUserFacingLabels, + getModerationCauseKey, + unique, +} from '#/lib/moderation' import {useSession} from '#/state/session' import {atoms as a} from '#/alf' import { @@ -48,21 +52,20 @@ export function PostAlerts({ /* * Labels that the moderation system already surfaces in this context - * whether as an alert, an inform, or a blur handled by ContentHider - should - * not be repeated in the "+n" pill. System labels and the author's own - * "bot" self-label are excluded the same way LabelsOnMe excludes them. + * not be repeated in the "+n" pill. */ const shownCauses = [...alerts, ...informs, ...modui.blurs] - const additionalLabels = allLabels.filter( - label => - !label.val.startsWith('!') && - !(label.val === 'bot' && label.src === currentAccount?.did) && - shownCauses.every( - cause => - cause.type !== 'label' || - cause.label.val !== label.val || - cause.label.src !== label.src || - cause.label.uri !== label.uri, - ), + const additionalLabels = filterUserFacingLabels( + allLabels, + currentAccount?.did, + ).filter(label => + shownCauses.every( + cause => + cause.type !== 'label' || + cause.label.val !== label.val || + cause.label.src !== label.src || + cause.label.uri !== label.uri, + ), ) if ( diff --git a/src/lib/moderation.ts b/src/lib/moderation.ts index 2fb37009e2..0d2e3c4dbd 100644 --- a/src/lib/moderation.ts +++ b/src/lib/moderation.ts @@ -58,6 +58,21 @@ export function labelIsHideableOffense( return ['!hide', '!takedown'].includes(label.val) } +/** + * Filters out labels that are not user-facing: system labels (val prefixed + * with `!`) and the user's own "bot" self-label. + */ +export function filterUserFacingLabels( + labels: ComAtprotoLabelDefs.Label[], + currentAccountDid: string | undefined, +): ComAtprotoLabelDefs.Label[] { + return labels.filter( + label => + !label.val.startsWith('!') && + !(label.val === 'bot' && label.src === currentAccountDid), + ) +} + export function getLabelingServiceTitle({ displayName, handle,