diff --git a/lib/pleroma/web/activity_pub/mrf/notify_local_users_policy.ex b/lib/pleroma/web/activity_pub/mrf/notify_local_users_policy.ex new file mode 100644 index 000000000..3bbbaa19d --- /dev/null +++ b/lib/pleroma/web/activity_pub/mrf/notify_local_users_policy.ex @@ -0,0 +1,55 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2020 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + +defmodule Pleroma.Web.ActivityPub.MRF.NotifyLocalUsersPolicy do + alias Pleroma.User + @behaviour Pleroma.Web.ActivityPub.MRF + @moduledoc "Notifies all local users by configurable tag in subject field (only for admins)" + + require Pleroma.Constants + + @impl true + def filter( + %{ + "type" => "Create", + "to" => to, + "actor" => actor, + "object" => object + } = message + ) + when is_map(object) do + user = User.get_cached_by_ap_id(actor) + + if user.is_admin and object["inReplyTo"] == nil do + tag = Pleroma.Config.get([:mrf_notifylocalusers, :tag]) + if object["summary"] == tag do + ap_ids = + User.Query.build(%{local: true, internal: false, deactivated: false}) + |> Pleroma.Repo.all() + |> Enum.map(fn s -> s.ap_id end) + to = to ++ ap_ids + + object = + object + |> Map.put("to", to) + + message = + message + |> Map.put("to", to) + |> Map.put("object", object) + {:ok, message} + else + {:ok, message} + end + else + {:ok, message} + end + end + + @impl true + def filter(message), do: {:ok, message} + + @impl true + def describe, do: {:ok, %{}} +end