Transmogrifier: Strip internal emoji reaction fields.
authorlain <lain@soykaf.club>
Thu, 12 Sep 2019 16:59:13 +0000 (18:59 +0200)
committerlain <lain@soykaf.club>
Thu, 12 Sep 2019 16:59:13 +0000 (18:59 +0200)
lib/pleroma/web/activity_pub/transmogrifier.ex
test/web/activity_pub/transmogrifier_test.exs

index 9132df8cb48368216fc754aa0d0786b4f9053b55..0b9cc44998f62dbcaf2f33e238258529bf242a20 100644 (file)
@@ -995,9 +995,11 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
     |> Map.put("attachment", attachments)
   end
 
-  defp strip_internal_fields(object) do
+  def strip_internal_fields(object) do
     object
     |> Map.drop([
+      "reactions",
+      "reaction_count",
       "likes",
       "like_count",
       "announcements",
index 6df7073702ef5b028aa077e13584d03c1a8e274b..20d274a02f91f8780ec156e81a3a1dd451d0426a 100644 (file)
@@ -491,6 +491,20 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
       refute Map.has_key?(object.data, "likes")
     end
 
+    test "it strips internal reactions" do
+      user = insert(:user)
+      {:ok, activity} = CommonAPI.post(user, %{"status" => "#cofe"})
+      {:ok, _, _} = CommonAPI.react_with_emoji(activity.id, user, "📢")
+
+      %{object: object} = Activity.get_by_id_with_object(activity.id)
+      assert Map.has_key?(object.data, "reactions")
+      assert Map.has_key?(object.data, "reaction_count")
+
+      object_data = Transmogrifier.strip_internal_fields(object.data)
+      refute Map.has_key?(object_data, "reactions")
+      refute Map.has_key?(object_data, "reaction_count")
+    end
+
     test "it works for incoming update activities" do
       data = File.read!("test/fixtures/mastodon-post-activity.json") |> Poison.decode!()