activitypub: mrf: tag policy: refactor the filtering hook a bit
authorWilliam Pitcock <nenolod@dereferenced.org>
Mon, 4 Feb 2019 17:06:37 +0000 (17:06 +0000)
committerWilliam Pitcock <nenolod@dereferenced.org>
Mon, 4 Feb 2019 17:06:37 +0000 (17:06 +0000)
lib/pleroma/web/activity_pub/mrf/tag_policy.ex

index 2af36616fbde389211a1274634066b3c4b57d7d4..dd3129707c28b21c441c6910f1c948cfa2ddd834 100644 (file)
@@ -87,9 +87,8 @@ defmodule Pleroma.Web.ActivityPub.MRF.TagPolicy do
 
   defp process_tag(_, message), do: {:ok, message}
 
-  @impl true
-  def filter(%{"object" => target_actor, "type" => "Follow"} = message) do
-    User.get_cached_by_ap_id(target_actor)
+  def filter_message(actor, message) do
+    User.get_cached_by_ap_id(actor)
     |> get_tags()
     |> Enum.reduce({:ok, message}, fn
       tag, {:ok, message} ->
@@ -101,17 +100,12 @@ defmodule Pleroma.Web.ActivityPub.MRF.TagPolicy do
   end
 
   @impl true
-  def filter(%{"actor" => actor, "type" => "Create"} = message) do
-    User.get_cached_by_ap_id(actor)
-    |> get_tags()
-    |> Enum.reduce({:ok, message}, fn
-      tag, {:ok, message} ->
-        process_tag(tag, message)
+  def filter(%{"object" => target_actor, "type" => "Follow"} = message),
+    do: filter_message(target_actor, message)
 
-      _, error ->
-        error
-    end)
-  end
+  @impl true
+  def filter(%{"actor" => actor, "type" => "Create"} = message),
+    do: filter_message(actor, message)
 
   @impl true
   def filter(message), do: {:ok, message}