+9
-4
cmd/monarch/handlers.go
+9
-4
cmd/monarch/handlers.go
···
17
17
18
18
func NewHandlerService(store *gorm.DB) *HandlerService {
19
19
migrations := []any{
20
+
// app.bsky.*
20
21
&models.ActorProfile{},
21
22
&models.ActorProfile_Label{},
22
23
&models.ActorProfile_JoinedViaStarterPack{},
···
57
58
&models.LabelerService_ReasonType{},
58
59
&models.LabelerService_SubjectCollection{},
59
60
&models.LabelerService_SubjectType{},
61
+
62
+
// chat.bsky.*
63
+
&models.ActorDeclaration{},
60
64
}
61
65
for _, migration := range migrations {
62
66
store.AutoMigrate(migration)
···
171
175
return fmt.Errorf("error upserting labeler service: %w", err)
172
176
}
173
177
174
-
default:
175
-
return nil
178
+
case syntax.NSID("chat.bsky.actor.declaration"):
179
+
declaration := models.NewActorDeclaration(uri, *rec)
180
+
if err := hs.store.Where(models.ActorDeclaration{ID: string(uri)}).Assign(declaration).FirstOrCreate(&models.ActorDeclaration{}).Error; err != nil {
181
+
return fmt.Errorf("error upserting chat actor declaration: %w", err)
182
+
}
176
183
}
177
-
178
-
slog.Info("created record", "uri", uri)
179
184
180
185
return nil
181
186
}
+31
models/actor_declaration.go
+31
models/actor_declaration.go
···
1
+
package models
2
+
3
+
import (
4
+
"bytes"
5
+
"log/slog"
6
+
"time"
7
+
8
+
chatbsky "github.com/bluesky-social/indigo/api/chat"
9
+
"github.com/bluesky-social/indigo/atproto/syntax"
10
+
)
11
+
12
+
type ActorDeclaration struct {
13
+
ID string `gorm:"primaryKey"`
14
+
15
+
AllowIncoming string
16
+
17
+
AutoCreatedAt time.Time `gorm:"autoCreateTime"`
18
+
AutoUpdatedAt time.Time `gorm:"autoUpdateTime"`
19
+
}
20
+
21
+
func NewActorDeclaration(uri syntax.ATURI, rec []byte) *ActorDeclaration {
22
+
var out chatbsky.ActorDeclaration
23
+
if err := out.UnmarshalCBOR(bytes.NewReader(rec)); err != nil {
24
+
slog.Error("could not unmarshal chat actor declaration CBOR", "err", err)
25
+
return nil
26
+
}
27
+
28
+
return &ActorDeclaration{
29
+
AllowIncoming: out.AllowIncoming,
30
+
}
31
+
}