ActivityPub
An ActivityPub model refers to all the django model classes that map to the Activity Streams/ActivityPub core types.
There are two primary base types for ActivityPub: Object
and Link
.
Considering that all the other types (Activity
, Actor
,
Collection
) are subtypes of Object
, we have the following Django
model classes:
CoreType
At the root we have the "CoreType" model. This model contains nothing
but the internal identifier for the resource - i.e, not its URI.
This class is defined to be able to represent relationships to objects
that can be represented by either one of Object
or Link
BaseActivityStreamsObject
This model is not abstract, but it is used mostly to allow us to
define the subtypes of Object
. You won't be using this class
directly most of the time.
Object
The type attribute is one choice defined by the Object.Types
enum class, where each value map to the Activity Streams types (e.g, Note
, Image
, Video
, Question
, etc...).
>>> from activitypub.models import Object
>>> my_note = Object(type=Object.Types.NOTE, content='Writing good documentation is an art that I am yet to master')
>>> my_note.save()
>>> print(my_note.type)
https://www.w3.org/ns/activitystreams#Note
Actor
Actors are the entities that carry out activities. They also are a
subtype of BaseActivityStreamsObject
and can be of type
Person
,Group
, Service
, Application
, etc.
>>> from activitypub.models import Actor
>>> my_bot = Actor.objects.filter(type=Actor.Types.SERVICE).first()
>>> print(my_bot.name)
'My bot'
Activity
Activities are the actions executed by the actors. They are also a
subtype of
BaseActivityStreamsObject
and its types map to all the possible types of activities (eg.
Follow
, Create
, Delete
, Accept
, etc...)
>>> from activitypub.models import Activity
activity = Activity.objects.create(actor=my_bot, type=Activity.Types.CREATE, object=my_note)
Collection
Collections are containers for other
Object
or
Link
resources. They can be of type
Collection
or OrderedCollection
. The collection has a many-to-many
relationship to CollectionItem
.
If the collection is set with is_ordered
, then all items in the
collections will be listed in the order they were added to the
collection (reverse-chronologically), and it will be of type
as:OrderedCollection
, If the list is not ordered, then the items
will be listed by the order of the "order" attribute.
Collection Page
Collection Pages are also containers for other
Object
or
Link
resources, but which should be seen
as a 'slice' of the Collection. They can be of type CollectionPage
or OrderedCollectionPage
and also have a many-to-many relationship
to CollectionItem
. They are used when the collection itself can grow
too too large - e.g, an outbox containing thousands of activities from
an actor).
Collection Pages are first-class models in ActivityPub Toolkit. They are not just artificial constructs to have a paginated view of the collection items at the view layer. As such, collections should not have collection items directly assigned to them if they are meant to be part of the paginated view.
Link
A Link describes a qualified, indirect reference to another CoreType
record.
Reference
A Reference model is used to store URIs. Any instance of BaseActivityStreamsObject
may contain its reference.
Having reference records separate from its models allows us to process JSON-LD documents that have no real information about the object except its URI. A reference with a valid URI can be fetched and resolved to its underlying object.
Cryptographic Key Pair
The keypair is provided by any actor that needs to authenticate the messages that it sends. Keys are usually referenced by its "key id"
Actors that are controlled by the server application (i.e, its URI is from a local Domain can have keypairs generated by the server.