Bluesky app fork with some witchin' additions 馃挮
at main 56 lines 1.2 kB view raw
1import { 2 type AppBskyFeedDefs, 3 type AppBskyFeedGetActorLikes as GetActorLikes, 4 type BskyAgent, 5} from '@atproto/api' 6 7import {type FeedAPI, type FeedAPIResponse} from './types' 8 9export class LikesFeedAPI implements FeedAPI { 10 agent: BskyAgent 11 params: GetActorLikes.QueryParams 12 13 constructor({ 14 agent, 15 feedParams, 16 }: { 17 agent: BskyAgent 18 feedParams: GetActorLikes.QueryParams 19 }) { 20 this.agent = agent 21 this.params = feedParams 22 } 23 24 async peekLatest(): Promise<AppBskyFeedDefs.FeedViewPost> { 25 const res = await this.agent.getActorLikes({ 26 ...this.params, 27 limit: 1, 28 }) 29 return res.data.feed[0] 30 } 31 32 async fetch({ 33 cursor, 34 limit, 35 }: { 36 cursor: string | undefined 37 limit: number 38 }): Promise<FeedAPIResponse> { 39 const res = await this.agent.getActorLikes({ 40 ...this.params, 41 cursor, 42 limit, 43 }) 44 if (res.success) { 45 // HACKFIX: the API incorrectly returns a cursor when there are no items -sfn 46 const isEmptyPage = res.data.feed.length === 0 47 return { 48 cursor: isEmptyPage ? undefined : res.data.cursor, 49 feed: res.data.feed, 50 } 51 } 52 return { 53 feed: [], 54 } 55 } 56}