diff options
Diffstat (limited to 'internal/ap')
-rw-r--r-- | internal/ap/activitystreams_test.go | 37 | ||||
-rw-r--r-- | internal/ap/collections.go | 20 |
2 files changed, 44 insertions, 13 deletions
diff --git a/internal/ap/activitystreams_test.go b/internal/ap/activitystreams_test.go index edade9718..050825a1a 100644 --- a/internal/ap/activitystreams_test.go +++ b/internal/ap/activitystreams_test.go @@ -25,6 +25,7 @@ import ( "github.com/superseriousbusiness/activity/streams/vocab" "github.com/superseriousbusiness/gotosocial/internal/ap" "github.com/superseriousbusiness/gotosocial/internal/paging" + "github.com/superseriousbusiness/gotosocial/internal/util" ) func TestASCollection(t *testing.T) { @@ -51,7 +52,7 @@ func TestASCollection(t *testing.T) { ID: parseURI(idURI), First: new(paging.Page), Query: url.Values{"limit": []string{"40"}}, - Total: total, + Total: util.Ptr(total), }) // Serialize collection. @@ -82,7 +83,7 @@ func TestASCollectionTotalOnly(t *testing.T) { // Create new collection using builder function. c := ap.NewASCollection(ap.CollectionParams{ ID: parseURI(idURI), - Total: total, + Total: util.Ptr(total), }) // Serialize collection. @@ -128,7 +129,7 @@ func TestASCollectionPage(t *testing.T) { p := ap.NewASCollectionPage(ap.CollectionPageParams{ CollectionParams: ap.CollectionParams{ ID: parseURI(idURI), - Total: total, + Total: util.Ptr(total), }, Current: currPg, @@ -166,7 +167,7 @@ func TestASOrderedCollection(t *testing.T) { ID: parseURI(idURI), First: new(paging.Page), Query: url.Values{"limit": []string{"40"}}, - Total: total, + Total: util.Ptr(total), }) // Serialize collection. @@ -193,7 +194,31 @@ func TestASOrderedCollectionTotalOnly(t *testing.T) { // Create new collection using builder function. c := ap.NewASOrderedCollection(ap.CollectionParams{ ID: parseURI(idURI), - Total: total, + Total: util.Ptr(total), + }) + + // Serialize collection. + s := toJSON(c) + + // Ensure outputs are equal. + assert.Equal(t, expect, s) +} + +func TestASOrderedCollectionNoTotal(t *testing.T) { + const ( + idURI = "https://zorg.flabormagorg.xyz/users/itsa_me_mario" + ) + + // Create JSON string of expected output. + expect := toJSON(map[string]any{ + "@context": "https://www.w3.org/ns/activitystreams", + "type": "OrderedCollection", + "id": idURI, + }) + + // Create new collection using builder function. + c := ap.NewASOrderedCollection(ap.CollectionParams{ + ID: parseURI(idURI), }) // Serialize collection. @@ -239,7 +264,7 @@ func TestASOrderedCollectionPage(t *testing.T) { p := ap.NewASOrderedCollectionPage(ap.CollectionPageParams{ CollectionParams: ap.CollectionParams{ ID: parseURI(idURI), - Total: total, + Total: util.Ptr(total), }, Current: currPg, diff --git a/internal/ap/collections.go b/internal/ap/collections.go index 62c81fd57..43b7541e4 100644 --- a/internal/ap/collections.go +++ b/internal/ap/collections.go @@ -321,7 +321,8 @@ type CollectionParams struct { Query url.Values // Total no. items. - Total int + // Omitted if nil. + Total *int } type CollectionPageParams struct { @@ -367,6 +368,7 @@ type CollectionPageBuilder interface { // vocab.ActivityStreamsOrderedItemsProperty type ItemsPropertyBuilder interface { AppendIRI(*url.URL) + AppendActivityStreamsCreate(vocab.ActivityStreamsCreate) // NOTE: add more of the items-property-like interface // functions here as you require them for building pages. @@ -409,9 +411,11 @@ func buildCollection[C CollectionBuilder](collection C, params CollectionParams) collection.SetJSONLDId(idProp) // Add the collection totalItems count property. - totalItems := streams.NewActivityStreamsTotalItemsProperty() - totalItems.Set(params.Total) - collection.SetActivityStreamsTotalItems(totalItems) + if params.Total != nil { + totalItems := streams.NewActivityStreamsTotalItemsProperty() + totalItems.Set(*params.Total) + collection.SetActivityStreamsTotalItems(totalItems) + } // No First page means we're done. if params.First == nil { @@ -497,9 +501,11 @@ func buildCollectionPage[C CollectionPageBuilder, I ItemsPropertyBuilder](collec } // Add the collection totalItems count property. - totalItems := streams.NewActivityStreamsTotalItemsProperty() - totalItems.Set(params.Total) - collectionPage.SetActivityStreamsTotalItems(totalItems) + if params.Total != nil { + totalItems := streams.NewActivityStreamsTotalItemsProperty() + totalItems.Set(*params.Total) + collectionPage.SetActivityStreamsTotalItems(totalItems) + } if params.Append == nil { // nil check outside the for loop. |