an app.bsky.* indexer

add ActorDeclaration (chat)

Changed files
+41 -5
cmd
monarch
models
+9 -4
cmd/monarch/handlers.go
··· 17 18 func NewHandlerService(store *gorm.DB) *HandlerService { 19 migrations := []any{ 20 &models.ActorProfile{}, 21 &models.ActorProfile_Label{}, 22 &models.ActorProfile_JoinedViaStarterPack{}, ··· 57 &models.LabelerService_ReasonType{}, 58 &models.LabelerService_SubjectCollection{}, 59 &models.LabelerService_SubjectType{}, 60 } 61 for _, migration := range migrations { 62 store.AutoMigrate(migration) ··· 171 return fmt.Errorf("error upserting labeler service: %w", err) 172 } 173 174 - default: 175 - return nil 176 } 177 - 178 - slog.Info("created record", "uri", uri) 179 180 return nil 181 }
··· 17 18 func NewHandlerService(store *gorm.DB) *HandlerService { 19 migrations := []any{ 20 + // app.bsky.* 21 &models.ActorProfile{}, 22 &models.ActorProfile_Label{}, 23 &models.ActorProfile_JoinedViaStarterPack{}, ··· 58 &models.LabelerService_ReasonType{}, 59 &models.LabelerService_SubjectCollection{}, 60 &models.LabelerService_SubjectType{}, 61 + 62 + // chat.bsky.* 63 + &models.ActorDeclaration{}, 64 } 65 for _, migration := range migrations { 66 store.AutoMigrate(migration) ··· 175 return fmt.Errorf("error upserting labeler service: %w", err) 176 } 177 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 + } 183 } 184 185 return nil 186 }
+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 + }
+1 -1
models/models.go
··· 16 // - [X] GraphStarterpack * 17 // - [X] GraphVerification * 18 // - [X] LabelerService * 19 - // - [ ] ActorDeclaration 20 // - [ ] LexiconSchema *
··· 16 // - [X] GraphStarterpack * 17 // - [X] GraphVerification * 18 // - [X] LabelerService * 19 + // - [X] ActorDeclaration 20 // - [ ] LexiconSchema *