migrate the chat and notification declaration records to the pds client

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Samuel Newman
2026-08-03 23:21:30 +03:00
parent ed652ad484
commit 780fccdbbe
2 changed files with 32 additions and 26 deletions
+17 -19
View File
@@ -1,7 +1,5 @@
import { import {type AppBskyActorDefs} from '@atproto/api'
type AppBskyActorDefs, import {type AtIdentifierString} from '@atproto/syntax'
type AppBskyNotificationDeclaration,
} from '@atproto/api'
import {t} from '@lingui/core/macro' import {t} from '@lingui/core/macro'
import { import {
type InfiniteData, type InfiniteData,
@@ -12,7 +10,8 @@ import {
useQueryClient, useQueryClient,
} from '@tanstack/react-query' } from '@tanstack/react-query'
import {useAgent, useAppviewClient, useSession} from '#/state/session' import {isRecordNotFoundError} from '#/lib/xrpc-error'
import {useAppviewClient, usePdsClient, useSession} from '#/state/session'
import * as Toast from '#/components/Toast' import * as Toast from '#/components/Toast'
import {app} from '#/lexicons' import {app} from '#/lexicons'
@@ -36,27 +35,25 @@ export function useActivitySubscriptionsQuery() {
} }
export function useNotificationDeclarationQuery() { export function useNotificationDeclarationQuery() {
const agent = useAgent() const client = usePdsClient()
const {currentAccount} = useSession() const {currentAccount} = useSession()
return useQuery({ return useQuery({
queryKey: RQKEY_getNotificationDeclaration, queryKey: RQKEY_getNotificationDeclaration,
queryFn: async () => { queryFn: async () => {
try { try {
const response = await agent.app.bsky.notification.declaration.get({ const response = await client.get(app.bsky.notification.declaration, {
repo: currentAccount!.did, // the session account is still legacy-typed, so its did is unbranded
repo: currentAccount!.did as AtIdentifierString,
rkey: 'self', rkey: 'self',
}) })
return response return response
} catch (err) { } catch (err) {
if ( if (isRecordNotFoundError(err)) {
err instanceof Error &&
err.message.startsWith('Could not locate record')
) {
return { return {
value: { value: {
$type: 'app.bsky.notification.declaration', $type: 'app.bsky.notification.declaration',
allowSubscriptions: 'followers', allowSubscriptions: 'followers',
} satisfies AppBskyNotificationDeclaration.Record, } satisfies app.bsky.notification.declaration.Main,
} }
} else { } else {
throw err throw err
@@ -67,17 +64,18 @@ export function useNotificationDeclarationQuery() {
} }
export function useNotificationDeclarationMutation() { export function useNotificationDeclarationMutation() {
const agent = useAgent() const client = usePdsClient()
const {currentAccount} = useSession() const {currentAccount} = useSession()
const queryClient = useQueryClient() const queryClient = useQueryClient()
return useMutation({ return useMutation({
mutationFn: async (record: AppBskyNotificationDeclaration.Record) => { mutationFn: async (record: app.bsky.notification.declaration.Main) => {
const response = await agent.app.bsky.notification.declaration.put( const response = await client.put(
app.bsky.notification.declaration,
record,
{ {
repo: currentAccount!.did, repo: currentAccount!.did as AtIdentifierString,
rkey: 'self', rkey: 'self',
}, },
record,
) )
return response return response
}, },
@@ -87,7 +85,7 @@ export function useNotificationDeclarationMutation() {
(old?: { (old?: {
uri: string uri: string
cid: string cid: string
value: AppBskyNotificationDeclaration.Record value: app.bsky.notification.declaration.Main
}) => { }) => {
if (!old) return old if (!old) return old
return { return {
@@ -3,11 +3,13 @@ import {
type AppBskyActorDefs, type AppBskyActorDefs,
type ChatBskyActorDeclaration, type ChatBskyActorDeclaration,
} from '@atproto/api' } from '@atproto/api'
import {type DidString} from '@atproto/syntax'
import {useMutation, useQueryClient} from '@tanstack/react-query' import {useMutation, useQueryClient} from '@tanstack/react-query'
import {logger} from '#/logger' import {logger} from '#/logger'
import {useAgent, useSession} from '#/state/session' import {usePdsClient, useSession} from '#/state/session'
import {resolveAllowGroupInvites} from '#/components/dms/util' import {resolveAllowGroupInvites} from '#/components/dms/util'
import {com} from '#/lexicons'
import {RQKEY as PROFILE_RKEY} from '../profile' import {RQKEY as PROFILE_RKEY} from '../profile'
export function useUpdateActorDeclaration({ export function useUpdateActorDeclaration({
@@ -19,7 +21,7 @@ export function useUpdateActorDeclaration({
}) { }) {
const queryClient = useQueryClient() const queryClient = useQueryClient()
const {currentAccount} = useSession() const {currentAccount} = useSession()
const agent = useAgent() const pdsClient = usePdsClient()
return useMutation({ return useMutation({
mutationFn: async (update: { mutationFn: async (update: {
@@ -41,8 +43,9 @@ export function useUpdateActorDeclaration({
update.allowGroupInvites ?? update.allowGroupInvites ??
current?.associated?.chat?.allowGroupInvites, current?.associated?.chat?.allowGroupInvites,
}) })
const result = await agent.com.atproto.repo.putRecord({ const result = await pdsClient.call(com.atproto.repo.putRecord, {
repo: currentAccount.did, // the session account is still legacy-typed, so its did is unbranded
repo: currentAccount.did as DidString,
collection: 'chat.bsky.actor.declaration', collection: 'chat.bsky.actor.declaration',
rkey: 'self', rkey: 'self',
record: { record: {
@@ -101,13 +104,13 @@ export function useUpdateActorDeclaration({
// for use in the settings screen for testing // for use in the settings screen for testing
export function useDeleteActorDeclaration() { export function useDeleteActorDeclaration() {
const {currentAccount} = useSession() const {currentAccount} = useSession()
const agent = useAgent() const pdsClient = usePdsClient()
return useMutation({ return useMutation({
mutationFn: async () => { mutationFn: async () => {
if (!currentAccount) throw new Error('Not signed in') if (!currentAccount) throw new Error('Not signed in')
const result = await agent.api.com.atproto.repo.deleteRecord({ const result = await pdsClient.call(com.atproto.repo.deleteRecord, {
repo: currentAccount.did, repo: currentAccount.did as DidString,
collection: 'chat.bsky.actor.declaration', collection: 'chat.bsky.actor.declaration',
rkey: 'self', rkey: 'self',
}) })
@@ -116,6 +119,11 @@ export function useDeleteActorDeclaration() {
}) })
} }
/*
* Still takes the legacy agent: its only caller is `getOtherRequiredData` in
* `#/ageAssurance/data`, which is blocked on `getPreferences` and so cannot
* hand over a lex client yet.
*/
export async function fetchActorDeclarationRecord({ export async function fetchActorDeclarationRecord({
agent, agent,
did, did,