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:
@@ -1,7 +1,5 @@
|
||||
import {
|
||||
type AppBskyActorDefs,
|
||||
type AppBskyNotificationDeclaration,
|
||||
} from '@atproto/api'
|
||||
import {type AppBskyActorDefs} from '@atproto/api'
|
||||
import {type AtIdentifierString} from '@atproto/syntax'
|
||||
import {t} from '@lingui/core/macro'
|
||||
import {
|
||||
type InfiniteData,
|
||||
@@ -12,7 +10,8 @@ import {
|
||||
useQueryClient,
|
||||
} 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 {app} from '#/lexicons'
|
||||
|
||||
@@ -36,27 +35,25 @@ export function useActivitySubscriptionsQuery() {
|
||||
}
|
||||
|
||||
export function useNotificationDeclarationQuery() {
|
||||
const agent = useAgent()
|
||||
const client = usePdsClient()
|
||||
const {currentAccount} = useSession()
|
||||
return useQuery({
|
||||
queryKey: RQKEY_getNotificationDeclaration,
|
||||
queryFn: async () => {
|
||||
try {
|
||||
const response = await agent.app.bsky.notification.declaration.get({
|
||||
repo: currentAccount!.did,
|
||||
const response = await client.get(app.bsky.notification.declaration, {
|
||||
// the session account is still legacy-typed, so its did is unbranded
|
||||
repo: currentAccount!.did as AtIdentifierString,
|
||||
rkey: 'self',
|
||||
})
|
||||
return response
|
||||
} catch (err) {
|
||||
if (
|
||||
err instanceof Error &&
|
||||
err.message.startsWith('Could not locate record')
|
||||
) {
|
||||
if (isRecordNotFoundError(err)) {
|
||||
return {
|
||||
value: {
|
||||
$type: 'app.bsky.notification.declaration',
|
||||
allowSubscriptions: 'followers',
|
||||
} satisfies AppBskyNotificationDeclaration.Record,
|
||||
} satisfies app.bsky.notification.declaration.Main,
|
||||
}
|
||||
} else {
|
||||
throw err
|
||||
@@ -67,17 +64,18 @@ export function useNotificationDeclarationQuery() {
|
||||
}
|
||||
|
||||
export function useNotificationDeclarationMutation() {
|
||||
const agent = useAgent()
|
||||
const client = usePdsClient()
|
||||
const {currentAccount} = useSession()
|
||||
const queryClient = useQueryClient()
|
||||
return useMutation({
|
||||
mutationFn: async (record: AppBskyNotificationDeclaration.Record) => {
|
||||
const response = await agent.app.bsky.notification.declaration.put(
|
||||
mutationFn: async (record: app.bsky.notification.declaration.Main) => {
|
||||
const response = await client.put(
|
||||
app.bsky.notification.declaration,
|
||||
record,
|
||||
{
|
||||
repo: currentAccount!.did,
|
||||
repo: currentAccount!.did as AtIdentifierString,
|
||||
rkey: 'self',
|
||||
},
|
||||
record,
|
||||
)
|
||||
return response
|
||||
},
|
||||
@@ -87,7 +85,7 @@ export function useNotificationDeclarationMutation() {
|
||||
(old?: {
|
||||
uri: string
|
||||
cid: string
|
||||
value: AppBskyNotificationDeclaration.Record
|
||||
value: app.bsky.notification.declaration.Main
|
||||
}) => {
|
||||
if (!old) return old
|
||||
return {
|
||||
|
||||
@@ -3,11 +3,13 @@ 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 {useAgent, useSession} from '#/state/session'
|
||||
import {usePdsClient, useSession} from '#/state/session'
|
||||
import {resolveAllowGroupInvites} from '#/components/dms/util'
|
||||
import {com} from '#/lexicons'
|
||||
import {RQKEY as PROFILE_RKEY} from '../profile'
|
||||
|
||||
export function useUpdateActorDeclaration({
|
||||
@@ -19,7 +21,7 @@ export function useUpdateActorDeclaration({
|
||||
}) {
|
||||
const queryClient = useQueryClient()
|
||||
const {currentAccount} = useSession()
|
||||
const agent = useAgent()
|
||||
const pdsClient = usePdsClient()
|
||||
|
||||
return useMutation({
|
||||
mutationFn: async (update: {
|
||||
@@ -41,8 +43,9 @@ 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, {
|
||||
// the session account is still legacy-typed, so its did is unbranded
|
||||
repo: currentAccount.did as DidString,
|
||||
collection: 'chat.bsky.actor.declaration',
|
||||
rkey: 'self',
|
||||
record: {
|
||||
@@ -101,13 +104,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',
|
||||
})
|
||||
@@ -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({
|
||||
agent,
|
||||
did,
|
||||
|
||||
Reference in New Issue
Block a user