ActivityPub/Primer/Like activity
The Like activity is used to indicate that an actor likes a particular object, including activities.
"Liking" an object is often represented by a star or heart in the user interface. It is a 0 or 1 state; either the object is "liked" or it is not.
There is a "Dislike" activity in Activity Streams 2.0, but it is not used in ActivityPub.
Client to server
Here are some things to check when validating a new Like activity received from the client:
- Check that the object of the activity exists.
- Check that the object of the activity is not already in the actor's
likedcollection. - Check that the actor has permission to view the object, such as being one of the addressees of the object or its
Createactivity. - Check that the actor is not blocked by the responsible actor for the object.
If these checks work,
- Add the
objectto the actor'slikedcollection.
There are then two paths to follow:
- If it is a local object (on the same server), add the `Like` activity to the `likes` collection for the object.
- Otherwise, the server should send the
Likeactivity to the actor responsible for the object, typically theattributedTooractorvalue.
Server to server
Here are some things to check when validating a new Like activity received from another server:
- Check that the
objectof the activity exists. - Check that the
objectof the activity is an object on the local server. Otherwise, the Like activity can be safely treated like any other activity with no side effects. - Check that the
actorof the activity is not the actor of an existingLikeactivity in thelikescollection of the object. - Check that the responsible actor for the object has not blocked the actor of the
Like. - Check that the actor has permission to view the object, such as being one of the addressees of the object or its
Createactivity.
If these checks work:
- Add the
Likeactivity to thelikescollection of the object.
likes collection
Most implementations treat the permission to view the object (for example, by being an addressee) as permission to add to the likes collection.
This is not mandated by ActivityPub, and it's reasonable to add additional restrictions. It's also reasonable to allow the responsible actor to manually remove activities from the likes collection.
Undo Like activity
Client to server
Here are some things to check when validating a new Undo activity with a Like activity as the object received from the client:
- Check that the
Likeactivity exists. - Check that the actor of the
Undoactivity is the same actor as of theLikeactivity. - Check that the object of the
Likeactivity is in thelikedcollection of the actor.
If these checks pass, then:
- Remove the object from the actor's
likedcollection.
And then two paths exist:
- If the object is local, remove the
Likeactivity from the object'slikescollection. - If the object is remote, send the
Undoactivity to the responsible actor for the object.
Server to server
When an Undo activity with a Like activity as its object has been received, here are some important things to do:
- Check that the
Likeactivity exists. - Check that the actor of the
Undoactivity is the same actor as of theLikeactivity. - Check that the object is local. Otherwise, the activity can be treated as having no side effects.
- Check that the
Likeactivity is in thelikescollection of the object.
If these checks pass, then:
- Remove the
Likeactivity from the object'slikescollection.
Multiple Like activities
An actor sending more than one Like activity for the same object is not discussed in the ActivityPub spec. However, most implementations treat the liked collection of the actor as unique by object id, and most implementations treat the likes collection of the object as unique by actor id.
Given this situation, some recommendations for best practices to maximize interoperation:
- Originating servers should avoid sending multiple
Likeactivities for the same object. - Receiving servers that receive multiple
Likeactivities for the same object, and treatlikedandlikesas unique, should quietly ignore all activities except the first.