Bluesky app fork with some witchin' additions 馃挮
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

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