diff --git a/lexicons/app/bsky/actor/defs.json b/lexicons/app/bsky/actor/defs.json index c0dd41d31f2..b3cfe2e1967 100644 --- a/lexicons/app/bsky/actor/defs.json +++ b/lexicons/app/bsky/actor/defs.json @@ -288,20 +288,20 @@ } } }, - "modsPref": { + "labelersPref": { "type": "object", - "required": ["mods"], + "required": ["labelers"], "properties": { - "mods": { + "labelers": { "type": "array", "items": { "type": "ref", - "ref": "#modPrefItem" + "ref": "#labelerPrefItem" } } } }, - "modPrefItem": { + "labelerPrefItem": { "type": "object", "required": ["did"], "properties": { diff --git a/packages/api/src/bsky-agent.ts b/packages/api/src/bsky-agent.ts index 38c18bcec45..4dfd64efc75 100644 --- a/packages/api/src/bsky-agent.ts +++ b/packages/api/src/bsky-agent.ts @@ -329,7 +329,7 @@ export class BskyAgent extends AtpAgent { moderationPrefs: { adultContentEnabled: false, labels: { ...DEFAULT_LABEL_SETTINGS }, - mods: [], + labelers: [], }, birthDate: undefined, interests: { @@ -355,12 +355,12 @@ export class BskyAgent extends AtpAgent { const adjustedPref = adjustLegacyContentLabelPref(pref) labelPrefs.push(adjustedPref) } else if ( - AppBskyActorDefs.isModsPref(pref) && - AppBskyActorDefs.validateModsPref(pref).success + AppBskyActorDefs.isLabelersPref(pref) && + AppBskyActorDefs.validateLabelersPref(pref).success ) { - // mods preferences - prefs.moderationPrefs.mods = pref.mods.map((mod) => ({ - ...mod, + // labelers preferences + prefs.moderationPrefs.labelers = pref.labelers.map((labeler) => ({ + ...labeler, labels: {}, })) } else if ( @@ -421,11 +421,11 @@ export class BskyAgent extends AtpAgent { // apply the label prefs for (const pref of labelPrefs) { if (pref.labelerDid) { - const mod = prefs.moderationPrefs.mods.find( - (mod) => mod.did === pref.labelerDid, + const labeler = prefs.moderationPrefs.labelers.find( + (labeler) => labeler.did === pref.labelerDid, ) - if (!mod) continue - mod.labels[pref.label] = pref.visibility as LabelPreference + if (!labeler) continue + labeler.labels[pref.label] = pref.visibility as LabelPreference } else { prefs.moderationPrefs.labels[pref.label] = pref.visibility as LabelPreference @@ -530,60 +530,64 @@ export class BskyAgent extends AtpAgent { }) } - async addModService(did: string) { + async addLabeler(did: string) { const prefs = await updatePreferences( this, (prefs: AppBskyActorDefs.Preferences) => { - let modsPref = prefs.findLast( + let labelersPref = prefs.findLast( (pref) => - AppBskyActorDefs.isModsPref(pref) && - AppBskyActorDefs.validateModsPref(pref).success, + AppBskyActorDefs.isLabelersPref(pref) && + AppBskyActorDefs.validateLabelersPref(pref).success, ) - if (!modsPref) { - modsPref = { - $type: 'app.bsky.actor.defs#modsPref', - mods: [], + if (!labelersPref) { + labelersPref = { + $type: 'app.bsky.actor.defs#labelersPref', + labelers: [], } } - if (AppBskyActorDefs.isModsPref(modsPref)) { - let modPrefItem = modsPref.mods.find((mod) => mod.did === did) - if (!modPrefItem) { - modPrefItem = { + if (AppBskyActorDefs.isLabelersPref(labelersPref)) { + let labelerPrefItem = labelersPref.labelers.find( + (labeler) => labeler.did === did, + ) + if (!labelerPrefItem) { + labelerPrefItem = { did, } - modsPref.mods.push(modPrefItem) + labelersPref.labelers.push(labelerPrefItem) } } return prefs - .filter((pref) => !AppBskyActorDefs.isModsPref(pref)) - .concat([modsPref]) + .filter((pref) => !AppBskyActorDefs.isLabelersPref(pref)) + .concat([labelersPref]) }, ) // automatically configure the client this.configureLabelersHeader(prefsArrayToLabelerDids(prefs)) } - async removeModService(did: string) { + async removeLabeler(did: string) { const prefs = await updatePreferences( this, (prefs: AppBskyActorDefs.Preferences) => { - let modsPref = prefs.findLast( + let labelersPref = prefs.findLast( (pref) => - AppBskyActorDefs.isModsPref(pref) && - AppBskyActorDefs.validateModsPref(pref).success, + AppBskyActorDefs.isLabelersPref(pref) && + AppBskyActorDefs.validateLabelersPref(pref).success, ) - if (!modsPref) { - modsPref = { - $type: 'app.bsky.actor.defs#modsPref', - mods: [], + if (!labelersPref) { + labelersPref = { + $type: 'app.bsky.actor.defs#labelersPref', + labelers: [], } } - if (AppBskyActorDefs.isModsPref(modsPref)) { - modsPref.mods = modsPref.mods.filter((mod) => mod.did !== did) + if (AppBskyActorDefs.isLabelersPref(labelersPref)) { + labelersPref.labelers = labelersPref.labelers.filter( + (labeler) => labeler.did !== did, + ) } return prefs - .filter((pref) => !AppBskyActorDefs.isModsPref(pref)) - .concat([modsPref]) + .filter((pref) => !AppBskyActorDefs.isLabelersPref(pref)) + .concat([labelersPref]) }, ) // automatically configure the client @@ -872,14 +876,16 @@ function adjustLegacyContentLabelPref( function prefsArrayToLabelerDids( prefs: AppBskyActorDefs.Preferences, ): string[] { - const modsPref = prefs.findLast( + const labelersPref = prefs.findLast( (pref) => - AppBskyActorDefs.isModsPref(pref) && - AppBskyActorDefs.validateModsPref(pref).success, + AppBskyActorDefs.isLabelersPref(pref) && + AppBskyActorDefs.validateLabelersPref(pref).success, ) let dids: string[] = [] - if (modsPref) { - dids = (modsPref as AppBskyActorDefs.ModsPref).mods.map((mod) => mod.did) + if (labelersPref) { + dids = (labelersPref as AppBskyActorDefs.LabelersPref).labelers.map( + (labeler) => labeler.did, + ) } return dids } diff --git a/packages/api/src/client/lexicons.ts b/packages/api/src/client/lexicons.ts index 635e9e19e60..a04bf6bab6e 100644 --- a/packages/api/src/client/lexicons.ts +++ b/packages/api/src/client/lexicons.ts @@ -5395,20 +5395,20 @@ export const schemaDict = { }, }, }, - modsPref: { + labelersPref: { type: 'object', - required: ['mods'], + required: ['labelers'], properties: { - mods: { + labelers: { type: 'array', items: { type: 'ref', - ref: 'lex:app.bsky.actor.defs#modPrefItem', + ref: 'lex:app.bsky.actor.defs#labelerPrefItem', }, }, }, }, - modPrefItem: { + labelerPrefItem: { type: 'object', required: ['did'], properties: { diff --git a/packages/api/src/client/types/app/bsky/actor/defs.ts b/packages/api/src/client/types/app/bsky/actor/defs.ts index 7eebedc47f4..4243002b862 100644 --- a/packages/api/src/client/types/app/bsky/actor/defs.ts +++ b/packages/api/src/client/types/app/bsky/actor/defs.ts @@ -338,36 +338,36 @@ export function validateHiddenPostsPref(v: unknown): ValidationResult { return lexicons.validate('app.bsky.actor.defs#hiddenPostsPref', v) } -export interface ModsPref { - mods: ModPrefItem[] +export interface LabelersPref { + labelers: LabelerPrefItem[] [k: string]: unknown } -export function isModsPref(v: unknown): v is ModsPref { +export function isLabelersPref(v: unknown): v is LabelersPref { return ( isObj(v) && hasProp(v, '$type') && - v.$type === 'app.bsky.actor.defs#modsPref' + v.$type === 'app.bsky.actor.defs#labelersPref' ) } -export function validateModsPref(v: unknown): ValidationResult { - return lexicons.validate('app.bsky.actor.defs#modsPref', v) +export function validateLabelersPref(v: unknown): ValidationResult { + return lexicons.validate('app.bsky.actor.defs#labelersPref', v) } -export interface ModPrefItem { +export interface LabelerPrefItem { did: string [k: string]: unknown } -export function isModPrefItem(v: unknown): v is ModPrefItem { +export function isLabelerPrefItem(v: unknown): v is LabelerPrefItem { return ( isObj(v) && hasProp(v, '$type') && - v.$type === 'app.bsky.actor.defs#modPrefItem' + v.$type === 'app.bsky.actor.defs#labelerPrefItem' ) } -export function validateModPrefItem(v: unknown): ValidationResult { - return lexicons.validate('app.bsky.actor.defs#modPrefItem', v) +export function validateLabelerPrefItem(v: unknown): ValidationResult { + return lexicons.validate('app.bsky.actor.defs#labelerPrefItem', v) } diff --git a/packages/api/src/moderation/decision.ts b/packages/api/src/moderation/decision.ts index 0f7bce23846..48ecf1fd8a7 100644 --- a/packages/api/src/moderation/decision.ts +++ b/packages/api/src/moderation/decision.ts @@ -214,7 +214,7 @@ export class ModerationDecision { const isSelf = label.src === this.did const labeler = isSelf ? undefined - : opts.prefs.mods.find((s) => s.did === label.src) + : opts.prefs.labelers.find((s) => s.did === label.src) if (!isSelf && !labeler) { return // skip labelers not configured by the user diff --git a/packages/api/src/moderation/types.ts b/packages/api/src/moderation/types.ts index 02c673c9d43..8edaffd3546 100644 --- a/packages/api/src/moderation/types.ts +++ b/packages/api/src/moderation/types.ts @@ -127,7 +127,7 @@ export type ModerationCause = | { type: 'muted'; source: ModerationCauseSource; priority: 6 } | { type: 'hidden'; source: ModerationCauseSource; priority: 6 } -export interface ModerationPrefsModerator { +export interface ModerationPrefsLabeler { did: string labels: Record } @@ -135,7 +135,7 @@ export interface ModerationPrefsModerator { export interface ModerationPrefs { adultContentEnabled: boolean labels: Record - mods: ModerationPrefsModerator[] + labelers: ModerationPrefsLabeler[] } export interface ModerationOpts { diff --git a/packages/api/tests/bsky-agent.test.ts b/packages/api/tests/bsky-agent.test.ts index bb914b0ebcc..dca946ff94e 100644 --- a/packages/api/tests/bsky-agent.test.ts +++ b/packages/api/tests/bsky-agent.test.ts @@ -228,7 +228,7 @@ describe('agent', () => { moderationPrefs: { adultContentEnabled: false, labels: DEFAULT_LABEL_SETTINGS, - mods: [], + labelers: [], }, birthDate: undefined, feedViewPrefs: { @@ -257,7 +257,7 @@ describe('agent', () => { moderationPrefs: { adultContentEnabled: true, labels: DEFAULT_LABEL_SETTINGS, - mods: [], + labelers: [], }, birthDate: undefined, feedViewPrefs: { @@ -286,7 +286,7 @@ describe('agent', () => { moderationPrefs: { adultContentEnabled: false, labels: DEFAULT_LABEL_SETTINGS, - mods: [], + labelers: [], }, birthDate: undefined, feedViewPrefs: { @@ -315,7 +315,7 @@ describe('agent', () => { moderationPrefs: { adultContentEnabled: false, labels: { ...DEFAULT_LABEL_SETTINGS, misinfo: 'hide' }, - mods: [], + labelers: [], }, birthDate: undefined, feedViewPrefs: { @@ -348,7 +348,7 @@ describe('agent', () => { misinfo: 'hide', spam: 'ignore', }, - mods: [], + labelers: [], }, birthDate: undefined, feedViewPrefs: { @@ -384,7 +384,7 @@ describe('agent', () => { misinfo: 'hide', spam: 'ignore', }, - mods: [], + labelers: [], }, birthDate: undefined, feedViewPrefs: { @@ -420,7 +420,7 @@ describe('agent', () => { misinfo: 'hide', spam: 'ignore', }, - mods: [], + labelers: [], }, birthDate: undefined, feedViewPrefs: { @@ -456,7 +456,7 @@ describe('agent', () => { misinfo: 'hide', spam: 'ignore', }, - mods: [], + labelers: [], }, birthDate: undefined, feedViewPrefs: { @@ -492,7 +492,7 @@ describe('agent', () => { misinfo: 'hide', spam: 'ignore', }, - mods: [], + labelers: [], }, birthDate: undefined, feedViewPrefs: { @@ -528,7 +528,7 @@ describe('agent', () => { misinfo: 'hide', spam: 'ignore', }, - mods: [], + labelers: [], }, birthDate: undefined, feedViewPrefs: { @@ -570,7 +570,7 @@ describe('agent', () => { misinfo: 'hide', spam: 'ignore', }, - mods: [], + labelers: [], }, birthDate: undefined, feedViewPrefs: { @@ -606,7 +606,7 @@ describe('agent', () => { misinfo: 'hide', spam: 'ignore', }, - mods: [], + labelers: [], }, birthDate: undefined, feedViewPrefs: { @@ -642,7 +642,7 @@ describe('agent', () => { misinfo: 'hide', spam: 'ignore', }, - mods: [], + labelers: [], }, birthDate: new Date('2023-09-11T18:05:42.556Z'), feedViewPrefs: { @@ -678,7 +678,7 @@ describe('agent', () => { misinfo: 'hide', spam: 'ignore', }, - mods: [], + labelers: [], }, birthDate: new Date('2023-09-11T18:05:42.556Z'), feedViewPrefs: { @@ -714,7 +714,7 @@ describe('agent', () => { misinfo: 'hide', spam: 'ignore', }, - mods: [], + labelers: [], }, birthDate: new Date('2023-09-11T18:05:42.556Z'), feedViewPrefs: { @@ -750,7 +750,7 @@ describe('agent', () => { misinfo: 'hide', spam: 'ignore', }, - mods: [], + labelers: [], }, birthDate: new Date('2023-09-11T18:05:42.556Z'), feedViewPrefs: { @@ -793,7 +793,7 @@ describe('agent', () => { misinfo: 'hide', spam: 'ignore', }, - mods: [], + labelers: [], }, birthDate: new Date('2023-09-11T18:05:42.556Z'), feedViewPrefs: { @@ -836,7 +836,7 @@ describe('agent', () => { misinfo: 'hide', spam: 'ignore', }, - mods: [], + labelers: [], }, birthDate: new Date('2023-09-11T18:05:42.556Z'), feedViewPrefs: { @@ -879,7 +879,7 @@ describe('agent', () => { misinfo: 'hide', spam: 'ignore', }, - mods: [], + labelers: [], }, birthDate: new Date('2023-09-11T18:05:42.556Z'), feedViewPrefs: { @@ -942,16 +942,16 @@ describe('agent', () => { visibility: 'warn', }, { - $type: 'app.bsky.actor.defs#modsPref', - mods: [ + $type: 'app.bsky.actor.defs#labelersPref', + labelers: [ { did: 'did:plc:first-labeler', }, ], }, { - $type: 'app.bsky.actor.defs#modsPref', - mods: [ + $type: 'app.bsky.actor.defs#labelersPref', + labelers: [ { did: 'did:plc:first-labeler', }, @@ -1037,7 +1037,7 @@ describe('agent', () => { ...DEFAULT_LABEL_SETTINGS, porn: 'warn', }, - mods: [ + labelers: [ { did: 'did:plc:first-labeler', labels: {}, @@ -1081,7 +1081,7 @@ describe('agent', () => { ...DEFAULT_LABEL_SETTINGS, porn: 'warn', }, - mods: [ + labelers: [ { did: 'did:plc:first-labeler', labels: {}, @@ -1125,7 +1125,7 @@ describe('agent', () => { ...DEFAULT_LABEL_SETTINGS, porn: 'ignore', }, - mods: [ + labelers: [ { did: 'did:plc:first-labeler', labels: {}, @@ -1157,7 +1157,7 @@ describe('agent', () => { hiddenPosts: [], }) - await agent.removeModService('did:plc:other') + await agent.removeLabeler('did:plc:other') await expect(agent.getPreferences()).resolves.toStrictEqual({ feeds: { pinned: [], @@ -1169,7 +1169,7 @@ describe('agent', () => { ...DEFAULT_LABEL_SETTINGS, porn: 'ignore', }, - mods: [ + labelers: [ { did: 'did:plc:first-labeler', labels: {}, @@ -1209,7 +1209,7 @@ describe('agent', () => { ...DEFAULT_LABEL_SETTINGS, porn: 'ignore', }, - mods: [ + labelers: [ { did: 'did:plc:first-labeler', labels: {}, @@ -1249,7 +1249,7 @@ describe('agent', () => { ...DEFAULT_LABEL_SETTINGS, porn: 'ignore', }, - mods: [ + labelers: [ { did: 'did:plc:first-labeler', labels: {}, @@ -1300,7 +1300,7 @@ describe('agent', () => { ...DEFAULT_LABEL_SETTINGS, porn: 'ignore', }, - mods: [ + labelers: [ { did: 'did:plc:first-labeler', labels: {}, @@ -1341,8 +1341,8 @@ describe('agent', () => { visibility: 'ignore', }, { - $type: 'app.bsky.actor.defs#modsPref', - mods: [ + $type: 'app.bsky.actor.defs#labelersPref', + labelers: [ { did: 'did:plc:first-labeler', }, diff --git a/packages/api/tests/moderation-custom-labels.test.ts b/packages/api/tests/moderation-custom-labels.test.ts index 89dc135b39c..fcc7d50b8b5 100644 --- a/packages/api/tests/moderation-custom-labels.test.ts +++ b/packages/api/tests/moderation-custom-labels.test.ts @@ -331,7 +331,7 @@ function modOpts(blurs: string, severity: string): ModerationOpts { prefs: { adultContentEnabled: true, labels: {}, - mods: [ + labelers: [ { did: 'did:web:labeler.test', labels: { custom: 'hide' }, diff --git a/packages/api/tests/moderation-prefs.test.ts b/packages/api/tests/moderation-prefs.test.ts index 03678842c16..00d8f2c24d0 100644 --- a/packages/api/tests/moderation-prefs.test.ts +++ b/packages/api/tests/moderation-prefs.test.ts @@ -63,7 +63,7 @@ describe('agent', () => { sexual: 'ignore', gore: 'ignore', }, - mods: [], + labelers: [], }, birthDate: undefined, feedViewPrefs: { @@ -92,7 +92,7 @@ describe('agent', () => { password: 'password', }) - await agent.addModService('did:plc:other') + await agent.addLabeler('did:plc:other') expect(agent.labelersHeader).toStrictEqual(['did:plc:other']) await expect(agent.getPreferences()).resolves.toStrictEqual({ feeds: { pinned: undefined, saved: undefined }, @@ -101,7 +101,7 @@ describe('agent', () => { moderationPrefs: { adultContentEnabled: false, labels: DEFAULT_LABEL_SETTINGS, - mods: [ + labelers: [ { did: 'did:plc:other', labels: {}, @@ -126,7 +126,7 @@ describe('agent', () => { }) expect(agent.labelersHeader).toStrictEqual(['did:plc:other']) - await agent.removeModService('did:plc:other') + await agent.removeLabeler('did:plc:other') expect(agent.labelersHeader).toStrictEqual([]) await expect(agent.getPreferences()).resolves.toStrictEqual({ feeds: { pinned: undefined, saved: undefined }, @@ -135,7 +135,7 @@ describe('agent', () => { moderationPrefs: { adultContentEnabled: false, labels: DEFAULT_LABEL_SETTINGS, - mods: [], + labelers: [], }, birthDate: undefined, feedViewPrefs: { @@ -165,7 +165,7 @@ describe('agent', () => { password: 'password', }) - await agent.addModService('did:plc:other') + await agent.addLabeler('did:plc:other') await agent.setContentLabelPref('porn', 'ignore') await agent.setContentLabelPref('porn', 'hide', 'did:plc:other') await agent.setContentLabelPref('x-custom', 'warn', 'did:plc:other') @@ -177,7 +177,7 @@ describe('agent', () => { moderationPrefs: { adultContentEnabled: false, labels: { ...DEFAULT_LABEL_SETTINGS, porn: 'ignore' }, - mods: [ + labelers: [ { did: 'did:plc:other', labels: { diff --git a/packages/api/tests/moderation.test.ts b/packages/api/tests/moderation.test.ts index b13d8c87ec8..8d025557c3a 100644 --- a/packages/api/tests/moderation.test.ts +++ b/packages/api/tests/moderation.test.ts @@ -29,7 +29,7 @@ describe('Moderation', () => { labels: { porn: 'hide', }, - mods: [], + labelers: [], }, }, ) @@ -61,7 +61,7 @@ describe('Moderation', () => { labels: { porn: 'ignore', }, - mods: [], + labelers: [], }, }, ) @@ -95,7 +95,7 @@ describe('Moderation', () => { labels: { porn: 'hide', }, - mods: [], + labelers: [], }, }, ) @@ -137,7 +137,7 @@ describe('Moderation', () => { labels: { porn: 'ignore', }, - mods: [ + labelers: [ { did: 'did:web:labeler.test', labels: { porn: 'ignore' }, @@ -182,7 +182,7 @@ describe('Moderation', () => { prefs: { adultContentEnabled: true, labels: {}, - mods: [ + labelers: [ { did: 'did:web:labeler.test', labels: {}, @@ -232,7 +232,7 @@ describe('Moderation', () => { labels: { porn: 'hide', }, - mods: [ + labelers: [ { did: 'did:web:labeler.test', labels: {}, @@ -253,7 +253,7 @@ describe('Moderation', () => { prefs: { adultContentEnabled: true, labels: { porn: 'warn' }, - mods: [ + labelers: [ { did: 'did:web:labeler.test', labels: { porn: 'warn' }, @@ -311,7 +311,7 @@ describe('Moderation', () => { prefs: { adultContentEnabled: true, labels: {}, - mods: [ + labelers: [ { did: 'did:web:labeler.test', labels: {}, @@ -374,7 +374,7 @@ describe('Moderation', () => { prefs: { adultContentEnabled: true, labels: {}, - mods: [ + labelers: [ { did: 'did:web:labeler.test', labels: { BadLabel: 'hide', 'bad/label': 'hide' }, diff --git a/packages/api/tests/util/moderation-behavior.ts b/packages/api/tests/util/moderation-behavior.ts index 07c8310a4d2..d7347c66254 100644 --- a/packages/api/tests/util/moderation-behavior.ts +++ b/packages/api/tests/util/moderation-behavior.ts @@ -254,7 +254,7 @@ export class ModerationBehaviorSuiteRunner { this.configurations[scenario.cfg]?.adultContentEnabled, ), labels: this.configurations[scenario.cfg].settings || {}, - mods: [ + labelers: [ { did: 'did:plc:fake-labeler', labels: {},