Classification of ActivityPub objects.
ActivityPub applications often have different processing rules for actors, activities, collections and other objects. In most cases, the class of an object can be inferred from its context: object delivered to inbox is expected to be an activity, and the value of its actor
property is expected to be an actor.
But in some cases the class can not be inferred, for example:
object
of Update
activity can be an object or an actor.object
of Announce
activity can be an object or an activity.Applications may use the type
property to determine object’s class, but that hinders interoperabilty because such applications would not be able to process objects with unknown types. Therefore, a different approach would be preferable.
Activity Streams 2.0 standard defines 8 core object types:
Object
Link
Activity
IntransitiveActivity
Collection
OrderedCollection
CollectionPage
OrderedCollectionPage
The Actor
type is also mentioned, but it is not a core type.
Unfortunately, definitions provided in the specification are not precise. The lack of good definitions and the exclusion of the Actor
type make standard classification unsuitable for practical purposes. Therefore, applications may need to use a different classification.
One way to divide objects into distinct classes is to look at their properties and their connections to other objects (indicated by their properties). This approach can be used to define 6 core types:
Object
Actor
Activity
(includes intransitive activities)Collection
(includes collection pages)VerificationMethod
Link
The next section specifies an algorithm that classifies any ActivityPub object as one of these core types by analyzing object’s shape. This technique is often referred to as duck typing.
The following algorithm can be used to determine the core type of the object:
publicKeyPem
or publicKeyMultibase
property, return VerificationMethod
.href
property, return Link
.inbox
and outbox
properties, return Actor
.actor
property, return Activity
.items
, orderedItems
, totalItems
, partOf
, first
, last
, next
, prev
or current
property, return Collection
.Object
.Application of this algorithm results in non-overlapping core types. For example, an actor with items
property is still an actor and not a collection.
The value of type
property is not taken into consideration.
[!WARNING] ActivityPub standard requires actors to have both
inbox
andoutbox
properties, but in practiceoutbox
is not always present. If compatibility with non-conformant implementations is desirable, step #3 can be changed to “If object hasinbox
property, returnActor
”.
[!WARNING] Pleroma adds an
actor
property to objects that are not activities. To make an allowance for that, the step #4 of the algorithm can be changed to “If object has anactor
property, and doesn’t have anattributedTo
property, returnActivity
”.
The alternative to duck typing is to use multiple types. For example, this object can be unambiguously identified as an Activity
:
{
"type": ["Bite", "Activity"]
}
However, existing implementations don’t add a second type, and even if changing all of them were possible, duck typing would still need to be used as a fallback during the transitional period.
CC0 1.0 Universal (CC0 1.0) Public Domain Dedication
To the extent possible under law, the authors of this Fediverse Enhancement Proposal have waived all copyright and related or neighboring rights to this work.