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