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 delist_threshold = Pleroma.Config.get([:mrf_hellthread, :delist_threshold])
11 follower_collection = User.get_cached_by_ap_id(message["actor"]).follower_address
14 with {:public, recipients} <- get_recipient_count(message) do
15 if recipients > delist_threshold and delist_threshold > 0 do
17 |> Map.put("to", [follower_collection])
18 |> Map.put("cc", ["https://www.w3.org/ns/activitystreams#Public"])
29 defp reject_message(message) do
32 [:mrf_hellthread, :reject_threshold],
33 Pleroma.Config.get([:mrf_hellthread, :threshold])
36 with {_, recipients} <- get_recipient_count(message) do
37 if recipients > reject_threshold and reject_threshold > 0 do
45 defp get_recipient_count(message) do
46 recipients = (message["to"] || []) ++ (message["cc"] || [])
47 follower_collection = User.get_cached_by_ap_id(message["actor"]).follower_address
49 if Enum.member?(recipients, "https://www.w3.org/ns/activitystreams#Public") do
52 |> List.delete("https://www.w3.org/ns/activitystreams#Public")
53 |> List.delete(follower_collection)
55 {:public, length(recipients)}
59 |> List.delete(follower_collection)
61 {:not_public, length(recipients)}
66 def filter(%{"type" => "Create"} = message) do
67 with {:ok, message} <- reject_message(message),
68 {:ok, message} <- delist_message(message) do
76 def filter(message), do: {:ok, message}