package models import ( "bytes" "log/slog" "time" appbsky "github.com/bluesky-social/indigo/api/bsky" "github.com/bluesky-social/indigo/atproto/syntax" ) type GraphList struct { ID string `gorm:"primaryKey"` // TODO: Avatar, DescriptionFacets CreatedAt string Description *string Labels []GraphList_Label Name string Purpose *string AutoCreatedAt time.Time `gorm:"autoCreateTime"` AutoUpdatedAt time.Time `gorm:"autoUpdateTime"` } type GraphList_Label struct { GraphListID string Value string } func NewGraphList(uri syntax.ATURI, rec []byte) *GraphList { var out appbsky.GraphList if err := out.UnmarshalCBOR(bytes.NewReader(rec)); err != nil { slog.Error("could not unmarshal graph list CBOR", "err", err) return nil } list := GraphList{ ID: string(uri), CreatedAt: out.CreatedAt, Description: out.Description, Name: out.Name, Purpose: out.Purpose, } if out.Labels != nil && out.Labels.LabelDefs_SelfLabels != nil && out.Labels.LabelDefs_SelfLabels.Values != nil { for _, label := range out.Labels.LabelDefs_SelfLabels.Values { list.Labels = append(list.Labels, GraphList_Label{ Value: label.Val, }) } } return &list }