1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.ActivityPub.Pipeline do
10 alias Pleroma.Web.ActivityPub.ActivityPub
11 alias Pleroma.Web.ActivityPub.MRF
12 alias Pleroma.Web.ActivityPub.ObjectValidator
13 alias Pleroma.Web.ActivityPub.SideEffects
14 alias Pleroma.Web.Federator
16 @spec common_pipeline(map(), keyword()) ::
17 {:ok, Activity.t() | Object.t(), keyword()} | {:error, any()}
18 def common_pipeline(object, meta) do
19 case Repo.transaction(fn -> do_common_pipeline(object, meta) end) do
20 {:ok, {:ok, activity, meta}} ->
21 SideEffects.handle_after_transaction(meta)
32 def do_common_pipeline(object, meta) do
33 with {_, {:ok, validated_object, meta}} <-
34 {:validate_object, ObjectValidator.validate(object, meta)},
35 {_, {:ok, mrfd_object}} <- {:mrf_object, MRF.filter(validated_object)},
36 {_, {:ok, activity, meta}} <-
37 {:persist_object, ActivityPub.persist(mrfd_object, meta)},
38 {_, {:ok, activity, meta}} <-
39 {:execute_side_effects, SideEffects.handle(activity, meta)},
40 {_, {:ok, _}} <- {:federation, maybe_federate(activity, meta)} do
43 {:mrf_object, {:reject, _}} -> {:ok, nil, meta}
48 defp maybe_federate(%Object{}, _), do: {:ok, :not_federated}
50 defp maybe_federate(%Activity{} = activity, meta) do
51 with {:ok, local} <- Keyword.fetch(meta, :local) do
52 do_not_federate = meta[:do_not_federate] || !Config.get([:instance, :federating])
54 if !do_not_federate && local do
55 Federator.publish(activity)
61 _e -> {:error, :badarg}