From ec376960347a6255f1ec12c1758797ac30c073ff Mon Sep 17 00:00:00 2001 From: Eric Bailey Date: Thu, 25 Apr 2024 15:29:06 -0500 Subject: [Session] Drill `getAgent` into feed APIs (#3701) * Update to desired post-feed usage * Drill agent into feed apis * Thread getAgent instead --------- Co-authored-by: Dan Abramov --- src/lib/api/feed/custom.ts | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) (limited to 'src/lib/api/feed/custom.ts') diff --git a/src/lib/api/feed/custom.ts b/src/lib/api/feed/custom.ts index bd30d58ac..75182c41f 100644 --- a/src/lib/api/feed/custom.ts +++ b/src/lib/api/feed/custom.ts @@ -2,18 +2,30 @@ import { AppBskyFeedDefs, AppBskyFeedGetFeed as GetCustomFeed, AtpAgent, + BskyAgent, } from '@atproto/api' import {getContentLanguages} from '#/state/preferences/languages' -import {getAgent} from '#/state/session' import {FeedAPI, FeedAPIResponse} from './types' export class CustomFeedAPI implements FeedAPI { - constructor(public params: GetCustomFeed.QueryParams) {} + getAgent: () => BskyAgent + params: GetCustomFeed.QueryParams + + constructor({ + getAgent, + feedParams, + }: { + getAgent: () => BskyAgent + feedParams: GetCustomFeed.QueryParams + }) { + this.getAgent = getAgent + this.params = feedParams + } async peekLatest(): Promise { const contentLangs = getContentLanguages().join(',') - const res = await getAgent().app.bsky.feed.getFeed( + const res = await this.getAgent().app.bsky.feed.getFeed( { ...this.params, limit: 1, @@ -31,15 +43,19 @@ export class CustomFeedAPI implements FeedAPI { limit: number }): Promise { const contentLangs = getContentLanguages().join(',') - const agent = getAgent() + const agent = this.getAgent() const res = agent.session - ? await getAgent().app.bsky.feed.getFeed( + ? await this.getAgent().app.bsky.feed.getFeed( { ...this.params, cursor, limit, }, - {headers: {'Accept-Language': contentLangs}}, + { + headers: { + 'Accept-Language': contentLangs, + }, + }, ) : await loggedOutFetch({...this.params, cursor, limit}) if (res.success) { -- cgit 1.4.1