This repository has no description
0

Configure Feed

Select the types of activity you want to include in your feed.

core / appview / models / bsky.go
1.8 kB 79 lines
1package models 2 3import ( 4 "time" 5 6 apibsky "github.com/bluesky-social/indigo/api/bsky" 7 "github.com/bluesky-social/indigo/atproto/syntax" 8) 9 10type BskyPost struct { 11 AuthorDid string 12 Rkey string 13 Text string 14 CreatedAt time.Time 15 Langs []string 16 Tags []string 17 Embed *apibsky.FeedDefs_PostView_Embed 18 Facets []*apibsky.RichtextFacet 19 Labels *apibsky.FeedPost_Labels 20 Reply *apibsky.FeedPost_ReplyRef 21 LikeCount int64 22 ReplyCount int64 23 RepostCount int64 24 QuoteCount int64 25} 26 27func NewBskyPostFromView(postView *apibsky.FeedDefs_PostView) (*BskyPost, error) { 28 atUri, err := syntax.ParseATURI(postView.Uri) 29 if err != nil { 30 return nil, err 31 } 32 33 // decode the record to get FeedPost 34 feedPost, ok := postView.Record.Val.(*apibsky.FeedPost) 35 if !ok { 36 return nil, err 37 } 38 39 createdAt, err := time.Parse(time.RFC3339, feedPost.CreatedAt) 40 if err != nil { 41 return nil, err 42 } 43 44 var likeCount, replyCount, repostCount, quoteCount int64 45 if postView.LikeCount != nil { 46 likeCount = *postView.LikeCount 47 } 48 if postView.ReplyCount != nil { 49 replyCount = *postView.ReplyCount 50 } 51 if postView.RepostCount != nil { 52 repostCount = *postView.RepostCount 53 } 54 if postView.QuoteCount != nil { 55 quoteCount = *postView.QuoteCount 56 } 57 58 post := &BskyPost{ 59 Rkey: atUri.RecordKey().String(), 60 Text: feedPost.Text, 61 CreatedAt: createdAt, 62 Langs: feedPost.Langs, 63 Tags: feedPost.Tags, 64 Embed: postView.Embed, 65 Facets: feedPost.Facets, 66 Labels: feedPost.Labels, 67 Reply: feedPost.Reply, 68 LikeCount: likeCount, 69 ReplyCount: replyCount, 70 RepostCount: repostCount, 71 QuoteCount: quoteCount, 72 } 73 74 if author := postView.Author; author != nil { 75 post.AuthorDid = author.Did 76 } 77 78 return post, nil 79}