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 []ActorProfile_JoinedViaStarterPack Labels []ActorProfile_Label PinnedPost []ActorProfile_PinnedPost AutoCreatedAt time.Time `gorm:"autoCreateTime"` AutoUpdatedAt time.Time `gorm:"autoUpdateTime"` } type ActorProfile_Label struct { ActorProfileID string Value string } type ActorProfile_JoinedViaStarterPack struct { ActorProfileID string StrongRef } type ActorProfile_PinnedPost struct { ActorProfileID string StrongRef } 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 = append(profile.JoinedViaStarterPack, ActorProfile_JoinedViaStarterPack{ ActorProfileID: profile.ID, StrongRef: StrongRef{ Uri: out.JoinedViaStarterPack.Uri, Cid: out.JoinedViaStarterPack.Cid, }, }) } if out.PinnedPost != nil { profile.PinnedPost = append(profile.PinnedPost, ActorProfile_PinnedPost{ ActorProfileID: profile.ID, StrongRef: 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 }