Something went wrong. Try again.
message board on atproto atchan.net
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839import { Client } from '@atproto/lex'import type { OAuthSession } from '@atproto/oauth-client-node'import type { DatetimeString } from '@atproto/syntax'import * as net from '#lib/lexicons/net.js'import { logger } from '#lib/server/log.js'
const log = logger('actor')
/** * Ensure the signed-in user has an `net.atchan.actor.declaration` record, * writing one on login if it doesn't already exist. * * The general purpose of this declaration is to announce the account to the * firehose consumer: it's the first net.atchan.* record a new user writes, so it * is what enrols their repo and pulls their history in before they post * anything (see server/indexer/repos). */export async function declare_actor(session: OAuthSession): Promise<void> { const client = new Client(session)
try { await client.get(net.atchan.actor.declaration) // already declared - nothing to do return } catch { // not found (or transient) }
try { await client.create(net.atchan.actor.declaration, { createdAt: new Date().toISOString() as DatetimeString }) log.info({ did: session.did }, `wrote actor declaration for ${session.did}`) } catch (err) { // a concurrent first post may have already created it; ignore log.error(err, 'failed to write actor declaration') }}