an app.bsky.* indexer
1package models
2
3import (
4 "bytes"
5 "log/slog"
6 "time"
7
8 appbsky "github.com/bluesky-social/indigo/api/bsky"
9 "github.com/bluesky-social/indigo/atproto/syntax"
10)
11
12type FeedGenerator struct {
13 ID string `gorm:"primaryKey"`
14
15 // TODO: Avatar, DescriptionFacets
16
17 AcceptsInteractions *bool
18 ContentMode *string
19 CreatedAt string
20 Description *string
21 Did string
22 DisplayName string
23 Labels []FeedGenerator_Label
24
25 AutoCreatedAt time.Time `gorm:"autoCreateTime"`
26 AutoUpdatedAt time.Time `gorm:"autoUpdateTime"`
27}
28
29type FeedGenerator_Label struct {
30 FeedGeneratorID string
31 Value string
32}
33
34func NewFeedGenerator(uri syntax.ATURI, rec []byte) *FeedGenerator {
35 var out appbsky.FeedGenerator
36 if err := out.UnmarshalCBOR(bytes.NewReader(rec)); err != nil {
37 slog.Error("could not unmarshal feed generator CBOR", "err", err)
38 return nil
39 }
40
41 feedgen := FeedGenerator{
42 AcceptsInteractions: out.AcceptsInteractions,
43 ContentMode: out.ContentMode,
44 CreatedAt: out.CreatedAt,
45 Description: out.Description,
46 Did: out.Did,
47 DisplayName: out.DisplayName,
48 }
49
50 if out.Labels != nil && out.Labels.LabelDefs_SelfLabels != nil && out.Labels.LabelDefs_SelfLabels.Values != nil {
51 for _, label := range out.Labels.LabelDefs_SelfLabels.Values {
52 feedgen.Labels = append(feedgen.Labels, FeedGenerator_Label{
53 FeedGeneratorID: feedgen.ID,
54 Value: label.Val,
55 })
56 }
57 }
58
59 return &feedgen
60}