an app.bsky.* indexer

add GraphListitem

Changed files
+43 -1
cmd
monarch
models
+7
cmd/monarch/handlers.go
···
&models.GraphBlock{},
&models.GraphList{},
&models.GraphListblock{},
+
&models.GraphListitem{},
}
for _, migration := range migrations {
store.AutoMigrate(migration)
···
listblock := models.NewGraphListblock(uri, *rec)
if err := hs.store.Where(models.GraphListblock{ID: string(uri)}).Assign(listblock).FirstOrCreate(&models.GraphListblock{}).Error; err != nil {
return fmt.Errorf("error upserting graph listblock: %w", err)
+
}
+
+
case syntax.NSID("app.bsky.graph.listitem"):
+
listitem := models.NewGraphListitem(uri, *rec)
+
if err := hs.store.Where(models.GraphListitem{ID: string(uri)}).Assign(listitem).FirstOrCreate(&models.GraphListitem{}).Error; err != nil {
+
return fmt.Errorf("error upserting graph listitem: %w", err)
}
}
+35
models/graph_listitem.go
···
+
package models
+
+
import (
+
"bytes"
+
"log/slog"
+
"time"
+
+
appbsky "github.com/bluesky-social/indigo/api/bsky"
+
"github.com/bluesky-social/indigo/atproto/syntax"
+
)
+
+
type GraphListitem struct {
+
ID string `gorm:"primaryKey"`
+
+
CreatedAt string
+
List string
+
Subject string
+
+
AutoCreatedAt time.Time `gorm:"autoCreateTime"`
+
AutoUpdatedAt time.Time `gorm:"autoUpdateTime"`
+
}
+
+
func NewGraphListitem(uri syntax.ATURI, rec []byte) *GraphListitem {
+
var out appbsky.GraphListitem
+
if err := out.UnmarshalCBOR(bytes.NewReader(rec)); err != nil {
+
slog.Error("could not unmarshal graph listitem CBOR", "err", err)
+
return nil
+
}
+
+
return &GraphListitem{
+
CreatedAt: out.CreatedAt,
+
List: out.List,
+
Subject: out.Subject,
+
}
+
}
+1 -1
models/models.go
···
// - [ ] GraphFollow
// - [X] GraphList *
// - [X] GraphListblock *
-
// - [ ] GraphListitem *
+
// - [X] GraphListitem *
// - [ ] GraphStarterpack *
// - [ ] GraphVerification *
// - [ ] LabelerService *