1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.ActivityPub.MRF.HellthreadPolicy do
7 @behaviour Pleroma.Web.ActivityPub.MRF
9 defp delist_message(message) do
10 follower_collection = User.get_cached_by_ap_id(message["actor"]).follower_address
13 |> Map.put("to", [follower_collection])
14 |> Map.put("cc", ["https://www.w3.org/ns/activitystreams#Public"])
17 defp get_recipient_count(message) do
18 recipients = (message["to"] || []) ++ (message["cc"] || [])
21 Enum.member?(recipients, "https://www.w3.org/ns/activitystreams#Public") &&
22 Enum.find(recipients, &String.ends_with?(&1, "/followers")) ->
23 length(recipients) - 2
25 Enum.member?(recipients, "https://www.w3.org/ns/activitystreams#Public") ||
26 Enum.find(recipients, &String.ends_with?(&1, "/followers")) ->
27 length(recipients) - 1
35 def filter(%{"type" => "Create"} = message) do
36 delist_threshold = Pleroma.Config.get([:mrf_hellthread, :delist_threshold])
40 [:mrf_hellthread, :reject_threshold],
41 Pleroma.Config.get([:mrf_hellthread, :threshold])
44 recipients = get_recipient_count(message)
47 recipients > reject_threshold and reject_threshold > 0 ->
50 recipients > delist_threshold and delist_threshold > 0 ->
51 if Enum.member?(message["to"], "https://www.w3.org/ns/activitystreams#Public") or
52 Enum.member?(message["cc"], "https://www.w3.org/ns/activitystreams#Public") do
53 {:ok, delist_message(message)}
64 def filter(message), do: {:ok, message}