Extract shared filterUserFacingLabels helper

PostAlerts and LabelsOnMe carried byte-for-byte copies of the same
filter excluding system labels and the user's own bot self-label.
Consolidate into one helper in lib/moderation so the two surfaces
cannot drift.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Eric Bailey
2026-07-09 18:42:14 -05:00
parent 4084a5e63a
commit 6fb153c034
3 changed files with 34 additions and 19 deletions
+2 -5
View File
@@ -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
}
+17 -14
View File
@@ -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 (
+15
View File
@@ -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,