an app.bsky.* indexer
at master 1.2 kB view raw
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 ID: string(uri), 41 CreatedAt: out.CreatedAt, 42 Description: out.Description, 43 Name: out.Name, 44 Purpose: out.Purpose, 45 } 46 47 if out.Labels != nil && out.Labels.LabelDefs_SelfLabels != nil && out.Labels.LabelDefs_SelfLabels.Values != nil { 48 for _, label := range out.Labels.LabelDefs_SelfLabels.Values { 49 list.Labels = append(list.Labels, GraphList_Label{ 50 Value: label.Val, 51 }) 52 } 53 } 54 55 return &list 56}