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 GraphList struct { 13 ID string `gorm:"primaryKey"` 14 15 // TODO: Avatar, DescriptionFacets 16 17 CreatedAt string 18 Description *string 19 Labels []GraphList_Label 20 Name string 21 Purpose *string 22 23 AutoCreatedAt time.Time `gorm:"autoCreateTime"` 24 AutoUpdatedAt time.Time `gorm:"autoUpdateTime"` 25} 26 27type GraphList_Label struct { 28 GraphListID string 29 Value string 30} 31 32func NewGraphList(uri syntax.ATURI, rec []byte) *GraphList { 33 var out appbsky.GraphList 34 if err := out.UnmarshalCBOR(bytes.NewReader(rec)); err != nil { 35 slog.Error("could not unmarshal graph list CBOR", "err", err) 36 return nil 37 } 38 39 list := GraphList{ 40 CreatedAt: out.CreatedAt, 41 Description: out.Description, 42 Name: out.Name, 43 Purpose: out.Purpose, 44 } 45 46 if out.Labels != nil && out.Labels.LabelDefs_SelfLabels != nil && out.Labels.LabelDefs_SelfLabels.Values != nil { 47 for _, label := range out.Labels.LabelDefs_SelfLabels.Values { 48 list.Labels = append(list.Labels, GraphList_Label{ 49 Value: label.Val, 50 }) 51 } 52 } 53 54 return &list 55}