Rename test, add check for follower collection when delisting
authorKaren Konou <konoukaren@gmail.com>
Fri, 15 Feb 2019 12:43:14 +0000 (13:43 +0100)
committerKaren Konou <konoukaren@gmail.com>
Fri, 15 Feb 2019 12:43:14 +0000 (13:43 +0100)
lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex
test/web/activity_pub/mrf/hellthread_policy_test.exs

index 95211c596a08a28fc9eb5388c1ff3eb45eeb109d..1fd7b9c67668b7c2992d0bfdb4021f3de6e2bcca 100644 (file)
@@ -10,17 +10,22 @@ defmodule Pleroma.Web.ActivityPub.MRF.HellthreadPolicy do
     delist_threshold = Pleroma.Config.get([:mrf_hellthread, :delist_threshold])
     follower_collection = User.get_cached_by_ap_id(message["actor"]).follower_address
 
+    follower_collection? = Enum.member?(message["to"] ++ message["cc"], follower_collection)
+
     message =
-      with {:public, recipients} <- get_recipient_count(message) do
-        if recipients > delist_threshold and delist_threshold > 0 do
+      case recipients = get_recipient_count(message) do
+        {:public, _} when follower_collection? and recipients > delist_threshold ->
           message
           |> Map.put("to", [follower_collection])
           |> Map.put("cc", ["https://www.w3.org/ns/activitystreams#Public"])
-        else
+
+        {:public, _} when recipients > delist_threshold ->
+          message
+          |> Map.put("to", [])
+          |> Map.put("cc", ["https://www.w3.org/ns/activitystreams#Public"])
+
+        _ ->
           message
-        end
-      else
-        _ -> message
       end
 
     {:ok, message}
index b5bdd35ccc95f29237687923409833a16ce895b5..ebf9997cd4fa758073785fdaddd038f15be20aa3 100644 (file)
@@ -41,7 +41,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.HellthreadPolicyTest do
       assert "https://www.w3.org/ns/activitystreams#Public" in message["cc"]
     end
 
-    test "threshold test", %{message: message} do
+    test "excludes follower collection and public URI from threshold count", %{message: message} do
       Pleroma.Config.put([:mrf_hellthread], %{delist_threshold: 0, reject_threshold: 3})
 
       {:ok, _} = filter(message)