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 FeedLike struct { 13 ID string `gorm:"primaryKey"` 14 15 CreatedAt string 16 Subject FeedLike_Subject 17 Via FeedLike_Via 18 19 AutoCreatedAt time.Time `gorm:"autoCreateTime"` 20 AutoUpdatedAt time.Time `gorm:"autoUpdateTime"` 21} 22 23type FeedLike_Subject struct { 24 FeedLikeID string 25 StrongRef 26} 27 28type FeedLike_Via struct { 29 FeedLikeID string 30 StrongRef 31} 32 33func NewFeedLike(uri syntax.ATURI, rec []byte) *FeedLike { 34 var out appbsky.FeedLike 35 if err := out.UnmarshalCBOR(bytes.NewReader(rec)); err != nil { 36 slog.Error("could not unmarshal feed like CBOR", "err", err) 37 return nil 38 } 39 40 like := FeedLike{ 41 ID: string(uri), 42 CreatedAt: out.CreatedAt, 43 } 44 45 if out.Subject != nil { 46 like.Subject = FeedLike_Subject{ 47 FeedLikeID: like.ID, 48 StrongRef: StrongRef{ 49 Uri: out.Subject.Uri, 50 Cid: out.Subject.Cid, 51 }, 52 } 53 } 54 55 if out.Via != nil { 56 like.Via = FeedLike_Via{ 57 FeedLikeID: like.ID, 58 StrongRef: StrongRef{ 59 Uri: out.Via.Uri, 60 Cid: out.Via.Cid, 61 }, 62 } 63 } 64 65 return &like 66}