Skip to content

Commit

Permalink
Update label target=profile behaviors: dont filter content on hide, d…
Browse files Browse the repository at this point in the history
…ont blur display names, but do show the info cards
  • Loading branch information
pfrazee committed Mar 9, 2024
1 parent 4933d0e commit 3c7f587
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 77 deletions.
10 changes: 9 additions & 1 deletion packages/api/src/moderation/decision.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,14 @@ export class ModerationDecision {
ui.informs.push(cause)
}
} else if (cause.type === 'label') {
if (context === 'profileList' || context === 'contentList') {
if (context === 'profileList' && cause.target === 'account') {
if (cause.setting === 'hide') {
ui.filters.push(cause)
}
} else if (
context === 'contentList' &&
(cause.target === 'account' || cause.target === 'content')
) {
if (cause.setting === 'hide') {
ui.filters.push(cause)
}
Expand Down Expand Up @@ -298,6 +305,7 @@ export class ModerationDecision {
: { type: 'labeler', did: labeler.did },
label,
labelDef,
target,
setting: labelPref,
behavior: labelDef.behaviors[target] || NOOP_BEHAVIOR,
noOverride,
Expand Down
1 change: 1 addition & 0 deletions packages/api/src/moderation/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ export type ModerationCause =
source: ModerationCauseSource
label: Label
labelDef: InterpretedLabelValueDefinition
target: LabelTarget
setting: LabelPreference
behavior: ModerationBehavior
noOverride: boolean
Expand Down
8 changes: 4 additions & 4 deletions packages/api/src/moderation/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,8 @@ export function interpretLabelValueDefinition(
behaviors.account.contentList = 'blur'
behaviors.account.contentView = def.adultOnly ? 'blur' : alertOrInform
// target=profile, blurs=content
behaviors.account.profileView = alertOrInform
behaviors.profile.avatar = 'blur'
behaviors.profile.banner = 'blur'
behaviors.profile.displayName = 'blur'
behaviors.profile.profileList = alertOrInform
behaviors.profile.profileView = alertOrInform
// target=content, blurs=content
behaviors.content.contentList = 'blur'
behaviors.content.contentView = def.adultOnly ? 'blur' : alertOrInform
Expand All @@ -62,6 +60,7 @@ export function interpretLabelValueDefinition(
behaviors.account.banner = 'blur'
behaviors.account.contentMedia = 'blur'
// target=profile, blurs=media
behaviors.profile.profileList = alertOrInform
behaviors.profile.profileView = alertOrInform
behaviors.profile.avatar = 'blur'
behaviors.profile.banner = 'blur'
Expand All @@ -74,6 +73,7 @@ export function interpretLabelValueDefinition(
behaviors.account.contentList = alertOrInform
behaviors.account.contentView = alertOrInform
// target=profile, blurs=none
behaviors.profile.profileList = alertOrInform
behaviors.profile.profileView = alertOrInform
// target=content, blurs=none
behaviors.content.contentList = alertOrInform
Expand Down
16 changes: 5 additions & 11 deletions packages/api/tests/moderation-behaviors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,9 @@ const SCENARIOS: SuiteScenarios = {
author: 'alice',
labels: { profile: ['!hide'] },
behaviors: {
profileList: ['filter'],
avatar: ['blur', 'noOverride'],
banner: ['blur', 'noOverride'],
displayName: ['blur', 'noOverride'],
contentList: ['filter'],
},
},
"Imperative label ('!hide') on post": {
Expand All @@ -155,7 +153,6 @@ const SCENARIOS: SuiteScenarios = {
avatar: ['blur', 'noOverride'],
banner: ['blur', 'noOverride'],
displayName: ['blur', 'noOverride'],
contentList: ['filter'],
},
},
"Imperative label ('!hide') on author account": {
Expand Down Expand Up @@ -354,10 +351,8 @@ const SCENARIOS: SuiteScenarios = {
author: 'alice',
labels: { profile: ['porn'] },
behaviors: {
profileList: ['filter'],
avatar: ['blur'],
banner: ['blur'],
contentList: ['filter'],
},
},
"Blur-media label ('porn') on post (hide)": {
Expand All @@ -378,7 +373,6 @@ const SCENARIOS: SuiteScenarios = {
behaviors: {
avatar: ['blur'],
banner: ['blur'],
contentList: ['filter'],
},
},
"Blur-media label ('porn') on author account (hide)": {
Expand Down Expand Up @@ -498,10 +492,10 @@ const SCENARIOS: SuiteScenarios = {
author: 'alice',
labels: { profile: ['porn'] },
behaviors: {
profileList: ['filter'],
profileList: [],
avatar: ['blur', 'noOverride'],
banner: ['blur', 'noOverride'],
contentList: ['filter'],
contentList: [],
},
},
'Adult-only label on post when adult content is disabled': {
Expand All @@ -522,7 +516,7 @@ const SCENARIOS: SuiteScenarios = {
behaviors: {
avatar: ['blur', 'noOverride'],
banner: ['blur', 'noOverride'],
contentList: ['filter'],
contentList: [],
},
},
'Adult-only label on author account when adult content is disabled': {
Expand Down Expand Up @@ -793,12 +787,12 @@ const SCENARIOS: SuiteScenarios = {
author: 'alice',
labels: { account: ['!warn'], profile: ['!hide'] },
behaviors: {
profileList: ['filter', 'blur'],
profileList: ['blur'],
profileView: ['blur'],
avatar: ['blur', 'noOverride'],
banner: ['blur', 'noOverride'],
displayName: ['blur', 'noOverride'],
contentList: ['filter', 'blur'],
contentList: ['blur'],
contentView: ['blur'],
},
},
Expand Down
89 changes: 31 additions & 58 deletions packages/api/tests/moderation-custom-labels.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,10 @@ const TESTS: Scenario[] = [
contentView: ['alert'],
},
profile: {
profileList: ['filter'],
avatar: ['blur'],
banner: ['blur'],
displayName: ['blur'],
contentList: ['filter'],
profileList: ['alert'],
profileView: ['alert'],
},
post: {
profileList: ['filter'],
contentList: ['filter', 'blur'],
contentView: ['alert'],
},
Expand All @@ -60,14 +56,10 @@ const TESTS: Scenario[] = [
contentView: ['inform'],
},
profile: {
profileList: ['filter'],
avatar: ['blur'],
banner: ['blur'],
displayName: ['blur'],
contentList: ['filter'],
profileList: ['inform'],
profileView: ['inform'],
},
post: {
profileList: ['filter'],
contentList: ['filter', 'blur'],
contentView: ['inform'],
},
Expand All @@ -82,14 +74,10 @@ const TESTS: Scenario[] = [
contentView: [],
},
profile: {
profileList: ['filter'],
avatar: ['blur'],
banner: ['blur'],
displayName: ['blur'],
contentList: ['filter'],
profileList: [],
profileView: [],
},
post: {
profileList: ['filter'],
contentList: ['filter', 'blur'],
contentView: [],
},
Expand All @@ -107,14 +95,12 @@ const TESTS: Scenario[] = [
contentMedia: ['blur'],
},
profile: {
profileList: ['filter'],
profileList: ['alert'],
profileView: ['alert'],
avatar: ['blur'],
banner: ['blur'],
contentList: ['filter'],
},
post: {
profileList: ['filter'],
contentList: ['filter'],
contentMedia: ['blur'],
},
Expand All @@ -131,14 +117,12 @@ const TESTS: Scenario[] = [
contentMedia: ['blur'],
},
profile: {
profileList: ['filter'],
profileList: ['inform'],
profileView: ['inform'],
avatar: ['blur'],
banner: ['blur'],
contentList: ['filter'],
},
post: {
profileList: ['filter'],
contentList: ['filter'],
contentMedia: ['blur'],
},
Expand All @@ -154,13 +138,10 @@ const TESTS: Scenario[] = [
contentMedia: ['blur'],
},
profile: {
profileList: ['filter'],
avatar: ['blur'],
banner: ['blur'],
contentList: ['filter'],
},
post: {
profileList: ['filter'],
contentList: ['filter'],
contentMedia: ['blur'],
},
Expand All @@ -176,12 +157,10 @@ const TESTS: Scenario[] = [
contentView: ['alert'],
},
profile: {
profileList: ['filter'],
profileList: ['alert'],
profileView: ['alert'],
contentList: ['filter'],
},
post: {
profileList: ['filter'],
contentList: ['filter', 'alert'],
contentView: ['alert'],
},
Expand All @@ -196,12 +175,10 @@ const TESTS: Scenario[] = [
contentView: ['inform'],
},
profile: {
profileList: ['filter'],
profileList: ['inform'],
profileView: ['inform'],
contentList: ['filter'],
},
post: {
profileList: ['filter'],
contentList: ['filter', 'inform'],
contentView: ['inform'],
},
Expand All @@ -213,12 +190,8 @@ const TESTS: Scenario[] = [
profileList: ['filter'],
contentList: ['filter'],
},
profile: {
profileList: ['filter'],
contentList: ['filter'],
},
profile: {},
post: {
profileList: ['filter'],
contentList: ['filter'],
},
},
Expand Down Expand Up @@ -300,27 +273,27 @@ describe('Moderation: custom labels', () => {
}),
modOpts(blurs, severity),
)
expect(res.ui('profileList')).toBeModerationResult(
expected.profileList || [],
)
expect(res.ui('profileView')).toBeModerationResult(
expected.profileView || [],
)
expect(res.ui('avatar')).toBeModerationResult(expected.avatar || [])
expect(res.ui('banner')).toBeModerationResult(expected.banner || [])
expect(res.ui('displayName')).toBeModerationResult(
expected.displayName || [],
)
expect(res.ui('contentList')).toBeModerationResult(
expected.contentList || [],
)
expect(res.ui('contentView')).toBeModerationResult(
expected.contentView || [],
)
expect(res.ui('contentMedia')).toBeModerationResult(
expected.contentMedia || [],
)
}
expect(res.ui('profileList')).toBeModerationResult(
expected.profileList || [],
)
expect(res.ui('profileView')).toBeModerationResult(
expected.profileView || [],
)
expect(res.ui('avatar')).toBeModerationResult(expected.avatar || [])
expect(res.ui('banner')).toBeModerationResult(expected.banner || [])
expect(res.ui('displayName')).toBeModerationResult(
expected.displayName || [],
)
expect(res.ui('contentList')).toBeModerationResult(
expected.contentList || [],
)
expect(res.ui('contentView')).toBeModerationResult(
expected.contentView || [],
)
expect(res.ui('contentMedia')).toBeModerationResult(
expected.contentMedia || [],
)
},
)
})
Expand Down
6 changes: 3 additions & 3 deletions packages/api/tests/moderation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ describe('Moderation', () => {
modOpts,
)

expect(res.ui('profileList')).toBeModerationResult(['filter'])
expect(res.ui('profileList')).toBeModerationResult([])
expect(res.ui('profileView')).toBeModerationResult([])
expect(res.ui('avatar')).toBeModerationResult([])
expect(res.ui('banner')).toBeModerationResult([])
Expand Down Expand Up @@ -512,7 +512,7 @@ describe('Moderation', () => {
modOpts,
)

expect(res1.ui('profileList')).toBeModerationResult(['filter'])
expect(res1.ui('profileList')).toBeModerationResult([])
expect(res1.ui('profileView')).toBeModerationResult([])
expect(res1.ui('avatar')).toBeModerationResult([])
expect(res1.ui('banner')).toBeModerationResult([])
Expand Down Expand Up @@ -637,7 +637,7 @@ describe('Moderation', () => {
modOpts,
)

expect(res.ui('profileList')).toBeModerationResult(['filter'])
expect(res.ui('profileList')).toBeModerationResult([])
expect(res.ui('profileView')).toBeModerationResult([])
expect(res.ui('avatar')).toBeModerationResult([])
expect(res.ui('banner')).toBeModerationResult([])
Expand Down

0 comments on commit 3c7f587

Please sign in to comment.