Write chat declaration record in response to different events (#10216)

Co-authored-by: Eric Bailey <git@esb.lol>
This commit is contained in:
DS Boyce
2026-04-20 13:39:12 -07:00
committed by GitHub
parent d58ff89441
commit 8c2e4c6fad
10 changed files with 298 additions and 125 deletions
@@ -1,4 +1,8 @@
import {type AppBskyActorDefs} from '@atproto/api'
import type AtpAgent from '@atproto/api'
import {
type AppBskyActorDefs,
type ChatBskyActorDeclaration,
} from '@atproto/api'
import {useMutation, useQueryClient} from '@tanstack/react-query'
import {logger} from '#/logger'
@@ -78,3 +82,21 @@ export function useDeleteActorDeclaration() {
},
})
}
export async function fetchActorDeclarationRecord({
agent,
did,
}: {
agent: AtpAgent
did?: string
}) {
if (!did) return
const res = await agent.com.atproto.repo
.getRecord({
repo: did,
collection: 'chat.bsky.actor.declaration',
rkey: 'self',
})
.catch(_e => undefined)
return res?.data.value as ChatBskyActorDeclaration.Main
}
@@ -0,0 +1,39 @@
import type AtpAgent from '@atproto/api'
import {type ChatBskyActorDeclaration} from '@atproto/api'
import {networkRetry} from '#/lib/async/retry'
import {logger} from '#/logger'
import {setOtherRequiredDataActorDeclarationCache} from '#/ageAssurance/data'
/**
* Helper to update the chat settings record.
*/
export async function restrictChatSettings({
agent,
did,
}: {
agent: AtpAgent
did: string
}): Promise<void> {
try {
const record: ChatBskyActorDeclaration.Main = {
$type: 'chat.bsky.actor.declaration',
allowIncoming: 'none',
}
await networkRetry(3, () =>
agent.com.atproto.repo.putRecord({
repo: did,
collection: 'chat.bsky.actor.declaration',
rkey: 'self',
record,
}),
)
// important, update local cache to avoid running this again
setOtherRequiredDataActorDeclarationCache({
did,
actorDeclaration: record,
})
} catch {
logger.error(`restrictChatSettings: failed to set chat declaration`)
}
}