an app.bsky.* indexer

add ActorStatus

Changed files
+66 -2
cmd
monarch
models
+10 -1
cmd/monarch/handlers.go
···
&models.ActorProfile_Label{},
&models.ActorProfile_JoinedViaStarterPack{},
&models.ActorProfile_PinnedPost{},
+
+
&models.ActorStatus{},
+
&models.ActorStatus_Embed{},
}
for _, migration := range migrations {
store.AutoMigrate(migration)
···
case syntax.NSID("app.bsky.actor.profile"):
profile := models.NewActorProfile(uri, *rec)
if err := hs.store.Where(models.ActorProfile{ID: string(uri)}).Assign(profile).FirstOrCreate(&models.ActorProfile{}).Error; err != nil {
-
return fmt.Errorf("error upserting profile: %w", err)
+
return fmt.Errorf("error upserting actor profile: %w", err)
+
}
+
+
case syntax.NSID("app.bsky.actor.status"):
+
status := models.NewActorStatus(uri, *rec)
+
if err := hs.store.Where(models.ActorStatus{ID: string(uri)}).Assign(status).FirstOrCreate(&models.ActorStatus{}).Error; err != nil {
+
return fmt.Errorf("error upserting actor status: %w", err)
}
}
+1 -1
models/actor_profile.go
···
func NewActorProfile(uri syntax.ATURI, rec []byte) *ActorProfile {
var out appbsky.ActorProfile
if err := out.UnmarshalCBOR(bytes.NewReader(rec)); err != nil {
-
slog.Error("could not unmarshal profile CBOR", "err", err)
+
slog.Error("could not unmarshal actor profile CBOR", "err", err)
return nil
}
+54
models/actor_status.go
···
+
package models
+
+
import (
+
"bytes"
+
"log/slog"
+
"time"
+
+
appbsky "github.com/bluesky-social/indigo/api/bsky"
+
"github.com/bluesky-social/indigo/atproto/syntax"
+
)
+
+
type ActorStatus struct {
+
ID string `gorm:"primaryKey"`
+
+
CreatedAt string
+
DurationMinutes *int64
+
Embed *ActorStatus_Embed
+
Status string
+
+
AutoCreatedAt time.Time `gorm:"autoCreateTime"`
+
AutoUpdatedAt time.Time `gorm:"autoUpdateTime"`
+
}
+
+
type ActorStatus_Embed struct {
+
ActorStatusID string
+
Description string
+
Title string
+
Uri string
+
}
+
+
func NewActorStatus(uri syntax.ATURI, rec []byte) *ActorStatus {
+
var out appbsky.ActorStatus
+
if err := out.UnmarshalCBOR(bytes.NewReader(rec)); err != nil {
+
slog.Error("could not unmarshal actor status CBOR", "err", err)
+
return nil
+
}
+
+
status := ActorStatus{
+
CreatedAt: out.CreatedAt,
+
DurationMinutes: out.DurationMinutes,
+
Status: out.Status,
+
}
+
+
if out.Embed != nil && out.Embed.EmbedExternal != nil && out.Embed.EmbedExternal.External != nil {
+
status.Embed = &ActorStatus_Embed{
+
ActorStatusID: status.ID,
+
Description: out.Embed.EmbedExternal.External.Description,
+
Title: out.Embed.EmbedExternal.External.Title,
+
Uri: out.Embed.EmbedExternal.External.Uri,
+
}
+
}
+
+
return &status
+
}
+1
models/models.go
···
package models
+
// ActorProfile
// ActorStatus
// FeedGenerator
// FeedLike