From 24cec4e7aab33b6c44ba6d1ecf16895f254351b8 Mon Sep 17 00:00:00 2001 From: tobi <31960611+tsmethurst@users.noreply.github.com> Date: Wed, 1 Mar 2023 18:52:44 +0100 Subject: [feature] Federate pinned posts (aka `featuredCollection`) in and out (#1560) * start fiddling * the ol' fiddle + update * start working on fetching statuses * poopy doopy doo where r u uwu * further adventures in featuring statuses * finishing up * fmt * simply status unpin loop * move empty featured check back to caller function * remove unnecessary log.WithContext calls * remove unnecessary IsIRI() checks * add explanatory comment about status URIs * change log level to error * better test names --- internal/typeutils/internaltoas.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'internal/typeutils/internaltoas.go') diff --git a/internal/typeutils/internaltoas.go b/internal/typeutils/internaltoas.go index 06b49c18f..bbcf6c84b 100644 --- a/internal/typeutils/internaltoas.go +++ b/internal/typeutils/internaltoas.go @@ -1296,6 +1296,34 @@ func (c *converter) OutboxToASCollection(ctx context.Context, outboxID string) ( return collection, nil } +func (c *converter) StatusesToASFeaturedCollection(ctx context.Context, featuredCollectionID string, statuses []*gtsmodel.Status) (vocab.ActivityStreamsOrderedCollection, error) { + collection := streams.NewActivityStreamsOrderedCollection() + + collectionIDProp := streams.NewJSONLDIdProperty() + featuredCollectionIDURI, err := url.Parse(featuredCollectionID) + if err != nil { + return nil, fmt.Errorf("error parsing url %s", featuredCollectionID) + } + collectionIDProp.SetIRI(featuredCollectionIDURI) + collection.SetJSONLDId(collectionIDProp) + + itemsProp := streams.NewActivityStreamsOrderedItemsProperty() + for _, s := range statuses { + uri, err := url.Parse(s.URI) + if err != nil { + return nil, fmt.Errorf("error parsing url %s", s.URI) + } + itemsProp.AppendIRI(uri) + } + collection.SetActivityStreamsOrderedItems(itemsProp) + + totalItemsProp := streams.NewActivityStreamsTotalItemsProperty() + totalItemsProp.Set(len(statuses)) + collection.SetActivityStreamsTotalItems(totalItemsProp) + + return collection, nil +} + func (c *converter) ReportToASFlag(ctx context.Context, r *gtsmodel.Report) (vocab.ActivityStreamsFlag, error) { flag := streams.NewActivityStreamsFlag() -- cgit v1.2.3