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 ID: string(uri),
43 AcceptsInteractions: out.AcceptsInteractions,
44 ContentMode: out.ContentMode,
45 CreatedAt: out.CreatedAt,
46 Description: out.Description,
47 Did: out.Did,
48 DisplayName: out.DisplayName,
49 }
50
51 if out.Labels != nil && out.Labels.LabelDefs_SelfLabels != nil && out.Labels.LabelDefs_SelfLabels.Values != nil {
52 for _, label := range out.Labels.LabelDefs_SelfLabels.Values {
53 feedgen.Labels = append(feedgen.Labels, FeedGenerator_Label{
54 FeedGeneratorID: feedgen.ID,
55 Value: label.Val,
56 })
57 }
58 }
59
60 return &feedgen
61}