Changed references of "Pleroma" to "Akkoma" in email text
[akkoma] / lib / pleroma / web / activity_pub / mrf / force_bot_unlisted_policy.ex
index 7290f444b2a17fad9806ed89ec793d6012fef276..fa6b93333c75c9c45ba5f1b28b038647fcf2a6ca 100644 (file)
@@ -1,36 +1,32 @@
 # Pleroma: A lightweight social networking server
-# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Web.ActivityPub.MRF.ForceBotUnlistedPolicy do
   alias Pleroma.User
-  @behaviour Pleroma.Web.ActivityPub.MRF
+  @behaviour Pleroma.Web.ActivityPub.MRF.Policy
   @moduledoc "Remove bot posts from federated timeline"
 
   require Pleroma.Constants
 
-  defp check_by_actor_type(user) do
-    if user.actor_type in ["Application", "Service"], do: 1.0, else: 0.0
-  end
-
-  defp check_by_nickname(user) do
-    if Regex.match?(~r/bot@|ebooks@/i, user.nickname), do: 1.0, else: 0.0
-  end
+  defp check_by_actor_type(user), do: user.actor_type in ["Application", "Service"]
+  defp check_by_nickname(user), do: Regex.match?(~r/bot@|ebooks@/i, user.nickname)
 
-  defp botness_score(user), do: check_by_actor_type(user) + check_by_nickname(user)
+  defp check_if_bot(user), do: check_by_actor_type(user) or check_by_nickname(user)
 
   @impl true
   def filter(
         %{
-          "type" => "Create",
+          "type" => type,
           "to" => to,
           "cc" => cc,
           "actor" => actor,
           "object" => object
         } = message
-      ) do
+      )
+      when type in ["Create", "Update"] do
     user = User.get_cached_by_ap_id(actor)
-    isbot = 0.8 < botness_score(user)
+    isbot = check_if_bot(user)
 
     if isbot and Enum.member?(to, Pleroma.Constants.as_public()) do
       to = List.delete(to, Pleroma.Constants.as_public()) ++ [user.follower_address]