2019-10-23 09:52:27 +00:00
|
|
|
# Pleroma: A lightweight social networking server
|
2020-03-26 14:37:42 +00:00
|
|
|
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
2019-10-23 09:52:27 +00:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
defmodule Pleroma.Web.ActivityPub.Pipeline do
|
|
|
|
alias Pleroma.Activity
|
2020-04-28 14:26:19 +00:00
|
|
|
alias Pleroma.Object
|
2019-10-23 09:52:27 +00:00
|
|
|
alias Pleroma.Web.ActivityPub.ActivityPub
|
|
|
|
alias Pleroma.Web.ActivityPub.MRF
|
|
|
|
alias Pleroma.Web.ActivityPub.ObjectValidator
|
|
|
|
alias Pleroma.Web.ActivityPub.SideEffects
|
|
|
|
alias Pleroma.Web.Federator
|
|
|
|
|
2020-04-28 14:26:19 +00:00
|
|
|
@spec common_pipeline(map(), keyword()) ::
|
|
|
|
{:ok, Activity.t() | Object.t(), keyword()} | {:error, any()}
|
2019-10-23 09:52:27 +00:00
|
|
|
def common_pipeline(object, meta) do
|
|
|
|
with {_, {:ok, validated_object, meta}} <-
|
|
|
|
{:validate_object, ObjectValidator.validate(object, meta)},
|
|
|
|
{_, {:ok, mrfd_object}} <- {:mrf_object, MRF.filter(validated_object)},
|
2020-04-28 14:26:19 +00:00
|
|
|
{_, {:ok, activity, meta}} <-
|
2019-10-23 09:52:27 +00:00
|
|
|
{:persist_object, ActivityPub.persist(mrfd_object, meta)},
|
2020-04-28 14:26:19 +00:00
|
|
|
{_, {:ok, activity, meta}} <-
|
2019-10-23 09:52:27 +00:00
|
|
|
{:execute_side_effects, SideEffects.handle(activity, meta)},
|
|
|
|
{_, {:ok, _}} <- {:federation, maybe_federate(activity, meta)} do
|
|
|
|
{:ok, activity, meta}
|
|
|
|
else
|
2020-03-26 14:45:28 +00:00
|
|
|
{:mrf_object, {:reject, _}} -> {:ok, nil, meta}
|
2019-10-23 09:52:27 +00:00
|
|
|
e -> {:error, e}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-04-28 14:26:19 +00:00
|
|
|
defp maybe_federate(%Object{}, _), do: {:ok, :not_federated}
|
|
|
|
|
|
|
|
defp maybe_federate(%Activity{} = activity, meta) do
|
2019-10-23 09:52:27 +00:00
|
|
|
with {:ok, local} <- Keyword.fetch(meta, :local) do
|
|
|
|
if local do
|
|
|
|
Federator.publish(activity)
|
|
|
|
{:ok, :federated}
|
|
|
|
else
|
|
|
|
{:ok, :not_federated}
|
|
|
|
end
|
|
|
|
else
|
2020-03-24 18:24:09 +00:00
|
|
|
_e -> {:error, :badarg}
|
2019-10-23 09:52:27 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|