phase 4: migrate ageAssurance unit and chat wrapper signatures to lex clients

This commit is contained in:
Samuel Newman
2026-07-17 12:10:41 +03:00
parent d052d14f2b
commit 5a099a8db6
8 changed files with 110 additions and 108 deletions
+3 -2
View File
@@ -3,7 +3,7 @@ import {useMutation, useQueryClient} from '@tanstack/react-query'
import {restrictChatSettings} from '#/state/queries/messages/restrictChatSettings'
import {preferencesQueryKey} from '#/state/queries/preferences'
import {useAgent, useSession} from '#/state/session'
import {useAgent, usePdsClient, useSession} from '#/state/session'
import {usePatchAgeAssuranceOtherRequiredData} from '#/ageAssurance'
import {isUnderAge} from '#/ageAssurance/util'
import {IS_DEV} from '#/env'
@@ -55,6 +55,7 @@ export function useIsBirthdateUpdateAllowed() {
export function useBirthdateMutation() {
const queryClient = useQueryClient()
const agent = useAgent()
const pdsClient = usePdsClient()
const patchOtherRequiredData = usePatchAgeAssuranceOtherRequiredData()
return useMutation<void, unknown, {birthDate: Date}>({
@@ -68,7 +69,7 @@ export function useBirthdateMutation() {
if (isUnderAge(birthDate.toISOString(), 18)) {
await restrictChatSettings({
agent,
client: pdsClient,
restrictIncoming: true,
restrictGroupInvites: true,
})
@@ -1,10 +1,9 @@
import {type Client} from '@atproto/lex-client'
import {type DidString} from '@atproto/syntax'
import {useMutation, useQueryClient} from '@tanstack/react-query'
import {logger} from '#/logger'
import {usePdsClient, useSession} from '#/state/session'
import {agentToLexClient} from '#/state/session/clients'
import {type SessionAgent} from '#/state/session/session-core'
import {resolveAllowGroupInvites} from '#/components/dms/util'
import {type app, chat, com} from '#/lexicons'
import {RQKEY as PROFILE_RKEY} from '../profile'
@@ -116,25 +115,13 @@ export function useDeleteActorDeclaration() {
}
export async function fetchActorDeclarationRecord({
agent,
client,
did,
}: {
agent: SessionAgent
client: Client
did?: string
}) {
if (!did) return
/*
* This helper is called with a bridge `SessionAgent` threaded from
* `#/ageAssurance/data`. Wrap it as an account lex `Client` so the record
* read goes through the same path as the migrated hooks; the caller keeps
* passing the agent until the bridge is removed (Phase 4). The cast is safe:
* `agentToLexClient` only reads `did` and `fetchHandler`, both of which the
* base `Agent` (and thus `SessionAgent`) provides - its `AtpAgent` parameter
* type is just narrower than it needs. TODO(phase4): drop with the bridge.
*/
const client = agentToLexClient(
agent as unknown as Parameters<typeof agentToLexClient>[0],
)
const res = await client
.get(chat.bsky.actor.declaration, {repo: did as DidString, rkey: 'self'})
.catch(_e => undefined)
@@ -1,11 +1,9 @@
import {type DidString} from '@atproto/syntax'
import {type Client} from '@atproto/lex-client'
import {networkRetry} from '#/lib/async/retry'
import {logger} from '#/logger'
import {type SessionAgent} from '#/state/session'
import {agentToLexClient} from '#/state/session/clients'
import {
getDidFromAgentSession,
getDidFromClient,
getOtherRequiredDataFromCache,
setOtherRequiredDataActorDeclarationCache,
} from '#/ageAssurance/data'
@@ -26,15 +24,15 @@ import {chat} from '#/lexicons'
* back to the lexicon defaults when the cache is empty.
*/
export async function restrictChatSettings({
agent,
client,
restrictIncoming = false,
restrictGroupInvites = false,
}: {
agent: SessionAgent
client: Client
restrictIncoming?: boolean
restrictGroupInvites?: boolean
}): Promise<void> {
const did = getDidFromAgentSession(agent)
const did = getDidFromClient(client)
if (!did) return
const cached = getOtherRequiredDataFromCache({did})?.actorDeclaration
@@ -69,22 +67,10 @@ export async function restrictChatSettings({
return
}
/*
* Callers thread a bridge `SessionAgent` (session-core / birthdate); wrap it
* as an account lex `Client` so the record write goes through the lex path.
* The cast is safe: `agentToLexClient` only reads `did` and `fetchHandler`,
* both of which the base `Agent` provides - its `AtpAgent` parameter type is
* just narrower than it needs. TODO(phase4): take a Client directly once the
* bridge is removed.
*/
const client = agentToLexClient(
agent as unknown as Parameters<typeof agentToLexClient>[0],
)
try {
await networkRetry(3, () =>
client.put(chat.bsky.actor.declaration, record, {
repo: did as DidString,
repo: did,
rkey: 'self',
}),
)
+9 -4
View File
@@ -619,7 +619,8 @@ export async function createSessionBundleAndResume(
const moderation = configureModerationForAccount(bundle, account)
const aa = prefetchAgeAssuranceServerData({
agent: bundle.agent,
appviewClient: bundle.appviewClient,
accountClient: bundle.accountClient,
})
await Promise.all([gates, moderation, aa])
hooks.arm()
@@ -670,7 +671,8 @@ export async function createSessionBundleAndLogin(
const gates = features.refresh({strategy: 'prefer-fresh-gates'})
const moderation = configureModerationForAccount(bundle, account)
const aa = prefetchAgeAssuranceServerData({
agent: bundle.agent,
appviewClient: bundle.appviewClient,
accountClient: bundle.accountClient,
})
await Promise.all([gates, moderation, aa])
hooks.arm()
@@ -750,7 +752,10 @@ export async function createSessionBundleAndCreateAccount(
setBirthdateForDid({did: account.did, birthdate})
snoozeBirthdateUpdateAllowedForDid(account.did)
// do this last
const aa = prefetchAgeAssuranceServerData({agent})
const aa = prefetchAgeAssuranceServerData({
appviewClient: bundle.appviewClient,
accountClient: bundle.accountClient,
})
// Not awaited so that we can still get into onboarding.
// This is OK because we won't let you toggle adult stuff until you set the date.
@@ -801,7 +806,7 @@ export async function createSessionBundleAndCreateAccount(
const {flags} = unsafeGetAndComputeAgeAssurance({did: account.did})
if (flags?.chatDisabled || flags?.groupChatDisabled) {
void restrictChatSettings({
agent,
client: bundle.accountClient,
restrictIncoming: flags.chatDisabled,
restrictGroupInvites: flags.groupChatDisabled,
})