Fix addressing
authorHaelwenn (lanodan) Monnier <contact@hacktivis.me>
Tue, 15 Sep 2020 15:22:08 +0000 (17:22 +0200)
committerHaelwenn (lanodan) Monnier <contact@hacktivis.me>
Mon, 5 Apr 2021 17:19:12 +0000 (19:19 +0200)
lib/pleroma/object/fetcher.ex
lib/pleroma/web/activity_pub/object_validators/common_fixes.ex
lib/pleroma/web/activity_pub/object_validators/create_generic_validator.ex

index bcccf1c4c9138af6355094d20d58b029cfff58a9..82d2c8bcb395345eb7cc07ab2aa5633b84b051ed 100644 (file)
@@ -4,6 +4,7 @@
 
 defmodule Pleroma.Object.Fetcher do
   alias Pleroma.HTTP
+  alias Pleroma.Maps
   alias Pleroma.Object
   alias Pleroma.Object.Containment
   alias Pleroma.Repo
@@ -124,12 +125,14 @@ defmodule Pleroma.Object.Fetcher do
   defp prepare_activity_params(data) do
     %{
       "type" => "Create",
-      "to" => data["to"] || [],
-      "cc" => data["cc"] || [],
       # Should we seriously keep this attributedTo thing?
       "actor" => data["actor"] || data["attributedTo"],
       "object" => data
     }
+    |> Maps.put_if_present("to", data["to"])
+    |> Maps.put_if_present("cc", data["cc"])
+    |> Maps.put_if_present("bto", data["bto"])
+    |> Maps.put_if_present("bcc", data["bcc"])
   end
 
   def fetch_object_from_id!(id, options \\ []) do
index 009cd51b059cbc16b1a84d7eb91202cd2373a6dd..c958fcc5d2c680439e9ba08a3f9ba5ac2ab8c62a 100644 (file)
@@ -9,9 +9,14 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.CommonFixes do
   alias Pleroma.Web.ActivityPub.Transmogrifier
   alias Pleroma.Web.ActivityPub.Utils
 
-  def cast_recipients(message, field, field_fallback \\ []) do
+  def cast_and_filter_recipients(message, field, follower_collection, field_fallback \\ []) do
     {:ok, data} = ObjectValidators.Recipients.cast(message[field] || field_fallback)
 
+    data =
+      Enum.reject(data, fn x ->
+        String.ends_with?(x, "/followers") and x != follower_collection
+      end)
+
     Map.put(message, field, data)
   end
 
@@ -24,11 +29,10 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.CommonFixes do
     data
     |> Map.put("context", context)
     |> Map.put("context_id", context_id)
-    |> cast_recipients("to")
-    |> cast_recipients("cc")
-    |> cast_recipients("bto")
-    |> cast_recipients("bcc")
-    |> Transmogrifier.fix_explicit_addressing(follower_collection)
+    |> cast_and_filter_recipients("to", follower_collection)
+    |> cast_and_filter_recipients("cc", follower_collection)
+    |> cast_and_filter_recipients("bto", follower_collection)
+    |> cast_and_filter_recipients("bcc", follower_collection)
     |> Transmogrifier.fix_implicit_addressing(follower_collection)
   end
 
@@ -36,11 +40,10 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.CommonFixes do
     %User{follower_address: follower_collection} = User.get_cached_by_ap_id(activity["actor"])
 
     activity
-    |> cast_recipients("to")
-    |> cast_recipients("cc")
-    |> cast_recipients("bto")
-    |> cast_recipients("bcc")
-    |> Transmogrifier.fix_explicit_addressing(follower_collection)
+    |> cast_and_filter_recipients("to", follower_collection)
+    |> cast_and_filter_recipients("cc", follower_collection)
+    |> cast_and_filter_recipients("bto", follower_collection)
+    |> cast_and_filter_recipients("bcc", follower_collection)
     |> Transmogrifier.fix_implicit_addressing(follower_collection)
   end
 
index 51d43e8d08f1ddcf1ac674630452ba335d060ae7..d2de53049d760edf2820b17e6c309c92a83e7b8f 100644 (file)
@@ -63,11 +63,10 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.CreateGenericValidator do
     %User{follower_address: follower_collection} = User.get_cached_by_ap_id(data["actor"])
 
     data
-    |> CommonFixes.cast_recipients("to", object["to"])
-    |> CommonFixes.cast_recipients("cc", object["cc"])
-    |> CommonFixes.cast_recipients("bto", object["bto"])
-    |> CommonFixes.cast_recipients("bcc", object["bcc"])
-    |> Transmogrifier.fix_explicit_addressing(follower_collection)
+    |> CommonFixes.cast_and_filter_recipients("to", follower_collection, object["to"])
+    |> CommonFixes.cast_and_filter_recipients("cc", follower_collection, object["cc"])
+    |> CommonFixes.cast_and_filter_recipients("bto", follower_collection, object["bto"])
+    |> CommonFixes.cast_and_filter_recipients("bcc", follower_collection, object["bcc"])
     |> Transmogrifier.fix_implicit_addressing(follower_collection)
   end