-
Notifications
You must be signed in to change notification settings - Fork 578
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Handle sync legacy labels * Remap values on read * Filter out double-written legacy label values * Better naming, fix types
- Loading branch information
1 parent
2408225
commit 92a5be6
Showing
2 changed files
with
204 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -175,7 +175,7 @@ describe('agent', () => { | |
interests: { tags: [] }, | ||
moderationPrefs: { | ||
adultContentEnabled: false, | ||
labels: { ...DEFAULT_LABEL_SETTINGS, porn: 'ignore' }, | ||
labels: { ...DEFAULT_LABEL_SETTINGS, porn: 'ignore', nsfw: 'ignore' }, | ||
labelers: [ | ||
{ | ||
did: 'did:plc:other', | ||
|
@@ -204,4 +204,132 @@ describe('agent', () => { | |
}, | ||
}) | ||
}) | ||
|
||
it(`updates label pref`, async () => { | ||
const agent = new BskyAgent({ service: network.pds.url }) | ||
|
||
await agent.createAccount({ | ||
handle: 'user8.test', | ||
email: '[email protected]', | ||
password: 'password', | ||
}) | ||
|
||
await agent.addLabeler('did:plc:other') | ||
await agent.setContentLabelPref('porn', 'ignore') | ||
await agent.setContentLabelPref('porn', 'ignore', 'did:plc:other') | ||
await agent.setContentLabelPref('porn', 'hide') | ||
await agent.setContentLabelPref('porn', 'hide', 'did:plc:other') | ||
|
||
const { moderationPrefs } = await agent.getPreferences() | ||
const labeler = moderationPrefs.labelers.find( | ||
(l) => l.did === 'did:plc:other', | ||
) | ||
|
||
expect(moderationPrefs.labels.porn).toEqual('hide') | ||
expect(labeler?.labels?.porn).toEqual('hide') | ||
}) | ||
|
||
it(`double-write for legacy: 'graphic-media' in sync with 'gore'`, async () => { | ||
const agent = new BskyAgent({ service: network.pds.url }) | ||
|
||
await agent.createAccount({ | ||
handle: 'user9.test', | ||
email: '[email protected]', | ||
password: 'password', | ||
}) | ||
|
||
await agent.setContentLabelPref('graphic-media', 'hide') | ||
const a = await agent.getPreferences() | ||
|
||
expect(a.moderationPrefs.labels.gore).toEqual('hide') | ||
expect(a.moderationPrefs.labels['graphic-media']).toEqual('hide') | ||
|
||
await agent.setContentLabelPref('graphic-media', 'warn') | ||
const b = await agent.getPreferences() | ||
|
||
expect(b.moderationPrefs.labels.gore).toEqual('warn') | ||
expect(b.moderationPrefs.labels['graphic-media']).toEqual('warn') | ||
}) | ||
|
||
it(`double-write for legacy: 'porn' in sync with 'nsfw'`, async () => { | ||
const agent = new BskyAgent({ service: network.pds.url }) | ||
|
||
await agent.createAccount({ | ||
handle: 'user10.test', | ||
email: '[email protected]', | ||
password: 'password', | ||
}) | ||
|
||
await agent.setContentLabelPref('porn', 'hide') | ||
const a = await agent.getPreferences() | ||
|
||
expect(a.moderationPrefs.labels.nsfw).toEqual('hide') | ||
expect(a.moderationPrefs.labels.porn).toEqual('hide') | ||
|
||
await agent.setContentLabelPref('porn', 'warn') | ||
const b = await agent.getPreferences() | ||
|
||
expect(b.moderationPrefs.labels.nsfw).toEqual('warn') | ||
expect(b.moderationPrefs.labels.porn).toEqual('warn') | ||
}) | ||
|
||
it(`double-write for legacy: 'sexual' in sync with 'suggestive'`, async () => { | ||
const agent = new BskyAgent({ service: network.pds.url }) | ||
|
||
await agent.createAccount({ | ||
handle: 'user11.test', | ||
email: '[email protected]', | ||
password: 'password', | ||
}) | ||
|
||
await agent.setContentLabelPref('sexual', 'hide') | ||
const a = await agent.getPreferences() | ||
|
||
expect(a.moderationPrefs.labels.sexual).toEqual('hide') | ||
expect(a.moderationPrefs.labels.suggestive).toEqual('hide') | ||
|
||
await agent.setContentLabelPref('sexual', 'warn') | ||
const b = await agent.getPreferences() | ||
|
||
expect(b.moderationPrefs.labels.sexual).toEqual('warn') | ||
expect(b.moderationPrefs.labels.suggestive).toEqual('warn') | ||
}) | ||
|
||
it(`double-write for legacy: filters out existing old label pref if double-written`, async () => { | ||
const agent = new BskyAgent({ service: network.pds.url }) | ||
|
||
await agent.createAccount({ | ||
handle: 'user12.test', | ||
email: '[email protected]', | ||
password: 'password', | ||
}) | ||
|
||
await agent.setContentLabelPref('nsfw', 'hide') | ||
await agent.setContentLabelPref('porn', 'hide') | ||
const a = await agent.app.bsky.actor.getPreferences({}) | ||
|
||
const nsfwSettings = a.data.preferences.filter( | ||
(pref) => pref.label === 'nsfw', | ||
) | ||
expect(nsfwSettings.length).toEqual(1) | ||
}) | ||
|
||
it(`remaps old values to new on read`, async () => { | ||
const agent = new BskyAgent({ service: network.pds.url }) | ||
|
||
await agent.createAccount({ | ||
handle: 'user13.test', | ||
email: '[email protected]', | ||
password: 'password', | ||
}) | ||
|
||
await agent.setContentLabelPref('nsfw', 'hide') | ||
await agent.setContentLabelPref('gore', 'hide') | ||
await agent.setContentLabelPref('suggestive', 'hide') | ||
const a = await agent.getPreferences() | ||
|
||
expect(a.moderationPrefs.labels.porn).toEqual('hide') | ||
expect(a.moderationPrefs.labels['graphic-media']).toEqual('hide') | ||
expect(a.moderationPrefs.labels['sexual']).toEqual('hide') | ||
}) | ||
}) |