Something went wrong. Try again.
Mirror — see github.com/blacksky-algorithms/blacksky.community
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263import {Agent, AtpAgent, BSKY_LABELER_DID} from '@atproto/api'
import {IS_TEST_USER} from '#/lib/constants'import {getNoAppLabelers} from '../preferences/no-app-labelers'import { BLACKSKY_LABELER, configureAdditionalModerationAuthorities,} from './additional-moderation-authorities'import {readLabelers} from './agent-config'import {type SessionAccount} from './types'
export function configureModerationForGuest() { // This global mutation is *only* OK because this code is only relevant for testing. // Don't add any other global behavior here! switchToBskyAppLabeler() configureAdditionalModerationAuthorities()}
export async function configureModerationForAccount( agent: Agent, account: SessionAccount,) { // This global mutation is *only* OK because this code is only relevant for testing. // Don't add any other global behavior here! switchToBskyAppLabeler() if (IS_TEST_USER(account.handle)) { await trySwitchToTestAppLabeler(agent) }
// The code below is actually relevant to production (and isn't global). const labelerDids = await readLabelers(account.did).catch(_ => {}) if (labelerDids) { agent.configureLabelersHeader( labelerDids.filter( did => did !== BSKY_LABELER_DID && did !== BLACKSKY_LABELER, ), ) } else { // If there are no headers in the storage, we'll not send them on the initial requests. // If we wanted to fix this, we could block on the preferences query here. }
configureAdditionalModerationAuthorities()}
function switchToBskyAppLabeler() { AtpAgent.configure({ appLabelers: getNoAppLabelers() ? [] : [BSKY_LABELER_DID, BLACKSKY_LABELER], })}
async function trySwitchToTestAppLabeler(agent: Agent) { const did = ( await agent .resolveHandle({handle: 'mod-authority.test'}) .catch(_ => undefined) )?.data.did if (did) { console.warn('USING TEST ENV MODERATION') AtpAgent.configure({appLabelers: [did]}) }}