an app.bsky.* indexer
at master 1.7 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 ActorProfile struct { 13 ID string `gorm:"primaryKey"` 14 15 // Avatar 16 // Banner 17 CreatedAt *string 18 Description *string 19 DisplayName *string 20 JoinedViaStarterPack *StrongRef `gorm:"embedded;embeddedPrefix:starterpack_"` 21 Labels []ActorProfile_Label 22 PinnedPost *StrongRef `gorm:"embedded;embeddedPrefix:pinnedpost_"` 23 24 AutoCreatedAt time.Time `gorm:"autoCreateTime"` 25 AutoUpdatedAt time.Time `gorm:"autoUpdateTime"` 26} 27 28type ActorProfile_Label struct { 29 ActorProfileID string 30 Value string 31} 32 33func NewActorProfile(uri syntax.ATURI, rec []byte) *ActorProfile { 34 var out appbsky.ActorProfile 35 if err := out.UnmarshalCBOR(bytes.NewReader(rec)); err != nil { 36 slog.Error("could not unmarshal actor profile CBOR", "err", err) 37 return nil 38 } 39 40 profile := ActorProfile{ 41 ID: string(uri), 42 CreatedAt: out.CreatedAt, 43 Description: out.Description, 44 DisplayName: out.DisplayName, 45 } 46 47 if out.JoinedViaStarterPack != nil { 48 profile.JoinedViaStarterPack = &StrongRef{ 49 Uri: out.JoinedViaStarterPack.Uri, 50 Cid: out.JoinedViaStarterPack.Cid, 51 } 52 } 53 54 if out.PinnedPost != nil { 55 profile.PinnedPost = &StrongRef{ 56 Uri: out.PinnedPost.Uri, 57 Cid: out.PinnedPost.Cid, 58 } 59 } 60 61 if out.Labels != nil && out.Labels.LabelDefs_SelfLabels != nil && out.Labels.LabelDefs_SelfLabels.Values != nil { 62 for _, label := range out.Labels.LabelDefs_SelfLabels.Values { 63 profile.Labels = append(profile.Labels, ActorProfile_Label{ 64 ActorProfileID: profile.ID, 65 Value: label.Val, 66 }) 67 } 68 } 69 70 return &profile 71}