my fork of the bluesky client
at main 54 lines 1.8 kB view raw
1import {BSKY_LABELER_DID, BskyAgent} from '@atproto/api' 2 3import {IS_TEST_USER} from '#/lib/constants' 4import {configureAdditionalModerationAuthorities} from './additional-moderation-authorities' 5import {readLabelers} from './agent-config' 6import {SessionAccount} from './types' 7 8export function configureModerationForGuest() { 9 // This global mutation is *only* OK because this code is only relevant for testing. 10 // Don't add any other global behavior here! 11 switchToBskyAppLabeler() 12 configureAdditionalModerationAuthorities() 13} 14 15export async function configureModerationForAccount( 16 agent: BskyAgent, 17 account: SessionAccount, 18) { 19 // This global mutation is *only* OK because this code is only relevant for testing. 20 // Don't add any other global behavior here! 21 switchToBskyAppLabeler() 22 if (IS_TEST_USER(account.handle)) { 23 await trySwitchToTestAppLabeler(agent) 24 } 25 26 // The code below is actually relevant to production (and isn't global). 27 const labelerDids = await readLabelers(account.did).catch(_ => {}) 28 if (labelerDids) { 29 agent.configureLabelersHeader( 30 labelerDids.filter(did => did !== BSKY_LABELER_DID), 31 ) 32 } else { 33 // If there are no headers in the storage, we'll not send them on the initial requests. 34 // If we wanted to fix this, we could block on the preferences query here. 35 } 36 37 configureAdditionalModerationAuthorities() 38} 39 40function switchToBskyAppLabeler() { 41 BskyAgent.configure({appLabelers: [BSKY_LABELER_DID]}) 42} 43 44async function trySwitchToTestAppLabeler(agent: BskyAgent) { 45 const did = ( 46 await agent 47 .resolveHandle({handle: 'mod-authority.test'}) 48 .catch(_ => undefined) 49 )?.data.did 50 if (did) { 51 console.warn('USING TEST ENV MODERATION') 52 BskyAgent.configure({appLabelers: [did]}) 53 } 54}