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:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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,14 +52,13 @@ 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) &&
|
||||
const additionalLabels = filterUserFacingLabels(
|
||||
allLabels,
|
||||
currentAccount?.did,
|
||||
).filter(label =>
|
||||
shownCauses.every(
|
||||
cause =>
|
||||
cause.type !== 'label' ||
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user