Files
at-container-registry/pkg/hold/pds/status.go
T

58 lines
1.5 KiB
Go

package pds
import (
"context"
"fmt"
"log/slog"
"time"
"atcr.io/pkg/atproto"
bsky "github.com/bluesky-social/indigo/api/bsky"
)
// SetStatus creates a new status post on Bluesky
// status should be "online" or "offline"
// Each call creates a unique post with a TID-based rkey
func (p *HoldPDS) SetStatus(ctx context.Context, status string) error {
// Check if Bluesky posts are enabled
if !p.enableBlueskyPosts {
slog.Debug("Bluesky posts disabled, skipping status post", "status", status)
return nil
}
// Format the post text with emoji indicator
emoji := "🟢"
if status == "offline" {
emoji = "🔴"
}
text := fmt.Sprintf("%s Current status: %s", emoji, status)
// Create the post with a unique TID
return p.createStatusPost(ctx, text)
}
// createStatusPost creates a new status post with a TID-based rkey
func (p *HoldPDS) createStatusPost(ctx context.Context, text string) error {
// Create post struct
now := time.Now()
post := &bsky.FeedPost{
LexiconTypeID: atproto.BskyPostCollection,
Text: text,
CreatedAt: now.Format(time.RFC3339),
}
// Use repomgr.CreateRecord to create the post with auto-generated TID
// CreateRecord automatically generates a unique TID using the repo's clock
rkey, recordCID, err := p.repomgr.CreateRecord(ctx, p.uid, atproto.BskyPostCollection, post)
if err != nil {
return fmt.Errorf("failed to create status post: %w", err)
}
slog.Info("Created status post",
"collection", atproto.BskyPostCollection,
"rkey", rkey,
"cid", recordCID.String(),
"text", text)
return nil
}