an app.bsky.* indexer
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 []ActorProfile_JoinedViaStarterPack 21 Labels []ActorProfile_Label 22 PinnedPost []ActorProfile_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 33type ActorProfile_JoinedViaStarterPack struct { 34 ActorProfileID string 35 StrongRef 36} 37 38type ActorProfile_PinnedPost struct { 39 ActorProfileID string 40 StrongRef 41} 42 43func NewActorProfile(uri syntax.ATURI, rec []byte) *ActorProfile { 44 var out appbsky.ActorProfile 45 if err := out.UnmarshalCBOR(bytes.NewReader(rec)); err != nil { 46 slog.Error("could not unmarshal actor profile CBOR", "err", err) 47 return nil 48 } 49 50 profile := ActorProfile{ 51 ID: string(uri), 52 CreatedAt: out.CreatedAt, 53 Description: out.Description, 54 DisplayName: out.DisplayName, 55 } 56 57 if out.JoinedViaStarterPack != nil { 58 profile.JoinedViaStarterPack = append(profile.JoinedViaStarterPack, ActorProfile_JoinedViaStarterPack{ 59 ActorProfileID: profile.ID, 60 StrongRef: StrongRef{ 61 Uri: out.JoinedViaStarterPack.Uri, 62 Cid: out.JoinedViaStarterPack.Cid, 63 }, 64 }) 65 } 66 67 if out.PinnedPost != nil { 68 profile.PinnedPost = append(profile.PinnedPost, ActorProfile_PinnedPost{ 69 ActorProfileID: profile.ID, 70 StrongRef: StrongRef{ 71 Uri: out.PinnedPost.Uri, 72 Cid: out.PinnedPost.Cid, 73 }, 74 }) 75 } 76 77 if out.Labels != nil && out.Labels.LabelDefs_SelfLabels != nil && out.Labels.LabelDefs_SelfLabels.Values != nil { 78 for _, label := range out.Labels.LabelDefs_SelfLabels.Values { 79 profile.Labels = append(profile.Labels, ActorProfile_Label{ 80 ActorProfileID: profile.ID, 81 Value: label.Val, 82 }) 83 } 84 } 85 86 return &profile 87}