Monorepo for Tangled
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 Rkey string
12 Text string
13 CreatedAt time.Time
14 Langs []string
15 Tags []string
16 Embed *apibsky.FeedDefs_PostView_Embed
17 Facets []*apibsky.RichtextFacet
18 Labels *apibsky.FeedPost_Labels
19 Reply *apibsky.FeedPost_ReplyRef
20 LikeCount int64
21 ReplyCount int64
22 RepostCount int64
23 QuoteCount int64
24}
25
26func NewBskyPostFromView(postView *apibsky.FeedDefs_PostView) (*BskyPost, error) {
27 atUri, err := syntax.ParseATURI(postView.Uri)
28 if err != nil {
29 return nil, err
30 }
31
32 // decode the record to get FeedPost
33 feedPost, ok := postView.Record.Val.(*apibsky.FeedPost)
34 if !ok {
35 return nil, err
36 }
37
38 createdAt, err := time.Parse(time.RFC3339, feedPost.CreatedAt)
39 if err != nil {
40 return nil, err
41 }
42
43 var likeCount, replyCount, repostCount, quoteCount int64
44 if postView.LikeCount != nil {
45 likeCount = *postView.LikeCount
46 }
47 if postView.ReplyCount != nil {
48 replyCount = *postView.ReplyCount
49 }
50 if postView.RepostCount != nil {
51 repostCount = *postView.RepostCount
52 }
53 if postView.QuoteCount != nil {
54 quoteCount = *postView.QuoteCount
55 }
56
57 return &BskyPost{
58 Rkey: atUri.RecordKey().String(),
59 Text: feedPost.Text,
60 CreatedAt: createdAt,
61 Langs: feedPost.Langs,
62 Tags: feedPost.Tags,
63 Embed: postView.Embed,
64 Facets: feedPost.Facets,
65 Labels: feedPost.Labels,
66 Reply: feedPost.Reply,
67 LikeCount: likeCount,
68 ReplyCount: replyCount,
69 RepostCount: repostCount,
70 QuoteCount: quoteCount,
71 }, nil
72}