ActivityPub/Primer/Follow activity

From W3C Wiki

Client to server

The Follow activity is how follow connections are initiated on the ActivityPub network. Here are some things to check when validating a new Follow 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 following collection.
  • Check that the object of the activity is an actor that can be followed. Actors have at least an inbox and an outbox property.
  • Check that an outstanding Follow request has not already been made. It may be useful to store outstanding Follow requests in an easy-to-find way in your storage.

If these checks work, there are two paths to follow:

  • If it is a local actor (on the same server), and the actor does not require manually confirming follows, then you can simply implement the follow. See the ActivityPub/Primer/Accept activity for how to do this.
  • Otherwise, the server should send the Follow activity to the object actor for approval. No additional modifications to the social graph should be made until an Accept or Reject activity is received.

Server to server

The Follow activity is how follow connections are initiated on the ActivityPub network. Here are some things to check when validating a new Follow 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 Follow activity can be safely treated like any other activity with no side effects.
  • Check that the object of the activity is an actor that can be followed. Actors have at least an inbox and an outbox property.
  • Check that the actor of the activity is not already in the object's followers collection.
  • Check that an outstanding Follow request has not already been made. It may be useful to store outstanding Follow requests in an easy-to-find way in your storage.

If these checks work, there are two paths to follow:

  • If the recipient does not require manually confirming follows, then you can simply create the connection and send an Accept activity in response.
  • If the recipient does require manually confirming follows, the server should allow the actor to review the follow and either accept or reject. A typical implementation shows new follow requests in a separate section of the UI. Another option is including the Follow activity in the actor's inbox for review.

To create the connection, there are two steps:

  • Add the actor of the activity to the object's followers collection.
  • Add the object of the activity to the actor's following collection.

Note that if the actor or the object are on a different server, these collections might not be canonical for the actor or object, but just a cache of the remote data. It's also reasonable not to cache these remote collections and to always retrieve them from the remote server.

Multiple Follow activities

An actor sending more than one Follow activity for the same actor is not discussed in the ActivityPub spec.

However, most implementations treat the followers and following collections of the actor as unique by actor id.

Given this situation, some recommendations for best practices to maximize interoperation:

Originating servers should avoid sending multiple Follow activities from the same actor for the same object. Receiving servers that receive multiple Follow activities from the same actor for the same object, and treat following and followers as unique, should quietly ignore all activities except the first.