package models import ( "bytes" "log/slog" "time" appbsky "github.com/bluesky-social/indigo/api/bsky" "github.com/bluesky-social/indigo/atproto/syntax" ) type FeedThreadgate struct { ID string `gorm:"primaryKey"` AllowRules []FeedThreadgate_AllowRule CreatedAt string HiddenReplies []FeedThreadgate_HiddenReply Post string AutoCreatedAt time.Time `gorm:"autoCreateTime"` AutoUpdatedAt time.Time `gorm:"autoUpdateTime"` } type FeedThreadgate_AllowRule struct { FeedThreadgateID string Rule string } type FeedThreadgate_HiddenReply struct { FeedThreadgateID string Uri string } func NewFeedThreadgate(uri syntax.ATURI, rec []byte) *FeedThreadgate { var out appbsky.FeedThreadgate if err := out.UnmarshalCBOR(bytes.NewReader(rec)); err != nil { slog.Error("could not unmarshal feed threadgate CBOR", "err", err) return nil } threadgate := FeedThreadgate{ ID: string(uri), CreatedAt: out.CreatedAt, Post: out.Post, } for _, hidden := range out.HiddenReplies { threadgate.HiddenReplies = append(threadgate.HiddenReplies, FeedThreadgate_HiddenReply{ FeedThreadgateID: threadgate.ID, Uri: hidden, }) } if out.Allow != nil { for _, rule := range out.Allow { if rule.FeedThreadgate_MentionRule != nil { threadgate.AllowRules = append(threadgate.AllowRules, FeedThreadgate_AllowRule{ FeedThreadgateID: threadgate.ID, Rule: rule.FeedThreadgate_MentionRule.LexiconTypeID, }) } if rule.FeedThreadgate_FollowerRule != nil { threadgate.AllowRules = append(threadgate.AllowRules, FeedThreadgate_AllowRule{ FeedThreadgateID: threadgate.ID, Rule: rule.FeedThreadgate_FollowerRule.LexiconTypeID, }) } if rule.FeedThreadgate_FollowingRule != nil { threadgate.AllowRules = append(threadgate.AllowRules, FeedThreadgate_AllowRule{ FeedThreadgateID: threadgate.ID, Rule: rule.FeedThreadgate_FollowingRule.LexiconTypeID, }) } if rule.FeedThreadgate_ListRule != nil { threadgate.AllowRules = append(threadgate.AllowRules, FeedThreadgate_AllowRule{ FeedThreadgateID: threadgate.ID, Rule: rule.FeedThreadgate_ListRule.LexiconTypeID, }) } } } return &threadgate }