diff options
author | Mark Felder <feld@FreeBSD.org> | 2020-11-11 09:36:46 -0600 |
---|---|---|
committer | Mark Felder <feld@feld.me> | 2021-05-11 16:50:10 -0500 |
commit | 3d43ee2aeb37814c43fc01d3141cd7f3a4fa9e17 (patch) | |
tree | 35f8f844d64cbd77f05efd9b007b1740065ae05a | |
parent | f00608ef05678d5f7cede35412f04c501575db67 (diff) | |
download | pleroma-3d43ee2aeb37814c43fc01d3141cd7f3a4fa9e17.tar.gz |
Support lists of potential keywords to match on, rename some assignments for clarity
-rw-r--r-- | lib/pleroma/web/activity_pub/mrf/auto_subject_policy.ex | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/lib/pleroma/web/activity_pub/mrf/auto_subject_policy.ex b/lib/pleroma/web/activity_pub/mrf/auto_subject_policy.ex index 32f2d50ee..7386d5acc 100644 --- a/lib/pleroma/web/activity_pub/mrf/auto_subject_policy.ex +++ b/lib/pleroma/web/activity_pub/mrf/auto_subject_policy.ex @@ -13,13 +13,18 @@ defmodule Pleroma.Web.ActivityPub.MRF.AutoSubjectPolicy do @behaviour Pleroma.Web.ActivityPub.MRF - defp string_matches?(string, _) when not is_binary(string) do + defp string_matches?(content, _) when not is_binary(content) do false end - defp string_matches?(string, pattern) when is_binary(pattern) do - wordlist = string |> String.split(" ", trim: true) |> Enum.uniq() - pattern in wordlist + defp string_matches?(content, keyword) when is_list(keyword) do + wordlist = content |> String.downcase() |> String.split(" ", trim: true) |> Enum.uniq() + Enum.any?(keyword, fn match -> String.downcase(match) in wordlist end) + end + + defp string_matches?(content, keyword) when is_binary(keyword) do + wordlist = content |> String.downcase() |> String.split(" ", trim: true) |> Enum.uniq() + String.downcase(keyword) in wordlist end defp check_subject(%{"object" => %{} = object} = message) do @@ -34,9 +39,9 @@ defmodule Pleroma.Web.ActivityPub.MRF.AutoSubjectPolicy do auto_summary = Enum.map( Pleroma.Config.get([:mrf_auto_subject, :match]), - fn {pat, key} -> - if string_matches?(String.downcase(object["content"]), String.downcase(pat)) do - key + fn {keyword, subject} -> + if string_matches?(object["content"], keyword) do + subject end end ) |