ActivityPub/Primer/Like activity

From W3C Wiki

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 liked collection.
  • Check that the actor has permission to view the object, such as being one of the addressees of the object or its Create activity.
  • Check that the actor is not blocked by the responsible actor for the object.

If these checks work,

  • Add the object to the actor's liked collection.

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 Like activity to the actor responsible for the object, typically the attributedTo or actor value.

Server to server

Here are some things to check when validating a new Like activity received from another server:

  • Check that the object of the activity exists.
  • Check that the object of 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 actor of the activity is not the actor of an existing Like activity in the likes collection 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 Create activity.

If these checks work:

  • Add the Like activity to the likes collection 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 Like activity exists.
  • Check that the actor of the Undo activity is the same actor as of the Like activity.
  • Check that the object of the Like activity is in the liked collection of the actor.

If these checks pass, then:

  • Remove the object from the actor's liked collection.

And then two paths exist:

  • If the object is local, remove the Like activity from the object's likes collection.
  • If the object is remote, send the Undo activity 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 Like activity exists.
  • Check that the actor of the Undo activity is the same actor as of the Like activity.
  • Check that the object is local. Otherwise, the activity can be treated as having no side effects.
  • Check that the Like activity is in the likes collection of the object.

If these checks pass, then:

  • Remove the Like activity from the object's likes collection.

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 Like activities for the same object.
  • Receiving servers that receive multiple Like activities for the same object, and treat liked and likes as unique, should quietly ignore all activities except the first.