defmodule Pleroma.Web.ActivityPub.ActivityPub do
alias Pleroma.{Activity, Repo, Object, Upload, User, Notification}
- alias Pleroma.Web.ActivityPub.Transmogrifier
+ alias Pleroma.Web.ActivityPub.{Transmogrifier, MRF}
alias Pleroma.Web.WebFinger
alias Pleroma.Web.Federator
alias Pleroma.Web.OStatus
@httpoison Application.get_env(:pleroma, :httpoison)
@instance Application.get_env(:pleroma, :instance)
- @rewrite_policy Keyword.get(@instance, :rewrite_policy)
def get_recipients(data) do
(data["to"] || []) ++ (data["cc"] || [])
def insert(map, local \\ true) when is_map(map) do
with nil <- Activity.get_by_ap_id(map["id"]),
map <- lazy_put_activity_defaults(map),
- {:ok, map} <- @rewrite_policy.filter(map),
+ {:ok, map} <- MRF.filter(map),
:ok <- insert_full_object(map) do
{:ok, activity} =
Repo.insert(%Activity{
--- /dev/null
+defmodule Pleroma.Web.ActivityPub.MRF do
+
+ @callback filter(Map.t) :: {:ok | :reject, Map.t}
+
+ def filter(object) do
+ get_policies()
+ |> Enum.reduce({:ok, object}, fn
+ (policy, {:ok, object}) ->
+ policy.filter(object)
+ (_, error) -> error
+ end)
+ end
+
+ def get_policies() do
+ Application.get_env(:pleroma, :instance, [])
+ |> Keyword.get(:rewrite_policy, [])
+ |> get_policies()
+ end
+ def get_policies(policy) when is_atom(policy), do: [policy]
+ def get_policies(policies) when is_list(policies), do: policies
+end