an app.bsky.* indexer

add ActorDeclaration (chat)

Changed files
+41 -5
cmd
monarch
models
+9 -4
cmd/monarch/handlers.go
···
func NewHandlerService(store *gorm.DB) *HandlerService {
migrations := []any{
+
// app.bsky.*
&models.ActorProfile{},
&models.ActorProfile_Label{},
&models.ActorProfile_JoinedViaStarterPack{},
···
&models.LabelerService_ReasonType{},
&models.LabelerService_SubjectCollection{},
&models.LabelerService_SubjectType{},
+
+
// chat.bsky.*
+
&models.ActorDeclaration{},
}
for _, migration := range migrations {
store.AutoMigrate(migration)
···
return fmt.Errorf("error upserting labeler service: %w", err)
}
-
default:
-
return nil
+
case syntax.NSID("chat.bsky.actor.declaration"):
+
declaration := models.NewActorDeclaration(uri, *rec)
+
if err := hs.store.Where(models.ActorDeclaration{ID: string(uri)}).Assign(declaration).FirstOrCreate(&models.ActorDeclaration{}).Error; err != nil {
+
return fmt.Errorf("error upserting chat actor declaration: %w", err)
+
}
}
-
-
slog.Info("created record", "uri", uri)
return nil
}
+31
models/actor_declaration.go
···
+
package models
+
+
import (
+
"bytes"
+
"log/slog"
+
"time"
+
+
chatbsky "github.com/bluesky-social/indigo/api/chat"
+
"github.com/bluesky-social/indigo/atproto/syntax"
+
)
+
+
type ActorDeclaration struct {
+
ID string `gorm:"primaryKey"`
+
+
AllowIncoming string
+
+
AutoCreatedAt time.Time `gorm:"autoCreateTime"`
+
AutoUpdatedAt time.Time `gorm:"autoUpdateTime"`
+
}
+
+
func NewActorDeclaration(uri syntax.ATURI, rec []byte) *ActorDeclaration {
+
var out chatbsky.ActorDeclaration
+
if err := out.UnmarshalCBOR(bytes.NewReader(rec)); err != nil {
+
slog.Error("could not unmarshal chat actor declaration CBOR", "err", err)
+
return nil
+
}
+
+
return &ActorDeclaration{
+
AllowIncoming: out.AllowIncoming,
+
}
+
}
+1 -1
models/models.go
···
// - [X] GraphStarterpack *
// - [X] GraphVerification *
// - [X] LabelerService *
-
// - [ ] ActorDeclaration
+
// - [X] ActorDeclaration
// - [ ] LexiconSchema *