From 717304eb14f800003a285fe641e799baa7122381 Mon Sep 17 00:00:00 2001 From: Eric Bailey Date: Thu, 25 Apr 2024 11:27:06 -0500 Subject: [PATCH] Drill agent into Onboarding/util (cherry picked from commit 2ba68eb5e446a694730b720f2a5b3307eb0914ef) --- src/screens/Onboarding/StepFinished.tsx | 1 + src/screens/Onboarding/util.ts | 18 +++++++++++------- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/screens/Onboarding/StepFinished.tsx b/src/screens/Onboarding/StepFinished.tsx index 56635c672d..dcc2245f80 100644 --- a/src/screens/Onboarding/StepFinished.tsx +++ b/src/screens/Onboarding/StepFinished.tsx @@ -57,6 +57,7 @@ export function StepFinished() { try { await Promise.all([ bulkWriteFollows( + getAgent(), suggestedAccountsStepResults.accountDids.concat(BSKY_APP_ACCOUNT_DID), ), // these must be serial diff --git a/src/screens/Onboarding/util.ts b/src/screens/Onboarding/util.ts index 6b12fb38fe..4174177075 100644 --- a/src/screens/Onboarding/util.ts +++ b/src/screens/Onboarding/util.ts @@ -1,7 +1,10 @@ -import {AppBskyGraphFollow, AppBskyGraphGetFollows} from '@atproto/api' +import { + AppBskyGraphFollow, + AppBskyGraphGetFollows, + BskyAgent, +} from '@atproto/api' import {until} from '#/lib/async/until' -import {getAgent} from '#/state/session' import {PRIMARY_FEEDS} from './StepAlgoFeeds' function shuffle(array: any) { @@ -63,8 +66,8 @@ export function aggregateInterestItems( return Array.from(new Set(results)).slice(0, 20) } -export async function bulkWriteFollows(dids: string[]) { - const session = getAgent().session +export async function bulkWriteFollows(agent: BskyAgent, dids: string[]) { + const session = agent.session if (!session) { throw new Error(`bulkWriteFollows failed: no session`) @@ -83,14 +86,15 @@ export async function bulkWriteFollows(dids: string[]) { value: r, })) - await getAgent().com.atproto.repo.applyWrites({ + await agent.com.atproto.repo.applyWrites({ repo: session.did, writes: followWrites, }) - await whenFollowsIndexed(session.did, res => !!res.data.follows.length) + await whenFollowsIndexed(agent, session.did, res => !!res.data.follows.length) } async function whenFollowsIndexed( + agent: BskyAgent, actor: string, fn: (res: AppBskyGraphGetFollows.Response) => boolean, ) { @@ -99,7 +103,7 @@ async function whenFollowsIndexed( 1e3, // 1s delay between tries fn, () => - getAgent().app.bsky.graph.getFollows({ + agent.app.bsky.graph.getFollows({ actor, limit: 1, }),