Prepare all types objects before serialising
authorsxsdv1 <sxsdv1@gmail.com>
Sat, 12 Jan 2019 16:52:30 +0000 (17:52 +0100)
committersxsdv1 <sxsdv1@gmail.com>
Sat, 12 Jan 2019 19:24:32 +0000 (20:24 +0100)
Activities returned from inbox can include other types of objects like
Article

lib/pleroma/web/activity_pub/transmogrifier.ex
test/support/factory.ex
test/web/activity_pub/transmogrifier_test.exs

index 87b7fc07f3ba2ef742e600cc7dd67ff27c70cec3..b0f8c59ccc01febe37c922f99427bb7d3b18e1fa 100644 (file)
@@ -641,7 +641,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
   #  internal -> Mastodon
   #  """
 
-  def prepare_outgoing(%{"type" => "Create", "object" => %{"type" => "Note"} = object} = data) do
+  def prepare_outgoing(%{"type" => "Create", "object" => object} = data) do
     object =
       object
       |> prepare_object
index 57fa4a79d68a65e29c64277ca992b190dd37bd8d..4ac77981a76de3d021cf4738ca060c3f0d889ac0 100644 (file)
@@ -57,6 +57,11 @@ defmodule Pleroma.Factory do
     %Pleroma.Object{data: Map.merge(data, %{"to" => [user2.ap_id]})}
   end
 
+  def article_factory do
+    note_factory()
+    |> Map.put("type", "Article")
+  end
+
   def tombstone_factory do
     data = %{
       "type" => "Tombstone",
@@ -110,6 +115,26 @@ defmodule Pleroma.Factory do
     }
   end
 
+  def article_activity_factory do
+    article = insert(:article)
+
+    data = %{
+      "id" => Pleroma.Web.ActivityPub.Utils.generate_activity_id(),
+      "type" => "Create",
+      "actor" => article.data["actor"],
+      "to" => article.data["to"],
+      "object" => article.data,
+      "published" => DateTime.utc_now() |> DateTime.to_iso8601(),
+      "context" => article.data["context"]
+    }
+
+    %Pleroma.Activity{
+      data: data,
+      actor: data["actor"],
+      recipients: data["to"]
+    }
+  end
+
   def announce_activity_factory do
     note_activity = insert(:note_activity)
     user = insert(:user)
index a5fd87ed4383963d0ec5a7c956430db9496273fd..65c8ec36da049a78f8f97fd0b6d4ae9a5b9e5c11 100644 (file)
@@ -835,6 +835,21 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
       assert is_nil(modified["object"]["announcement_count"])
       assert is_nil(modified["object"]["context_id"])
     end
+
+    test "it strips internal fields of article" do
+      activity = insert(:article_activity)
+
+      {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
+
+      assert length(modified["object"]["tag"]) == 2
+
+      assert is_nil(modified["object"]["emoji"])
+      assert is_nil(modified["object"]["likes"])
+      assert is_nil(modified["object"]["like_count"])
+      assert is_nil(modified["object"]["announcements"])
+      assert is_nil(modified["object"]["announcement_count"])
+      assert is_nil(modified["object"]["context_id"])
+    end
   end
 
   describe "user upgrade" do