package models import ( "bytes" "log/slog" "time" appbsky "github.com/bluesky-social/indigo/api/bsky" "github.com/bluesky-social/indigo/atproto/syntax" ) type ActorProfile struct { ID string `gorm:"primaryKey"` // Avatar // Banner CreatedAt *string Description *string DisplayName *string JoinedViaStarterPack *StrongRef `gorm:"embedded;embeddedPrefix:starterpack_"` Labels []ActorProfile_Label PinnedPost *StrongRef `gorm:"embedded;embeddedPrefix:pinnedpost_"` AutoCreatedAt time.Time `gorm:"autoCreateTime"` AutoUpdatedAt time.Time `gorm:"autoUpdateTime"` } type ActorProfile_Label struct { ActorProfileID string Value string } func NewActorProfile(uri syntax.ATURI, rec []byte) *ActorProfile { var out appbsky.ActorProfile if err := out.UnmarshalCBOR(bytes.NewReader(rec)); err != nil { slog.Error("could not unmarshal actor profile CBOR", "err", err) return nil } profile := ActorProfile{ ID: string(uri), CreatedAt: out.CreatedAt, Description: out.Description, DisplayName: out.DisplayName, } if out.JoinedViaStarterPack != nil { profile.JoinedViaStarterPack = &StrongRef{ Uri: out.JoinedViaStarterPack.Uri, Cid: out.JoinedViaStarterPack.Cid, } } if out.PinnedPost != nil { profile.PinnedPost = &StrongRef{ Uri: out.PinnedPost.Uri, Cid: out.PinnedPost.Cid, } } if out.Labels != nil && out.Labels.LabelDefs_SelfLabels != nil && out.Labels.LabelDefs_SelfLabels.Values != nil { for _, label := range out.Labels.LabelDefs_SelfLabels.Values { profile.Labels = append(profile.Labels, ActorProfile_Label{ ActorProfileID: profile.ID, Value: label.Val, }) } } return &profile }