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