mirror of https://git.lenooby09.tech/LeNooby09/social-app.git
1import {
2 AppBskyFeedDefs,
3 AppBskyFeedGetListFeed as GetListFeed,
4} from '@atproto/api'
5import {FeedAPI, FeedAPIResponse} from './types'
6import {getAgent} from '#/state/session'
7
8export class ListFeedAPI implements FeedAPI {
9 constructor(public params: GetListFeed.QueryParams) {}
10
11 async peekLatest(): Promise<AppBskyFeedDefs.FeedViewPost> {
12 const res = await getAgent().app.bsky.feed.getListFeed({
13 ...this.params,
14 limit: 1,
15 })
16 return res.data.feed[0]
17 }
18
19 async fetch({
20 cursor,
21 limit,
22 }: {
23 cursor: string | undefined
24 limit: number
25 }): Promise<FeedAPIResponse> {
26 const res = await getAgent().app.bsky.feed.getListFeed({
27 ...this.params,
28 cursor,
29 limit,
30 })
31 if (res.success) {
32 return {
33 cursor: res.data.cursor,
34 feed: res.data.feed,
35 }
36 }
37 return {
38 feed: [],
39 }
40 }
41}