diff options
Diffstat (limited to 'src/lib/api/feed/custom.ts')
-rw-r--r-- | src/lib/api/feed/custom.ts | 28 |
1 files changed, 22 insertions, 6 deletions
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<AppBskyFeedDefs.FeedViewPost> { 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<FeedAPIResponse> { 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) { |