aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorrinpatch <rinpatch@sdf.org>2019-02-04 12:36:50 +0000
committerrinpatch <rinpatch@sdf.org>2019-02-04 12:36:50 +0000
commit89762ad23034668f7440c9fb238dcf270e8c2e59 (patch)
tree3ed0ba0d8d1e00a74f39fa14b9e114b9f366e919 /lib
parentc57f37bd36702fa8865366fbfaea9ac3f28dfad3 (diff)
parent58262a8b8a759ecb69663a92a56f65b6e16db6ea (diff)
downloadpleroma-89762ad23034668f7440c9fb238dcf270e8c2e59.tar.gz
Merge branch 'feature/hellthread-filter-improvements' into 'develop'
Improve hellthread filter Closes #584 See merge request pleroma/pleroma!766
Diffstat (limited to 'lib')
-rw-r--r--lib/pleroma/config/deprecation_warnings.ex7
-rw-r--r--lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex44
2 files changed, 42 insertions, 9 deletions
diff --git a/lib/pleroma/config/deprecation_warnings.ex b/lib/pleroma/config/deprecation_warnings.ex
index dc50682ee..0eb1833aa 100644
--- a/lib/pleroma/config/deprecation_warnings.ex
+++ b/lib/pleroma/config/deprecation_warnings.ex
@@ -12,6 +12,13 @@ defmodule Pleroma.Config.DeprecationWarnings do
You are using the old configuration mechanism for the frontend. Please check config.md.
""")
end
+
+ if Pleroma.Config.get(:mrf_hellthread, :threshold) do
+ Logger.warn("""
+ !!!DEPRECATION WARNING!!!
+ You are using the old configuration mechanism for the hellthread filter. Please check config.md.
+ """)
+ end
end
def warn do
diff --git a/lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex b/lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex
index a3f516ae7..4c6e612b2 100644
--- a/lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex
+++ b/lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex
@@ -3,20 +3,46 @@
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.ActivityPub.MRF.HellthreadPolicy do
+ alias Pleroma.User
@behaviour Pleroma.Web.ActivityPub.MRF
+ defp delist_message(message) do
+ follower_collection = User.get_cached_by_ap_id(message["actor"]).follower_address
+
+ message
+ |> Map.put("to", [follower_collection])
+ |> Map.put("cc", ["https://www.w3.org/ns/activitystreams#Public"])
+ end
+
@impl true
- def filter(%{"type" => "Create"} = object) do
- threshold = Pleroma.Config.get([:mrf_hellthread, :threshold])
- recipients = (object["to"] || []) ++ (object["cc"] || [])
-
- if length(recipients) > threshold do
- {:reject, nil}
- else
- {:ok, object}
+ def filter(%{"type" => "Create"} = message) do
+ delist_threshold = Pleroma.Config.get([:mrf_hellthread, :delist_threshold])
+
+ reject_threshold =
+ Pleroma.Config.get(
+ [:mrf_hellthread, :reject_threshold],
+ Pleroma.Config.get([:mrf_hellthread, :threshold])
+ )
+
+ recipients = (message["to"] || []) ++ (message["cc"] || [])
+
+ cond do
+ length(recipients) > reject_threshold and reject_threshold > 0 ->
+ {:reject, nil}
+
+ length(recipients) > delist_threshold and delist_threshold > 0 ->
+ if Enum.member?(message["to"], "https://www.w3.org/ns/activitystreams#Public") or
+ Enum.member?(message["cc"], "https://www.w3.org/ns/activitystreams#Public") do
+ {:ok, delist_message(message)}
+ else
+ {:ok, message}
+ end
+
+ true ->
+ {:ok, message}
end
end
@impl true
- def filter(object), do: {:ok, object}
+ def filter(message), do: {:ok, message}
end