aboutsummaryrefslogtreecommitdiff
path: root/backend/notes/app.bsky.feed.post.go
diff options
context:
space:
mode:
Diffstat (limited to 'backend/notes/app.bsky.feed.post.go')
-rw-r--r--backend/notes/app.bsky.feed.post.go50
1 files changed, 50 insertions, 0 deletions
diff --git a/backend/notes/app.bsky.feed.post.go b/backend/notes/app.bsky.feed.post.go
index 43929b3..32e7854 100644
--- a/backend/notes/app.bsky.feed.post.go
+++ b/backend/notes/app.bsky.feed.post.go
@@ -13,6 +13,14 @@ type AppBskyFeedPostNote struct {
Text string `json:"text"`
CreatedAt time.Time `json:"createdAt"`
ReplyTo *string `json:"replyTo,omitempty"`
+ Facets []Facet `json:"facets,omitempty"`
+}
+
+type Facet struct {
+ ByteStart int `json:"byteStart"`
+ ByteEnd int `json:"byteEnd"`
+ Type string `json:"type"`
+ Value string `json:"value"` // the link destination, whether url, profile or tag
}
type AppBskyFeedPostRecord struct {
@@ -25,6 +33,18 @@ type AppBskyFeedPostRecord struct {
URI string `json:"uri"`
} `json:"parent"`
} `json:"reply,omitempty"`
+ Facets []struct {
+ Index struct {
+ ByteStart int `json:"byteStart"`
+ ByteEnd int `json:"byteEnd"`
+ } `json:"index"`
+ Features []struct {
+ Type string `json:"$type"`
+ URI string `json:"uri,omitempty"`
+ DID string `json:"did,omitempty"`
+ Tag string `json:"tag,omitempty"`
+ } `json:"features"`
+ } `json:"facets,omitempty"`
} `json:"value"`
}
@@ -66,6 +86,35 @@ func AppBskyFeedPostFromRecord(record AppBskyFeedPostRecord) (*AppBskyFeedPostNo
parts := strings.Split(record.URI, "/") // at://DID/collection/rkey
did := parts[2]
+ var facets []Facet
+ for _, f := range record.Value.Facets {
+ for _, feature := range f.Features {
+ var value string
+ var facetType string
+
+ switch feature.Type {
+ case "app.bsky.richtext.facet#link":
+ facetType = "link"
+ value = feature.URI
+ case "app.bsky.richtext.facet#mention":
+ facetType = "mention"
+ value = feature.DID
+ case "app.bsky.richtext.facet#tag":
+ facetType = "tag"
+ value = feature.Tag
+ default:
+ continue
+ }
+
+ facets = append(facets, Facet{
+ ByteStart: f.Index.ByteStart,
+ ByteEnd: f.Index.ByteEnd,
+ Type: facetType,
+ Value: value,
+ })
+ }
+ }
+
return &AppBskyFeedPostNote{
URI: record.URI,
AuthorDID: did,
@@ -73,5 +122,6 @@ func AppBskyFeedPostFromRecord(record AppBskyFeedPostRecord) (*AppBskyFeedPostNo
CreatedAt: createdAt,
Text: record.Value.Text,
ReplyTo: replyTo,
+ Facets: facets,
}, nil
}