Skip to content

Commit

Permalink
Additional 3p labeler updates (#2286)
Browse files Browse the repository at this point in the history
* Rename bsky_labeler_did

* Use labeldef default setting

* Add definedBy to interpretted label defs

* Improve dev-env mocks for labels

* Remove global label defs for dmca-violation, doxxing, and !no-promote

* Change nudity global label def to default to ignore and no longer be adult-only

* Remove old !no-promote tests

* Add mod authorities header and move bsky labeler into it

* Rename modsPref and addModService/removeModService to labelersPref and add/removeLabeler

* Add defaultSetting and adultOnly to custom label value definitions

* Rename InterprettedLabelValueDefinition to InterpretedLabelValueDefinition

* Update dev-env mock

* Move muted words and hidden posts into moderationPrefs

* Add muted word and hidden post handling to moderatePost

* Add mutewords tests

* Finish muteword tests

* Add mod-authority.test to dev-env

* Rename global label value def gore to graphic-media

* Fix typo

* Stop converting old label values

* Update label target=profile behaviors: dont filter content on hide, dont blur display names, but do show the info cards

* Update label target=account behaviors: dont blur media of content

* Add muteword moderation behaviors

* Fix mock label defs

* Implement quote-post moderation handling

* Add adult content test

* Handle sync legacy labels (#2291)

* Handle sync legacy labels

* Remap values on read

* Filter out double-written legacy label values

* Better naming, fix types

* Fix test

* Update moderation docs in sdk

* Update to new atproto-accept-labelers header behavior

* Add getLabelDefinitions() helper method

* Add proxy header support to agent

* Update mock moderation

* lint

* Implement moderation for userlists and feedgens

* Add another test label

* fix labeler in dev-env agents

* fix label hydration test

* fix lint error

* fix agent test

* fix takedown labels test

---------

Co-authored-by: Eric Bailey <[email protected]>
Co-authored-by: dholms <[email protected]>
  • Loading branch information
3 people authored Mar 13, 2024
1 parent 2ea27e3 commit 00a567d
Show file tree
Hide file tree
Showing 60 changed files with 3,469 additions and 1,294 deletions.
10 changes: 5 additions & 5 deletions lexicons/app/bsky/actor/defs.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
10 changes: 10 additions & 0 deletions lexicons/com/atproto/label/defs.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,16 @@
"description": "What should this label hide in the UI, if applied? 'content' hides all of the target; 'media' hides the images/video/audio; 'none' hides nothing.",
"knownValues": ["content", "media", "none"]
},
"defaultSetting": {
"type": "string",
"description": "The default setting for this label.",
"knownValues": ["ignore", "warn", "hide"],
"default": "warn"
},
"adultOnly": {
"type": "boolean",
"description": "Does the user need to have adult content enabled in order to configure this label?"
},
"locales": {
"type": "array",
"items": { "type": "ref", "ref": "#labelValueDefinitionStrings" }
Expand Down
99 changes: 41 additions & 58 deletions packages/api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,87 +178,70 @@ console.log(rt3.graphemeLength) // => 1

Applying the moderation system is a challenging task, but we've done our best to simplify it for you. The Moderation API helps handle a wide range of tasks, including:

- Moderator labeling
- User muting (including mutelists)
- User blocking
- Moderator labeling
- Mutewords
- Hidden posts

For more information, see the [Moderation Documentation](./docs/moderation.md) or the associated [Labels Reference](./docs/labels.md).
For more information, see the [Moderation Documentation](./docs/moderation.md).

```typescript
import { moderatePost, moderateProfile } from '@atproto/api'
import { moderatePost } from '@atproto/api'

// First get the user's moderation prefs and their label definitions
// =

const prefs = await agent.getPreferences()
const labelDefs = await agent.getLabelDefinitions(prefs)

// We call the appropriate moderation function for the content
// =

const postMod = moderatePost(postView, getOpts())
const profileMod = moderateProfile(profileView, getOpts())
const postMod = moderatePost(postView, {
userDid: agent.session.did,
moderationPrefs: prefs.moderationPrefs,
labelDefs,
})

// We then use the output to decide how to affect rendering
// =

if (postMod.content.filter) {
// don't render in feeds or similar
// in contexts where this is disruptive (eg threads) you should ignore this and instead check blur
// in feeds
if (postMod.ui('contentList').filter) {
// don't include in feeds
}
if (postMod.content.blur) {
// render the whole object behind a cover (use postMod.content.cause to explain)
if (postMod.content.noOverride) {
if (postMod.ui('contentList').blur) {
// render the whole object behind a cover (use postMod.ui('contentList').blurs to explain)
if (postMod.ui('contentList').noOverride) {
// do not allow the cover the be removed
}
}
if (postMod.content.alert) {
// render a warning on the content (use postMod.content.cause to explain)
if (postMod.ui('contentList').alert || postMod.ui('contentList').inform) {
// render warnings on the post
// find the warnings in postMod.ui('contentList').alerts and postMod.ui('contentList').informs
}
if (postMod.embed.blur) {
// render the embedded media behind a cover (use postMod.embed.cause to explain)
if (postMod.embed.noOverride) {

// viewed directly
if (postMod.ui('contentView').filter) {
// don't include in feeds
}
if (postMod.ui('contentView').blur) {
// render the whole object behind a cover (use postMod.ui('contentView').blurs to explain)
if (postMod.ui('contentView').noOverride) {
// do not allow the cover the be removed
}
}
if (postMod.embed.alert) {
// render a warning on the embedded media (use postMod.embed.cause to explain)
}
if (postMod.avatar.blur) {
// render the avatar behind a cover
}
if (postMod.avatar.alert) {
// render an alert on the avatar
if (postMod.ui('contentView').alert || postMod.ui('contentView').inform) {
// render warnings on the post
// find the warnings in postMod.ui('contentView').alerts and postMod.ui('contentView').informs
}

// The options passed into `apply()` supply the user's preferences
// =

function getOpts() {
return {
// the logged-in user's DID
userDid: 'did:plc:1234...',

// is adult content allowed?
adultContentEnabled: true,

// the global label settings (used on self-labels)
labels: {
porn: 'hide',
sexual: 'warn',
nudity: 'ignore',
// ...
},

// the per-labeler settings
labelers: [
{
labeler: {
did: '...',
displayName: 'My mod service',
},
labels: {
porn: 'hide',
sexual: 'warn',
nudity: 'ignore',
// ...
},
},
],
// post embeds in all contexts
if (postMod.ui('contentMedia').blur) {
// render the whole object behind a cover (use postMod.ui('contentMedia').blurs to explain)
if (postMod.ui('contentMedia').noOverride) {
// do not allow the cover the be removed
}
}
```
Expand Down
63 changes: 3 additions & 60 deletions packages/api/definitions/labels.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,6 @@
}
}
},
{
"identifier": "!no-promote",
"configurable": false,
"defaultSetting": "hide",
"flags": ["no-self"],
"severity": "none",
"blurs": "none",
"behaviors": {}
},
{
"identifier": "!warn",
"configurable": false,
Expand Down Expand Up @@ -91,54 +82,6 @@
}
}
},
{
"identifier": "dmca-violation",
"configurable": false,
"defaultSetting": "hide",
"flags": ["no-override", "no-self"],
"severity": "none",
"blurs": "content",
"behaviors": {
"account": {
"profileList": "blur",
"profileView": "blur",
"contentList": "blur",
"contentView": "blur"
},
"profile": {
"profileList": "blur",
"profileView": "blur"
},
"content": {
"contentList": "blur",
"contentView": "blur"
}
}
},
{
"identifier": "doxxing",
"configurable": false,
"defaultSetting": "hide",
"flags": ["no-override", "no-self"],
"severity": "none",
"blurs": "content",
"behaviors": {
"account": {
"profileList": "blur",
"profileView": "blur",
"contentList": "blur",
"contentView": "blur"
},
"profile": {
"profileList": "blur",
"profileView": "blur"
},
"content": {
"contentList": "blur",
"contentView": "blur"
}
}
},
{
"identifier": "porn",
"configurable": true,
Expand Down Expand Up @@ -184,8 +127,8 @@
{
"identifier": "nudity",
"configurable": true,
"defaultSetting": "warn",
"flags": ["adult"],
"defaultSetting": "ignore",
"flags": [],
"severity": "none",
"blurs": "media",
"behaviors": {
Expand All @@ -203,7 +146,7 @@
}
},
{
"identifier": "gore",
"identifier": "graphic-media",
"flags": ["adult"],
"configurable": true,
"defaultSetting": "warn",
Expand Down
108 changes: 0 additions & 108 deletions packages/api/docs/labels.md

This file was deleted.

Loading

0 comments on commit 00a567d

Please sign in to comment.