Drill agent into Onboarding/util

(cherry picked from commit 2ba68eb5e446a694730b720f2a5b3307eb0914ef)
This commit is contained in:
Eric Bailey
2024-04-25 11:27:06 -05:00
parent e7297a2c84
commit 717304eb14
2 changed files with 12 additions and 7 deletions
+1
View File
@@ -57,6 +57,7 @@ export function StepFinished() {
try { try {
await Promise.all([ await Promise.all([
bulkWriteFollows( bulkWriteFollows(
getAgent(),
suggestedAccountsStepResults.accountDids.concat(BSKY_APP_ACCOUNT_DID), suggestedAccountsStepResults.accountDids.concat(BSKY_APP_ACCOUNT_DID),
), ),
// these must be serial // these must be serial
+11 -7
View File
@@ -1,7 +1,10 @@
import {AppBskyGraphFollow, AppBskyGraphGetFollows} from '@atproto/api' import {
AppBskyGraphFollow,
AppBskyGraphGetFollows,
BskyAgent,
} from '@atproto/api'
import {until} from '#/lib/async/until' import {until} from '#/lib/async/until'
import {getAgent} from '#/state/session'
import {PRIMARY_FEEDS} from './StepAlgoFeeds' import {PRIMARY_FEEDS} from './StepAlgoFeeds'
function shuffle(array: any) { function shuffle(array: any) {
@@ -63,8 +66,8 @@ export function aggregateInterestItems(
return Array.from(new Set(results)).slice(0, 20) return Array.from(new Set(results)).slice(0, 20)
} }
export async function bulkWriteFollows(dids: string[]) { export async function bulkWriteFollows(agent: BskyAgent, dids: string[]) {
const session = getAgent().session const session = agent.session
if (!session) { if (!session) {
throw new Error(`bulkWriteFollows failed: no session`) throw new Error(`bulkWriteFollows failed: no session`)
@@ -83,14 +86,15 @@ export async function bulkWriteFollows(dids: string[]) {
value: r, value: r,
})) }))
await getAgent().com.atproto.repo.applyWrites({ await agent.com.atproto.repo.applyWrites({
repo: session.did, repo: session.did,
writes: followWrites, writes: followWrites,
}) })
await whenFollowsIndexed(session.did, res => !!res.data.follows.length) await whenFollowsIndexed(agent, session.did, res => !!res.data.follows.length)
} }
async function whenFollowsIndexed( async function whenFollowsIndexed(
agent: BskyAgent,
actor: string, actor: string,
fn: (res: AppBskyGraphGetFollows.Response) => boolean, fn: (res: AppBskyGraphGetFollows.Response) => boolean,
) { ) {
@@ -99,7 +103,7 @@ async function whenFollowsIndexed(
1e3, // 1s delay between tries 1e3, // 1s delay between tries
fn, fn,
() => () =>
getAgent().app.bsky.graph.getFollows({ agent.app.bsky.graph.getFollows({
actor, actor,
limit: 1, limit: 1,
}), }),