Pleroma instance running on expired.mentality.rip https://expired.mentality.rip
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
1.4 KiB

  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.Web.ActivityPub.MRF.NotifyLocalUsersPolicy do
  5. alias Pleroma.User
  6. @behaviour Pleroma.Web.ActivityPub.MRF
  7. @moduledoc "Notifies all local users by configurable tag in subject field (only for admins)"
  8. require Pleroma.Constants
  9. @impl true
  10. def filter(
  11. %{
  12. "type" => "Create",
  13. "to" => to,
  14. "actor" => actor,
  15. "object" => object
  16. } = message
  17. )
  18. when is_map(object) do
  19. user = User.get_cached_by_ap_id(actor)
  20. if user.is_admin and object["inReplyTo"] == nil do
  21. tag = Pleroma.Config.get([:mrf_notifylocalusers, :tag])
  22. if object["summary"] == tag do
  23. ap_ids =
  24. User.Query.build(%{local: true, internal: false, deactivated: false})
  25. |> Pleroma.Repo.all()
  26. |> Enum.map(fn s -> s.ap_id end)
  27. to = to ++ ap_ids
  28. object =
  29. object
  30. |> Map.put("to", to)
  31. message =
  32. message
  33. |> Map.put("to", to)
  34. |> Map.put("object", object)
  35. {:ok, message}
  36. else
  37. {:ok, message}
  38. end
  39. else
  40. {:ok, message}
  41. end
  42. end
  43. @impl true
  44. def filter(message), do: {:ok, message}
  45. @impl true
  46. def describe, do: {:ok, %{}}
  47. end