logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://hacktivis.me/git/pleroma.git

mention_policy.ex (1349B)


  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.Web.ActivityPub.MRF.MentionPolicy do
  5. @moduledoc "Block messages which mention a user"
  6. @behaviour Pleroma.Web.ActivityPub.MRF.Policy
  7. @impl true
  8. def filter(%{"type" => "Create"} = message) do
  9. reject_actors = Pleroma.Config.get([:mrf_mention, :actors], [])
  10. recipients = (message["to"] || []) ++ (message["cc"] || [])
  11. if rejected_mention =
  12. Enum.find(recipients, fn recipient -> Enum.member?(reject_actors, recipient) end) do
  13. {:reject, "[MentionPolicy] Rejected for mention of #{rejected_mention}"}
  14. else
  15. {:ok, message}
  16. end
  17. end
  18. @impl true
  19. def filter(message), do: {:ok, message}
  20. @impl true
  21. def describe, do: {:ok, %{}}
  22. @impl true
  23. def config_description do
  24. %{
  25. key: :mrf_mention,
  26. related_policy: "Pleroma.Web.ActivityPub.MRF.MentionPolicy",
  27. label: "MRF Mention",
  28. description: "Block messages which mention a specific user",
  29. children: [
  30. %{
  31. key: :actors,
  32. type: {:list, :string},
  33. description: "A list of actors for which any post mentioning them will be dropped",
  34. suggestions: ["actor1", "actor2"]
  35. }
  36. ]
  37. }
  38. end
  39. end