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 {useLingui} from '@lingui/react'
|
||||||
import {Plural} from '@lingui/react/macro'
|
import {Plural} from '@lingui/react/macro'
|
||||||
|
|
||||||
|
import {filterUserFacingLabels} from '#/lib/moderation'
|
||||||
import {useSession} from '#/state/session'
|
import {useSession} from '#/state/session'
|
||||||
import {atoms as a} from '#/alf'
|
import {atoms as a} from '#/alf'
|
||||||
import {
|
import {
|
||||||
@@ -34,11 +35,7 @@ export function LabelsOnMe({
|
|||||||
if (!labels || !currentAccount) {
|
if (!labels || !currentAccount) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
labels = labels.filter(
|
labels = filterUserFacingLabels(labels, currentAccount.did)
|
||||||
l =>
|
|
||||||
!l.val.startsWith('!') &&
|
|
||||||
!(l.val === 'bot' && l.src === currentAccount.did),
|
|
||||||
)
|
|
||||||
if (!labels.length) {
|
if (!labels.length) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,11 @@ import {
|
|||||||
import {plural} from '@lingui/core/macro'
|
import {plural} from '@lingui/core/macro'
|
||||||
import {useLingui} from '@lingui/react/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 {useSession} from '#/state/session'
|
||||||
import {atoms as a} from '#/alf'
|
import {atoms as a} from '#/alf'
|
||||||
import {
|
import {
|
||||||
@@ -48,21 +52,20 @@ export function PostAlerts({
|
|||||||
/*
|
/*
|
||||||
* Labels that the moderation system already surfaces in this context -
|
* Labels that the moderation system already surfaces in this context -
|
||||||
* whether as an alert, an inform, or a blur handled by ContentHider - should
|
* 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
|
* not be repeated in the "+n" pill.
|
||||||
* "bot" self-label are excluded the same way LabelsOnMe excludes them.
|
|
||||||
*/
|
*/
|
||||||
const shownCauses = [...alerts, ...informs, ...modui.blurs]
|
const shownCauses = [...alerts, ...informs, ...modui.blurs]
|
||||||
const additionalLabels = allLabels.filter(
|
const additionalLabels = filterUserFacingLabels(
|
||||||
label =>
|
allLabels,
|
||||||
!label.val.startsWith('!') &&
|
currentAccount?.did,
|
||||||
!(label.val === 'bot' && label.src === currentAccount?.did) &&
|
).filter(label =>
|
||||||
shownCauses.every(
|
shownCauses.every(
|
||||||
cause =>
|
cause =>
|
||||||
cause.type !== 'label' ||
|
cause.type !== 'label' ||
|
||||||
cause.label.val !== label.val ||
|
cause.label.val !== label.val ||
|
||||||
cause.label.src !== label.src ||
|
cause.label.src !== label.src ||
|
||||||
cause.label.uri !== label.uri,
|
cause.label.uri !== label.uri,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
if (
|
if (
|
||||||
|
|||||||
@@ -58,6 +58,21 @@ export function labelIsHideableOffense(
|
|||||||
return ['!hide', '!takedown'].includes(label.val)
|
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({
|
export function getLabelingServiceTitle({
|
||||||
displayName,
|
displayName,
|
||||||
handle,
|
handle,
|
||||||
|
|||||||
Reference in New Issue
Block a user