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