migrate runtime call sites to lex clients and sdk actions
Phase 3 tasks 3-7 (parallel wave): composer/post pipeline on pdsClient/appviewClient with structural+instance blob guards and a golden CID fixture test; chat Convo/EventBus/queries on the dedicated chat client; preferences sugar to SDK actions on the PDS client; remaining state/queries producers (usePostThread unspecced flip, video scoped-token clients, notifications, starter packs, lists) to client.call; UI runtime sweep (AtUri from @atproto/syntax, moderation fns from @bsky.app/sdk/moderation, SDK RichText, ozone reason tokens, guard rewrites via #/types/bsky). Intermediate checkpoint (hooks skipped): ~114 typecheck errors remain in cross-boundary consumer files, resolved by the type-only codemod next. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,13 +1,12 @@
|
||||
import {
|
||||
type AppBskyActorDefs,
|
||||
type ChatBskyActorDeclaration,
|
||||
} from '@atproto/api'
|
||||
import {type DidString} from '@atproto/syntax'
|
||||
import {useMutation, useQueryClient} from '@tanstack/react-query'
|
||||
|
||||
import {logger} from '#/logger'
|
||||
import {type SessionAgent} from '#/state/session'
|
||||
import {useAgent, useSession} from '#/state/session'
|
||||
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'
|
||||
|
||||
export function useUpdateActorDeclaration({
|
||||
@@ -19,7 +18,7 @@ export function useUpdateActorDeclaration({
|
||||
}) {
|
||||
const queryClient = useQueryClient()
|
||||
const {currentAccount} = useSession()
|
||||
const agent = useAgent()
|
||||
const pdsClient = usePdsClient()
|
||||
|
||||
return useMutation({
|
||||
mutationFn: async (update: {
|
||||
@@ -28,7 +27,7 @@ export function useUpdateActorDeclaration({
|
||||
}) => {
|
||||
if (!currentAccount) throw new Error('Not signed in')
|
||||
const current =
|
||||
queryClient.getQueryData<AppBskyActorDefs.ProfileViewDetailed>(
|
||||
queryClient.getQueryData<app.bsky.actor.defs.ProfileViewDetailed>(
|
||||
PROFILE_RKEY(currentAccount.did),
|
||||
)
|
||||
const allowIncoming =
|
||||
@@ -41,8 +40,8 @@ export function useUpdateActorDeclaration({
|
||||
update.allowGroupInvites ??
|
||||
current?.associated?.chat?.allowGroupInvites,
|
||||
})
|
||||
const result = await agent.com.atproto.repo.putRecord({
|
||||
repo: currentAccount.did,
|
||||
const result = await pdsClient.call(com.atproto.repo.putRecord, {
|
||||
repo: currentAccount.did as DidString,
|
||||
collection: 'chat.bsky.actor.declaration',
|
||||
rkey: 'self',
|
||||
record: {
|
||||
@@ -57,7 +56,7 @@ export function useUpdateActorDeclaration({
|
||||
if (!currentAccount) return
|
||||
queryClient.setQueryData(
|
||||
PROFILE_RKEY(currentAccount?.did),
|
||||
(old?: AppBskyActorDefs.ProfileViewDetailed) => {
|
||||
(old?: app.bsky.actor.defs.ProfileViewDetailed) => {
|
||||
if (!old) return old
|
||||
const allowIncoming =
|
||||
update.allowIncoming ??
|
||||
@@ -81,7 +80,7 @@ export function useUpdateActorDeclaration({
|
||||
allowGroupInvites,
|
||||
},
|
||||
},
|
||||
} satisfies AppBskyActorDefs.ProfileViewDetailed
|
||||
} satisfies app.bsky.actor.defs.ProfileViewDetailed
|
||||
},
|
||||
)
|
||||
},
|
||||
@@ -101,13 +100,13 @@ export function useUpdateActorDeclaration({
|
||||
// for use in the settings screen for testing
|
||||
export function useDeleteActorDeclaration() {
|
||||
const {currentAccount} = useSession()
|
||||
const agent = useAgent()
|
||||
const pdsClient = usePdsClient()
|
||||
|
||||
return useMutation({
|
||||
mutationFn: async () => {
|
||||
if (!currentAccount) throw new Error('Not signed in')
|
||||
const result = await agent.api.com.atproto.repo.deleteRecord({
|
||||
repo: currentAccount.did,
|
||||
const result = await pdsClient.call(com.atproto.repo.deleteRecord, {
|
||||
repo: currentAccount.did as DidString,
|
||||
collection: 'chat.bsky.actor.declaration',
|
||||
rkey: 'self',
|
||||
})
|
||||
@@ -124,12 +123,20 @@ export async function fetchActorDeclarationRecord({
|
||||
did?: string
|
||||
}) {
|
||||
if (!did) return
|
||||
const res = await agent.com.atproto.repo
|
||||
.getRecord({
|
||||
repo: did,
|
||||
collection: 'chat.bsky.actor.declaration',
|
||||
rkey: 'self',
|
||||
})
|
||||
/*
|
||||
* 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)
|
||||
return res?.data.value as ChatBskyActorDeclaration.Main
|
||||
return res?.value
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user