an app.bsky.* indexer

add GraphList

Changed files
+64 -1
cmd
monarch
models
+8
cmd/monarch/handlers.go
···
&models.FeedGenerator_Label{},
&models.GraphBlock{},
+
+
&models.GraphList{},
}
for _, migration := range migrations {
store.AutoMigrate(migration)
···
block := models.NewGraphBlock(uri, *rec)
if err := hs.store.Where(models.GraphBlock{ID: string(uri)}).Assign(block).FirstOrCreate(&models.GraphBlock{}).Error; err != nil {
return fmt.Errorf("error upserting graph block: %w", err)
+
}
+
+
case syntax.NSID("app.bsky.graph.list"):
+
list := models.NewGraphList(uri, *rec)
+
if err := hs.store.Where(models.GraphList{ID: string(uri)}).Assign(list).FirstOrCreate(&models.GraphList{}).Error; err != nil {
+
return fmt.Errorf("error upserting graph list: %w", err)
}
}
+55
models/graph_list.go
···
+
package models
+
+
import (
+
"bytes"
+
"log/slog"
+
"time"
+
+
appbsky "github.com/bluesky-social/indigo/api/bsky"
+
"github.com/bluesky-social/indigo/atproto/syntax"
+
)
+
+
type GraphList struct {
+
ID string `gorm:"primaryKey"`
+
+
// TODO: Avatar, DescriptionFacets
+
+
CreatedAt string
+
Description *string
+
Labels []GraphList_Label
+
Name string
+
Purpose *string
+
+
AutoCreatedAt time.Time `gorm:"autoCreateTime"`
+
AutoUpdatedAt time.Time `gorm:"autoUpdateTime"`
+
}
+
+
type GraphList_Label struct {
+
GraphListID string
+
Value string
+
}
+
+
func NewGraphList(uri syntax.ATURI, rec []byte) *GraphList {
+
var out appbsky.GraphList
+
if err := out.UnmarshalCBOR(bytes.NewReader(rec)); err != nil {
+
slog.Error("could not unmarshal graph list CBOR", "err", err)
+
return nil
+
}
+
+
list := GraphList{
+
CreatedAt: out.CreatedAt,
+
Description: out.Description,
+
Name: out.Name,
+
Purpose: out.Purpose,
+
}
+
+
if out.Labels != nil && out.Labels.LabelDefs_SelfLabels != nil && out.Labels.LabelDefs_SelfLabels.Values != nil {
+
for _, label := range out.Labels.LabelDefs_SelfLabels.Values {
+
list.Labels = append(list.Labels, GraphList_Label{
+
Value: label.Val,
+
})
+
}
+
}
+
+
return &list
+
}
+1 -1
models/models.go
···
// - [ ] FeedThreadgate
// - [X] GraphBlock *
// - [ ] GraphFollow
-
// - [ ] GraphList *
+
// - [X] GraphList *
// - [ ] GraphListblock *
// - [ ] GraphListitem *
// - [ ] GraphStarterpack *