Rename test, add check for follower collection when delisting

This commit is contained in:
Karen Konou 2019-02-15 13:43:14 +01:00
parent d943c90249
commit dca6bee2f7
2 changed files with 12 additions and 7 deletions

View file

@ -10,17 +10,22 @@ defp delist_message(message) do
delist_threshold = Pleroma.Config.get([:mrf_hellthread, :delist_threshold]) delist_threshold = Pleroma.Config.get([:mrf_hellthread, :delist_threshold])
follower_collection = User.get_cached_by_ap_id(message["actor"]).follower_address follower_collection = User.get_cached_by_ap_id(message["actor"]).follower_address
follower_collection? = Enum.member?(message["to"] ++ message["cc"], follower_collection)
message = message =
with {:public, recipients} <- get_recipient_count(message) do case recipients = get_recipient_count(message) do
if recipients > delist_threshold and delist_threshold > 0 do {:public, _} when follower_collection? and recipients > delist_threshold ->
message message
|> Map.put("to", [follower_collection]) |> Map.put("to", [follower_collection])
|> Map.put("cc", ["https://www.w3.org/ns/activitystreams#Public"]) |> 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 message
end
else
_ -> message
end end
{:ok, message} {:ok, message}

View file

@ -41,7 +41,7 @@ test "delist test", %{user: user, message: message} do
assert "https://www.w3.org/ns/activitystreams#Public" in message["cc"] assert "https://www.w3.org/ns/activitystreams#Public" in message["cc"]
end 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}) Pleroma.Config.put([:mrf_hellthread], %{delist_threshold: 0, reject_threshold: 3})
{:ok, _} = filter(message) {:ok, _} = filter(message)