migrate the status, germ declaration and block records to the pds client
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,10 +1,8 @@
|
||||
import {Platform, View} from 'react-native'
|
||||
import {Image} from 'expo-image'
|
||||
import {
|
||||
type AppBskyActorDefs,
|
||||
type AppBskyActorGetProfile,
|
||||
type AtpAgent,
|
||||
} from '@atproto/api'
|
||||
import {type AppBskyActorDefs} from '@atproto/api'
|
||||
import {type Client} from '@atproto/lex'
|
||||
import {type DidString} from '@atproto/syntax'
|
||||
import {msg} from '@lingui/core/macro'
|
||||
import {useLingui} from '@lingui/react'
|
||||
import {Trans} from '@lingui/react/macro'
|
||||
@@ -13,7 +11,7 @@ import {useMutation, useQueryClient} from '@tanstack/react-query'
|
||||
import {until} from '#/lib/async/until'
|
||||
import {isNetworkError} from '#/lib/strings/errors'
|
||||
import {RQKEY} from '#/state/queries/profile'
|
||||
import {useAgent, useSession} from '#/state/session'
|
||||
import {useAppviewClient, usePdsClient, useSession} from '#/state/session'
|
||||
import {atoms as a, useTheme, web} from '#/alf'
|
||||
import {Button, ButtonIcon, ButtonText} from '#/components/Button'
|
||||
import * as Dialog from '#/components/Dialog'
|
||||
@@ -24,6 +22,7 @@ import {Loader} from '#/components/Loader'
|
||||
import * as Toast from '#/components/Toast'
|
||||
import {Text} from '#/components/Typography'
|
||||
import {useAnalytics} from '#/analytics'
|
||||
import {app, com} from '#/lexicons'
|
||||
import type * as bsky from '#/types/bsky'
|
||||
|
||||
export function GermButton({
|
||||
@@ -119,25 +118,27 @@ function GermSelfButton({did}: {did: string}) {
|
||||
const ax = useAnalytics()
|
||||
const {_} = useLingui()
|
||||
const selfExplanationDialogControl = Dialog.useDialogControl()
|
||||
const agent = useAgent()
|
||||
const appviewClient = useAppviewClient()
|
||||
const pdsClient = usePdsClient()
|
||||
const queryClient = useQueryClient()
|
||||
|
||||
const {mutate: deleteDeclaration, isPending} = useMutation({
|
||||
mutationFn: async () => {
|
||||
const previousRecord = await agent.com.germnetwork.declaration
|
||||
.get({
|
||||
repo: did,
|
||||
const previousRecord = await pdsClient
|
||||
// the profile view is still legacy-typed, so its did is unbranded
|
||||
.get(com.germnetwork.declaration, {
|
||||
repo: did as DidString,
|
||||
rkey: 'self',
|
||||
})
|
||||
.then(res => res.value)
|
||||
.catch(() => null)
|
||||
|
||||
await agent.com.germnetwork.declaration.delete({
|
||||
repo: did,
|
||||
await pdsClient.delete(com.germnetwork.declaration, {
|
||||
repo: did as DidString,
|
||||
rkey: 'self',
|
||||
})
|
||||
|
||||
await whenAppViewReady(agent, did, res => !res.data.associated?.germ)
|
||||
await whenAppViewReady(appviewClient, did, res => !res.associated?.germ)
|
||||
|
||||
return previousRecord
|
||||
},
|
||||
@@ -147,14 +148,15 @@ function GermSelfButton({did}: {did: string}) {
|
||||
async function undo() {
|
||||
if (!previousRecord) return
|
||||
try {
|
||||
await agent.com.germnetwork.declaration.put(
|
||||
{
|
||||
repo: did,
|
||||
rkey: 'self',
|
||||
},
|
||||
previousRecord,
|
||||
await pdsClient.put(com.germnetwork.declaration, previousRecord, {
|
||||
repo: did as DidString,
|
||||
rkey: 'self',
|
||||
})
|
||||
await whenAppViewReady(
|
||||
appviewClient,
|
||||
did,
|
||||
res => !!res.associated?.germ,
|
||||
)
|
||||
await whenAppViewReady(agent, did, res => !!res.data.associated?.germ)
|
||||
await queryClient.refetchQueries({queryKey: RQKEY(did)})
|
||||
|
||||
Toast.show(_(msg`Germ DM reconnected`))
|
||||
@@ -323,14 +325,17 @@ function platform() {
|
||||
}
|
||||
|
||||
async function whenAppViewReady(
|
||||
agent: AtpAgent,
|
||||
appviewClient: Client,
|
||||
actor: string,
|
||||
fn: (res: AppBskyActorGetProfile.Response) => boolean,
|
||||
fn: (res: app.bsky.actor.getProfile.$OutputBody) => boolean,
|
||||
) {
|
||||
await until(
|
||||
5, // 5 tries
|
||||
1e3, // 1s delay between tries
|
||||
fn,
|
||||
() => agent.app.bsky.actor.getProfile({actor}),
|
||||
() =>
|
||||
appviewClient.call(app.bsky.actor.getProfile, {
|
||||
actor: actor as DidString,
|
||||
}),
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user