Monorepo for Tangled
1package bsky
2
3import (
4 "context"
5 "log"
6
7 bsky "github.com/bluesky-social/indigo/api/bsky"
8 "github.com/bluesky-social/indigo/xrpc"
9 "tangled.org/core/appview/models"
10 "tangled.org/core/consts"
11)
12
13func FetchPosts(ctx context.Context, c *xrpc.Client, limit int, cursor string) ([]models.BskyPost, string, error) {
14 resp, err := bsky.FeedGetAuthorFeed(ctx, c, consts.TangledDid, cursor, "posts_no_replies", false, int64(limit))
15 if err != nil {
16 return nil, "", err
17 }
18
19 var posts []models.BskyPost
20 for _, feedViewPost := range resp.Feed {
21 // skip quote posts
22 if feedViewPost.Post.Embed != nil && feedViewPost.Post.Embed.EmbedRecord_View != nil {
23 continue
24 }
25
26 post, err := models.NewBskyPostFromView(feedViewPost.Post)
27 if err != nil {
28 log.Println(err)
29 continue
30 }
31
32 posts = append(posts, *post)
33 }
34
35 return posts, stringPtr(resp.Cursor), nil
36}
37
38func stringPtr(s *string) string {
39 if s == nil {
40 return ""
41 }
42 return *s
43}