View Source ActivityPub (Bonfire v0.9.10-cooperation-beta.108)

ActivityPub Library for elixir.

WORK IN PROGRESS, TESTING FEDERATION WITH DIFFERENT IMPLEMENTATIONS IS UNDERWAY

Installation

  1. Add this library to your dependencies in mix.exs
defp deps do
  [...]
  {:activity_pub, git: "https://github.com/bonfire-networks/activity_pub.git", branch: "stable"} # branch can "stable", or "develop" for the bleeding edge
end
  1. Create an adapter module. To start, one created at lib/my_app/adapter.ex might look like
defmodule MyApp.Adapter do
  @moduledoc """
  Adapter functions delegated from the `ActivityPub` Library
  """

  @behaviour ActivityPub.Federator.Adapter
end

Note that, due to the defined @behavior, Elixir will warn you that the required functions

  • base_url/0
  • get_actor_by_id/1
  • get_actor_by_username/1
  • get_follower_local_ids/1
  • get_following_local_ids/1
  • get_redirect_url/1
  • handle_activity/1
  • maybe_create_remote_actor/1
  • maybe_publish_object/2
  • update_local_actor/2
  • update_remote_actor/1

have not yet been implemented though you will be able to start your app. Defining these allows ActivityPub to handle ActivityPub HTTP and database calls and operations. An example of an implemented adaptor can be found here.

Then set it in config

config :activity_pub, :adapter, MyApp.Adapter
  1. Set your application repo in config
config :activity_pub, :repo, MyApp.Repo
  1. Create a new ecto migration and call ActivityPub.Migration.up/0 from it

  2. Inject AP routes to your router by adding use ActivityPub.Web.Router to your app's router module

  3. Copy the default AP config to your app's confix.exs

config :activity_pub, :mrf_simple,
  media_removal: [],
  media_nsfw: [],
  report_removal: [],
  accept: [],
  avatar_removal: [],
  banner_removal: []

config :activity_pub, :instance,
  hostname: "example.com",
  federation_publisher_modules: [ActivityPub.Federator.APPublisher],
  federation_reachability_timeout_days: 7,
  federating: true,
  rewrite_policy: []

config :activity_pub, :http,
  proxy_url: nil,
  user_agent: "Your app name",
  send_user_agent: true,
  adapter: [
    ssl_options: [
      # Workaround for remote server certificate chain issues
      partial_chain: &:hackney_connect.partial_chain/1,
      # We don't support TLS v1.3 yet
      versions: [:tlsv1, :"tlsv1.1", :"tlsv1.2"]
    ]
  ]
  1. Change the hostname value in the instance config block to your instance's hostname

  2. If you don't already have Oban set up, follow the Oban installation intructions and add the AP queues:

config :my_app, Oban, queues: [federator_incoming: 50, federator_outgoing: 50, remote_fetcher: 20]

Now you should be able to compile and run your app and move over to integration.

This module is the entrypoint to the ActivityPub API for processing incoming and outgoing federated objects (normalising, saving the the Object storage, passing them to the adapter, and queueing outgoing activities to be pushed out).

In general, the functions in this module take object-like map. That includes a struct as the input for actor parameters. Use the functions in the ActivityPub.Actor module (ActivityPub.Actor.get_cached/1 for example) to retrieve those.

Summary

Functions

Generates and federates an Accept activity via the data passed through params.

Generates and federates a Create activity via the data passed through params.

Generates and federates a Follow activity.

Record a Like

Generates and federates a Reject activity via the data passed through params.

Generates and federates an Unfollow activity.

Functions

@spec accept(%{
  :to => [any()],
  :actor => ActivityPub.Actor.t(),
  :object => map() | binary(),
  optional(atom()) => any()
}) :: {:ok, ActivityPub.Object.t()} | {:error, any()}

Generates and federates an Accept activity via the data passed through params.

@spec create(%{
  :to => [any()],
  :actor => ActivityPub.Actor.t(),
  :context => binary(),
  :object => map(),
  optional(atom()) => any()
}) :: {:ok, ActivityPub.Object.t()} | {:error, any()}

Generates and federates a Create activity via the data passed through params.

Link to this function

delete(object, is_local?, opts \\ [])

View Source
@spec flag(%{
  :actor => ActivityPub.Actor.t(),
  :context => binary(),
  :account => ActivityPub.Actor.t(),
  :statuses => [any()],
  :content => binary(),
  optional(atom()) => any()
}) :: {:ok, ActivityPub.Object.t()} | {:error, any()}

Generates and federates a Follow activity.

Note: the follow should be reflected as a Follow on the host database side only after receiving an Accept activity in response (though you could register it as a Request if your app has that concept)

Record a Like

Link to this function

move(origin, target, local \\ true, recursing \\ false)

View Source
@spec reject(%{to: [any()], actor: ActivityPub.Actor.t(), object: binary()}) ::
  {:ok, ActivityPub.Object.t()} | {:error, any()}

Generates and federates a Reject activity via the data passed through params.

Generates and federates an Unfollow activity.