activitypub: transmogrifier: fix up to/cc addressing brain damage caused by mastodon...
authorWilliam Pitcock <nenolod@dereferenced.org>
Sat, 17 Nov 2018 16:05:41 +0000 (16:05 +0000)
committerWilliam Pitcock <nenolod@dereferenced.org>
Sun, 20 Jan 2019 02:27:48 +0000 (02:27 +0000)
lib/pleroma/web/activity_pub/transmogrifier.ex

index fa3abe3d81013ad9194b34481a7ce9de2ab6a878..e9a801cf5b9412140a255513e29fdc3ce9fadea2 100644 (file)
@@ -93,12 +93,42 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
     end
   end
 
-  def fix_addressing(map) do
-    map
-    |> fix_addressing_list("to")
-    |> fix_addressing_list("cc")
-    |> fix_addressing_list("bto")
-    |> fix_addressing_list("bcc")
+  def fix_explicit_addressing(%{"to" => to, "cc" => cc} = object, explicit_mentions) do
+    explicit_to =
+      to
+      |> Enum.filter(fn x -> x in explicit_mentions end)
+
+    explicit_cc =
+      to
+      |> Enum.filter(fn x -> x not in explicit_mentions end)
+
+    final_cc =
+      (cc ++ explicit_cc)
+      |> Enum.uniq()
+
+    object
+    |> Map.put("to", explicit_to)
+    |> Map.put("cc", final_cc)
+  end
+
+  def fix_explicit_addressing(object, _explicit_mentions), do: object
+
+  def fix_addressing(object) do
+    object =
+      object
+      |> fix_addressing_list("to")
+      |> fix_addressing_list("cc")
+      |> fix_addressing_list("bto")
+      |> fix_addressing_list("bcc")
+
+    explicit_mentions =
+      object
+      |> Utils.determine_explicit_mentions()
+
+    explicit_mentions = explicit_mentions ++ ["https://www.w3.org/ns/activitystreams#Public"]
+
+    object
+    |> fix_explicit_addressing(explicit_mentions)
   end
 
   def fix_actor(%{"attributedTo" => actor} = object) do