migrate the starter pack writes to the pds client

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Samuel Newman
2026-08-03 23:41:15 +03:00
parent a86590ad4b
commit 3a970a7104
10 changed files with 216 additions and 192 deletions
+11 -3
View File
@@ -8,6 +8,7 @@ import {
type Un$Typed,
} from '@atproto/api'
import {TID} from '@atproto/common-web'
import {type AtUriString} from '@atproto/syntax'
import {msg} from '@lingui/core/macro'
import {useLingui} from '@lingui/react'
import {Trans} from '@lingui/react/macro'
@@ -26,7 +27,7 @@ import {useSetHasCheckedForStarterPack} from '#/state/preferences/used-starter-p
import {getAllListMembers} from '#/state/queries/list-members'
import {preferencesQueryKey} from '#/state/queries/preferences'
import {RQKEY as profileRQKey} from '#/state/queries/profile'
import {useAgent, useAppviewClient} from '#/state/session'
import {useAgent, useAppviewClient, usePdsClient} from '#/state/session'
import {useOnboardingDispatch} from '#/state/shell'
import {
useActiveStarterPack,
@@ -59,6 +60,7 @@ export function StepFinished() {
const queryClient = useQueryClient()
const agent = useAgent()
const appviewClient = useAppviewClient()
const pdsClient = usePdsClient()
const requestNotificationsPermission = useRequestNotificationsPermission()
const activeStarterPack = useActiveStarterPack()
const setActiveStarterPack = useSetActiveStarterPack()
@@ -102,10 +104,15 @@ export function StepFinished() {
await Promise.all([
bulkWriteFollows(
agent,
pdsClient,
appviewClient,
[BSKY_APP_ACCOUNT_DID, ...(listItems?.map(i => i.subject.did) ?? [])],
starterPack
? {uri: starterPack.uri, cid: starterPack.cid}
? // the starter pack view is still legacy-typed
{
uri: starterPack.uri as AtUriString,
cid: starterPack.cid,
}
: undefined,
),
(async () => {
@@ -236,6 +243,7 @@ export function StepFinished() {
queryClient,
agent,
appviewClient,
pdsClient,
dispatch,
onboardDispatch,
activeStarterPack,
@@ -14,7 +14,7 @@ import {logger} from '#/logger'
import {updateProfileShadow} from '#/state/cache/profile-shadow'
import {useLanguagePrefs} from '#/state/preferences'
import {useModerationOpts} from '#/state/preferences/moderation-opts'
import {useAgent, useSession} from '#/state/session'
import {useAppviewClient, usePdsClient, useSession} from '#/state/session'
import {
OnboardingControls,
OnboardingPosition,
@@ -42,7 +42,8 @@ export function StepSuggestedAccounts() {
const t = useTheme()
const {gtMobile} = useBreakpoints()
const moderationOpts = useModerationOpts()
const agent = useAgent()
const appviewClient = useAppviewClient()
const pdsClient = usePdsClient()
const {currentAccount} = useSession()
const queryClient = useQueryClient()
@@ -119,7 +120,10 @@ export function StepSuggestedAccounts() {
followingUri: 'pending',
})
}
const uris = await wait(1e3, bulkWriteFollows(agent, followableDids))
const uris = await wait(
1e3,
bulkWriteFollows(pdsClient, appviewClient, followableDids),
)
for (const did of followableDids) {
const uri = uris.get(did)
updateProfileShadow(queryClient, did, {
@@ -1,6 +1,7 @@
import {useState} from 'react'
import {View} from 'react-native'
import {type AppBskyGraphDefs, AppBskyGraphStarterpack} from '@atproto/api'
import {type AtUriString} from '@atproto/syntax'
import {msg} from '@lingui/core/macro'
import {useLingui} from '@lingui/react'
import {Trans} from '@lingui/react/macro'
@@ -11,7 +12,7 @@ import {isBlockedOrBlocking, isMuted} from '#/lib/moderation/blocked-and-muted'
import {logger} from '#/logger'
import {updateProfileShadow} from '#/state/cache/profile-shadow'
import {getAllListMembers} from '#/state/queries/list-members'
import {useAgent, useAppviewClient, useSession} from '#/state/session'
import {useAppviewClient, usePdsClient, useSession} from '#/state/session'
import {bulkWriteFollows} from '#/screens/Onboarding/util'
import {AvatarStack} from '#/screens/Search/components/StarterPackCard'
import {atoms as a, useBreakpoints, useTheme, web} from '#/alf'
@@ -35,8 +36,8 @@ export function StarterPackCard({
const ax = useAnalytics()
const {currentAccount} = useSession()
const {gtPhone} = useBreakpoints()
const agent = useAgent()
const appviewClient = useAppviewClient()
const pdsClient = usePdsClient()
const queryClient = useQueryClient()
const record = view.record
const [isProcessing, setIsProcessing] = useState(false)
@@ -74,8 +75,9 @@ export function StarterPackCard({
let followUris: Map<string, string>
try {
followUris = await bulkWriteFollows(agent, dids, {
uri: view.uri,
followUris = await bulkWriteFollows(pdsClient, appviewClient, dids, {
// the starter pack view is still legacy-typed
uri: view.uri as AtUriString,
cid: view.cid,
})
} catch (e) {
+24 -27
View File
@@ -1,37 +1,34 @@
import {
type $Typed,
type AppBskyGraphFollow,
type AppBskyGraphGetFollows,
type AtpAgent,
type ComAtprotoRepoApplyWrites,
type ComAtprotoRepoStrongRef,
} from '@atproto/api'
import {TID} from '@atproto/common-web'
import {type $Typed, type Client} from '@atproto/lex'
import {
type AtIdentifierString,
type DidString,
toDatetimeString,
} from '@atproto/syntax'
import chunk from 'lodash.chunk'
import {until} from '#/lib/async/until'
import {app, com} from '#/lexicons'
export async function bulkWriteFollows(
agent: AtpAgent,
pdsClient: Client,
appviewClient: Client,
dids: string[],
via?: ComAtprotoRepoStrongRef.Main,
via?: com.atproto.repo.strongRef.Main,
) {
const session = agent.session
const did = pdsClient.assertDid
if (!session) {
throw new Error(`bulkWriteFollows failed: no session`)
}
const followRecords: $Typed<AppBskyGraphFollow.Record>[] = dids.map(did => {
const followRecords: $Typed<app.bsky.graph.follow.Main>[] = dids.map(did => {
return {
$type: 'app.bsky.graph.follow',
subject: did,
createdAt: new Date().toISOString(),
// callers hold plain dids read off legacy-typed views
subject: did as DidString,
createdAt: toDatetimeString(new Date()),
via,
}
})
const followWrites: $Typed<ComAtprotoRepoApplyWrites.Create>[] =
const followWrites: $Typed<com.atproto.repo.applyWrites.Create>[] =
followRecords.map(r => ({
$type: 'com.atproto.repo.applyWrites#create',
collection: 'app.bsky.graph.follow',
@@ -41,35 +38,35 @@ export async function bulkWriteFollows(
const chunks = chunk(followWrites, 50)
for (const chunk of chunks) {
await agent.com.atproto.repo.applyWrites({
repo: session.did,
await pdsClient.call(com.atproto.repo.applyWrites, {
repo: did,
writes: chunk,
})
}
await whenFollowsIndexed(agent, session.did, res => !!res.data.follows.length)
await whenFollowsIndexed(appviewClient, did, res => !!res.follows.length)
const followUris = new Map<string, string>()
for (const r of followWrites) {
followUris.set(
r.value.subject as string,
`at://${session.did}/app.bsky.graph.follow/${r.rkey}`,
`at://${did}/app.bsky.graph.follow/${r.rkey}`,
)
}
return followUris
}
async function whenFollowsIndexed(
agent: AtpAgent,
appviewClient: Client,
actor: string,
fn: (res: AppBskyGraphGetFollows.Response) => boolean,
fn: (res: app.bsky.graph.getFollows.$OutputBody) => boolean,
) {
await until(
5, // 5 tries
1e3, // 1s delay between tries
fn,
() =>
agent.app.bsky.graph.getFollows({
actor,
appviewClient.call(app.bsky.graph.getFollows, {
actor: actor as AtIdentifierString,
limit: 1,
}),
)
@@ -29,7 +29,7 @@ import {
useContactsMatchesQuery,
useContactsSyncStatusQuery,
} from '#/state/queries/find-contacts'
import {useAgent, useAppviewClient, useSession} from '#/state/session'
import {useAppviewClient, usePdsClient, useSession} from '#/state/session'
import {ErrorScreen} from '#/view/com/util/error/ErrorScreen'
import {List} from '#/view/com/util/List'
import {atoms as a, tokens, useGutters, useTheme} from '#/alf'
@@ -370,7 +370,7 @@ function StatusHeader({
}) {
const {_} = useLingui()
const ax = useAnalytics()
const agent = useAgent()
const pdsClient = usePdsClient()
const client = useAppviewClient()
const queryClient = useQueryClient()
const {currentAccount} = useSession()
@@ -406,7 +406,10 @@ function StatusHeader({
followCount: didsToFollow.length,
})
const uris = await wait(500, bulkWriteFollows(agent, didsToFollow))
const uris = await wait(
500,
bulkWriteFollows(pdsClient, client, didsToFollow),
)
for (const did of didsToFollow) {
const uri = uris.get(did)
@@ -7,6 +7,7 @@ import {
AtUri,
type ModerationOpts,
} from '@atproto/api'
import {type AtUriString} from '@atproto/syntax'
import {RichText as RichTextAPI} from '@bsky.app/sdk/richtext'
import {msg} from '@lingui/core/macro'
import {useLingui} from '@lingui/react'
@@ -37,7 +38,7 @@ import {
useDeleteStarterPackMutation,
useStarterPackQuery,
} from '#/state/queries/starter-packs'
import {useAgent, useAppviewClient, useSession} from '#/state/session'
import {useAppviewClient, usePdsClient, useSession} from '#/state/session'
import {useSetActiveStarterPack} from '#/state/shell/landing'
import {useLoggedOutViewControls} from '#/state/shell/logged-out'
import {
@@ -311,8 +312,8 @@ function Header({
const {_} = useLingui()
const t = useTheme()
const {currentAccount, hasSession} = useSession()
const agent = useAgent()
const appviewClient = useAppviewClient()
const pdsClient = usePdsClient()
const queryClient = useQueryClient()
const setActiveStarterPack = useSetActiveStarterPack()
const {requestSwitchToAccount} = useLoggedOutViewControls()
@@ -379,8 +380,9 @@ function Header({
let followUris: Map<string, string>
try {
followUris = await bulkWriteFollows(agent, dids, {
uri: starterPack.uri,
followUris = await bulkWriteFollows(pdsClient, appviewClient, dids, {
// the starter pack view is still legacy-typed
uri: starterPack.uri as AtUriString,
cid: starterPack.cid,
})
} catch (e) {