From 8d64efe22909fc3dbc579a68dcb65e7e907806d8 Mon Sep 17 00:00:00 2001 From: Evan Jarrett Date: Fri, 19 Dec 2025 10:00:21 -0600 Subject: [PATCH] clean up some lexicon usage --- pkg/atproto/lexicon.go | 3 +++ pkg/hold/pds/manifest_post.go | 7 ++++--- pkg/hold/pds/manifest_post_test.go | 5 +++-- pkg/hold/pds/status.go | 12 ++++-------- pkg/hold/pds/status_test.go | 13 +++---------- pkg/hold/pds/xrpc.go | 2 +- 6 files changed, 18 insertions(+), 24 deletions(-) diff --git a/pkg/atproto/lexicon.go b/pkg/atproto/lexicon.go index af4d8a3..cbb7d32 100644 --- a/pkg/atproto/lexicon.go +++ b/pkg/atproto/lexicon.go @@ -41,6 +41,9 @@ const ( // TangledProfileCollection is the collection name for tangled profiles // Stored in hold's embedded PDS (singleton record at rkey "self") TangledProfileCollection = "sh.tangled.actor.profile" + + // BskyPostCollection is the collection name for Bluesky posts + BskyPostCollection = "app.bsky.feed.post" // SailorProfileCollection is the collection name for user profiles SailorProfileCollection = "io.atcr.sailor.profile" diff --git a/pkg/hold/pds/manifest_post.go b/pkg/hold/pds/manifest_post.go index 2bc73d2..9d53baf 100644 --- a/pkg/hold/pds/manifest_post.go +++ b/pkg/hold/pds/manifest_post.go @@ -9,6 +9,7 @@ import ( "strings" "time" + "atcr.io/pkg/atproto" bsky "github.com/bluesky-social/indigo/api/bsky" "github.com/distribution/distribution/v3/registry/storage/driver" ) @@ -70,7 +71,7 @@ func (p *HoldPDS) CreateManifestPost( // Create post struct with facets and embed post := &bsky.FeedPost{ - LexiconTypeID: "app.bsky.feed.post", + LexiconTypeID: atproto.BskyPostCollection, Text: text, Facets: facets, Embed: embed, @@ -82,7 +83,7 @@ func (p *HoldPDS) CreateManifestPost( rkey, recordCID, err := p.repomgr.CreateRecord( ctx, p.uid, - "app.bsky.feed.post", + atproto.BskyPostCollection, post, ) @@ -91,7 +92,7 @@ func (p *HoldPDS) CreateManifestPost( } // Build ATProto URI for the post - postURI := fmt.Sprintf("at://%s/app.bsky.feed.post/%s", p.did, rkey) + postURI := fmt.Sprintf("at://%s/%s/%s", p.did, atproto.BskyPostCollection, rkey) slog.Info("Created manifest post", "uri", postURI, diff --git a/pkg/hold/pds/manifest_post_test.go b/pkg/hold/pds/manifest_post_test.go index f602686..8a43a20 100644 --- a/pkg/hold/pds/manifest_post_test.go +++ b/pkg/hold/pds/manifest_post_test.go @@ -4,6 +4,7 @@ import ( "strings" "testing" + "atcr.io/pkg/atproto" bsky "github.com/bluesky-social/indigo/api/bsky" ) @@ -196,7 +197,7 @@ func TestSimplifiedPostFormat(t *testing.T) { // Verify the complete post structure post := &bsky.FeedPost{ - LexiconTypeID: "app.bsky.feed.post", + LexiconTypeID: atproto.BskyPostCollection, Text: text, Facets: facets, Langs: []string{"en"}, @@ -250,7 +251,7 @@ func TestSimplifiedPostFormat_MultiArch(t *testing.T) { // Verify the complete post structure post := &bsky.FeedPost{ - LexiconTypeID: "app.bsky.feed.post", + LexiconTypeID: atproto.BskyPostCollection, Text: text, Facets: facets, Langs: []string{"en"}, diff --git a/pkg/hold/pds/status.go b/pkg/hold/pds/status.go index 02b6f18..b779827 100644 --- a/pkg/hold/pds/status.go +++ b/pkg/hold/pds/status.go @@ -6,14 +6,10 @@ import ( "log/slog" "time" + "atcr.io/pkg/atproto" bsky "github.com/bluesky-social/indigo/api/bsky" ) -const ( - // StatusPostCollection is the collection name for Bluesky posts - StatusPostCollection = "app.bsky.feed.post" -) - // 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 @@ -40,20 +36,20 @@ func (p *HoldPDS) createStatusPost(ctx context.Context, text string) error { // Create post struct now := time.Now() post := &bsky.FeedPost{ - LexiconTypeID: "app.bsky.feed.post", + 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, StatusPostCollection, post) + 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", StatusPostCollection, + "collection", atproto.BskyPostCollection, "rkey", rkey, "cid", recordCID.String(), "text", text) diff --git a/pkg/hold/pds/status_test.go b/pkg/hold/pds/status_test.go index cee6e56..430f36c 100644 --- a/pkg/hold/pds/status_test.go +++ b/pkg/hold/pds/status_test.go @@ -61,7 +61,7 @@ func TestStatusPost(t *testing.T) { listPosts := func() ([]map[string]any, error) { req := makeXRPCGetRequest(atproto.RepoListRecords, map[string]string{ "repo": did, - "collection": StatusPostCollection, + "collection": atproto.BskyPostCollection, "limit": "100", "reverse": "true", // Most recent first }) @@ -134,8 +134,8 @@ func TestStatusPost(t *testing.T) { } // URI format: at://did:web:test.example.com/app.bsky.feed.post/3m3c4... // We just check that it contains the collection - if !contains(uri, StatusPostCollection) { - t.Errorf("Expected URI to contain collection %s, got %s", StatusPostCollection, uri) + if !contains(uri, atproto.BskyPostCollection) { + t.Errorf("Expected URI to contain collection %s, got %s", atproto.BskyPostCollection, uri) } }) @@ -226,13 +226,6 @@ func TestStatusPost(t *testing.T) { }) } -func TestStatusPostCollection(t *testing.T) { - // Verify constant - if StatusPostCollection != "app.bsky.feed.post" { - t.Errorf("Expected StatusPostCollection 'app.bsky.feed.post', got '%s'", StatusPostCollection) - } -} - // Helper function to check if a string contains a substring func contains(s, substr string) bool { return len(s) >= len(substr) && (s == substr || len(s) > len(substr) && findSubstring(s, substr)) diff --git a/pkg/hold/pds/xrpc.go b/pkg/hold/pds/xrpc.go index 774709d..2834bab 100644 --- a/pkg/hold/pds/xrpc.go +++ b/pkg/hold/pds/xrpc.go @@ -366,7 +366,7 @@ func (h *XRPCHandler) buildProfileResponse(ctx context.Context) map[string]any { repoHandle, err := repo.OpenRepo(ctx, session, head) if err == nil { postCount := 0 - _ = repoHandle.ForEach(ctx, "app.bsky.feed.post", func(k string, v cid.Cid) error { + _ = repoHandle.ForEach(ctx, atproto.BskyPostCollection, func(k string, v cid.Cid) error { postCount++ return nil })