+10
-1
cmd/monarch/handlers.go
+10
-1
cmd/monarch/handlers.go
···
38
38
&models.FeedPostgate_DetachedEmbeddingUri{},
39
39
&models.FeedPostgate_EmbeddingRule{},
40
40
&models.FeedRepost{},
41
+
&models.FeedThreadgate{},
42
+
&models.FeedThreadgate_AllowRule{},
43
+
&models.FeedThreadgate_HiddenReply{},
41
44
42
45
&models.GraphBlock{},
43
46
&models.GraphList{},
···
109
112
110
113
case syntax.NSID("app.bsky.feed.repost"):
111
114
repost := models.NewFeedRepost(uri, *rec)
112
-
if err := hs.store.Where(models.FeedRepost{ID: string(uri)}).Assign(repost).FirstOrCreate(repost).Error; err != nil {
115
+
if err := hs.store.Where(models.FeedRepost{ID: string(uri)}).Assign(repost).FirstOrCreate(&models.FeedRepost{}).Error; err != nil {
113
116
return fmt.Errorf("error upserting feed repost: %w", err)
117
+
}
118
+
119
+
case syntax.NSID("app.bsky.feed.threadgate"):
120
+
threadgate := models.NewFeedThreadgate(uri, *rec)
121
+
if err := hs.store.Where(models.FeedThreadgate{ID: string(uri)}).Assign(threadgate).FirstOrCreate(&models.FeedThreadgate{}).Error; err != nil {
122
+
return fmt.Errorf("error upserting feed threadgate: %w", err)
114
123
}
115
124
116
125
case syntax.NSID("app.bsky.graph.block"):
+87
models/feed_threadgate.go
+87
models/feed_threadgate.go
···
1
+
package models
2
+
3
+
import (
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
+
12
+
type FeedThreadgate struct {
13
+
ID string `gorm:"primaryKey"`
14
+
15
+
AllowRules []FeedThreadgate_AllowRule
16
+
CreatedAt string
17
+
HiddenReplies []FeedThreadgate_HiddenReply
18
+
Post string
19
+
20
+
AutoCreatedAt time.Time `gorm:"autoCreateTime"`
21
+
AutoUpdatedAt time.Time `gorm:"autoUpdateTime"`
22
+
}
23
+
24
+
type FeedThreadgate_AllowRule struct {
25
+
FeedThreadgateID string
26
+
Rule string
27
+
}
28
+
29
+
type FeedThreadgate_HiddenReply struct {
30
+
FeedThreadgateID string
31
+
Uri string
32
+
}
33
+
34
+
func NewFeedThreadgate(uri syntax.ATURI, rec []byte) *FeedThreadgate {
35
+
var out appbsky.FeedThreadgate
36
+
if err := out.UnmarshalCBOR(bytes.NewReader(rec)); err != nil {
37
+
slog.Error("could not unmarshal feed threadgate CBOR", "err", err)
38
+
return nil
39
+
}
40
+
41
+
threadgate := FeedThreadgate{
42
+
ID: string(uri),
43
+
CreatedAt: out.CreatedAt,
44
+
Post: out.Post,
45
+
}
46
+
47
+
for _, hidden := range out.HiddenReplies {
48
+
threadgate.HiddenReplies = append(threadgate.HiddenReplies, FeedThreadgate_HiddenReply{
49
+
FeedThreadgateID: threadgate.ID,
50
+
Uri: hidden,
51
+
})
52
+
}
53
+
54
+
if out.Allow != nil {
55
+
for _, rule := range out.Allow {
56
+
if rule.FeedThreadgate_MentionRule != nil {
57
+
threadgate.AllowRules = append(threadgate.AllowRules, FeedThreadgate_AllowRule{
58
+
FeedThreadgateID: threadgate.ID,
59
+
Rule: rule.FeedThreadgate_MentionRule.LexiconTypeID,
60
+
})
61
+
}
62
+
63
+
if rule.FeedThreadgate_FollowerRule != nil {
64
+
threadgate.AllowRules = append(threadgate.AllowRules, FeedThreadgate_AllowRule{
65
+
FeedThreadgateID: threadgate.ID,
66
+
Rule: rule.FeedThreadgate_FollowerRule.LexiconTypeID,
67
+
})
68
+
}
69
+
70
+
if rule.FeedThreadgate_FollowingRule != nil {
71
+
threadgate.AllowRules = append(threadgate.AllowRules, FeedThreadgate_AllowRule{
72
+
FeedThreadgateID: threadgate.ID,
73
+
Rule: rule.FeedThreadgate_FollowingRule.LexiconTypeID,
74
+
})
75
+
}
76
+
77
+
if rule.FeedThreadgate_ListRule != nil {
78
+
threadgate.AllowRules = append(threadgate.AllowRules, FeedThreadgate_AllowRule{
79
+
FeedThreadgateID: threadgate.ID,
80
+
Rule: rule.FeedThreadgate_ListRule.LexiconTypeID,
81
+
})
82
+
}
83
+
}
84
+
}
85
+
86
+
return &threadgate
87
+
}