Handling collections
In ActivityPub, ActivityStreams collections are frequently used to handle side-effects. For example, when a Follow
activity is sent, the actor is added to the as:followers
collection.
ActivityPods make it easy to create custom collections, thanks to the collection API provided by SemApps. The service and mixin below make us of this API to easily handle collections.
Creating an unordered collection
Here’s how an app can create a custom “Friends” collection and attach it to Alice webId:
See the this page` for available collection options.
Creating an ordered collection
Here’s how to create an ordered collection:
See the this page` for available collection options.
Adding or removing items
Once the collection is created, adding items is pretty straightforward:
Automatically attaching collections to objects
The previous method works well if you want to create collections only on some occasions. But if you want a collection to be attached to all resources of a certain type, you can use the PodCollectionsHandlerMixin
With this new service, the application will listen for creation of resources of type as:Event
on the Pods it is installed, and automatically create and attach the collections.
If you want to attach collections to existing resources of type as:Event
, you can call the createAndAttachMissing
action.
Automatically creating WAC groups
The PodCollectionsHandlerMixin
accepts a createWacGroup
setting. If true, every time a collection is created, a WAC group will also be created with the same slug as the collection. When the add
or remove
actions are called, it will automatically add or remove members from the WAC group.
This option should only be used if you are inserting WebIDs in your collection.