ObjectValidator.stringify_keys: filter out nil values
authorHaelwenn (lanodan) Monnier <contact@hacktivis.me>
Wed, 11 Aug 2021 19:29:06 +0000 (21:29 +0200)
committerHaelwenn (lanodan) Monnier <contact@hacktivis.me>
Wed, 11 Aug 2021 19:38:10 +0000 (21:38 +0200)
lib/pleroma/web/activity_pub/object_validator.ex
lib/pleroma/web/push/impl.ex
test/pleroma/web/activity_pub/object_validators/chat_validation_test.exs
test/pleroma/web/activity_pub/transmogrifier/audio_handling_test.exs
test/pleroma/web/activity_pub/transmogrifier/video_handling_test.exs

index 6e40d8b72ce1ad854b35dab9a6a2fc2a089e213c..187cd0cfd6010145ef6c1f2ed4fedaf0082d871e 100644 (file)
@@ -213,6 +213,7 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidator do
 
   def stringify_keys(object) when is_map(object) do
     object
+    |> Enum.filter(fn {_, v} -> v != nil end)
     |> Map.new(fn {key, val} -> {to_string(key), stringify_keys(val)} end)
   end
 
index 83cbdc870bc877f9b68f65d6db472ba7a332fda0..28e13ef9c791cbfe16e4737099572cfa898cd786 100644 (file)
@@ -124,8 +124,8 @@ defmodule Pleroma.Web.Push.Impl do
 
   def format_body(activity, actor, object, mastodon_type \\ nil)
 
-  def format_body(_activity, actor, %{data: %{"type" => "ChatMessage", "content" => content}}, _) do
-    case content do
+  def format_body(_activity, actor, %{data: %{"type" => "ChatMessage"} = data}, _) do
+    case data["content"] do
       nil -> "@#{actor.nickname}: (Attachment)"
       content -> "@#{actor.nickname}: #{Utils.scrub_html_and_truncate(content, 80)}"
     end
index 320854187d753d57034d3e229d31f412f8be70b0..def2a10b4a2b85c25c618006fd379345e495d1a7 100644 (file)
@@ -68,7 +68,7 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.ChatValidationTest do
     test "validates for a basic object we build", %{valid_chat_message: valid_chat_message} do
       assert {:ok, object, _meta} = ObjectValidator.validate(valid_chat_message, [])
 
-      assert Map.put(valid_chat_message, "attachment", nil) == object
+      assert valid_chat_message == object
       assert match?(%{"firefox" => _}, object["emoji"])
     end
 
index a929f828db62f81b1f965ea8c2c3f7986e2ff2a7..a0942ce8b8c6a7f49fd1385cd80448ebe803a122 100644 (file)
@@ -73,16 +73,12 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.AudioHandlingTest do
              %{
                "mediaType" => "audio/ogg",
                "type" => "Link",
-               "name" => nil,
-               "blurhash" => nil,
                "url" => [
                  %{
                    "href" =>
                      "https://channels.tests.funkwhale.audio/api/v1/listen/3901e5d8-0445-49d5-9711-e096cf32e515/?upload=42342395-0208-4fee-a38d-259a6dae0871&download=false",
                    "mediaType" => "audio/ogg",
-                   "type" => "Link",
-                   "width" => nil,
-                   "height" => nil
+                   "type" => "Link"
                  }
                ]
              }
index 62b4a2cb37ba2d6f9a1274472897e551e41100da..fc3ec7450f880c750259cc7972a15ee07441e250 100644 (file)
@@ -53,16 +53,12 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.VideoHandlingTest do
              %{
                "type" => "Link",
                "mediaType" => "video/mp4",
-               "name" => nil,
-               "blurhash" => nil,
                "url" => [
                  %{
                    "href" =>
                      "https://peertube.moe/static/webseed/df5f464b-be8d-46fb-ad81-2d4c2d1630e3-480.mp4",
                    "mediaType" => "video/mp4",
-                   "type" => "Link",
-                   "width" => nil,
-                   "height" => nil
+                   "type" => "Link"
                  }
                ]
              }
@@ -78,16 +74,12 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.VideoHandlingTest do
              %{
                "type" => "Link",
                "mediaType" => "video/mp4",
-               "name" => nil,
-               "blurhash" => nil,
                "url" => [
                  %{
                    "href" =>
                      "https://framatube.org/static/webseed/6050732a-8a7a-43d4-a6cd-809525a1d206-1080.mp4",
                    "mediaType" => "video/mp4",
-                   "type" => "Link",
-                   "width" => nil,
-                   "height" => nil
+                   "type" => "Link"
                  }
                ]
              }
@@ -110,16 +102,12 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.VideoHandlingTest do
              %{
                "type" => "Link",
                "mediaType" => "video/mp4",
-               "name" => nil,
-               "blurhash" => nil,
                "url" => [
                  %{
                    "href" =>
                      "https://peertube.stream/static/streaming-playlists/hls/abece3c3-b9c6-47f4-8040-f3eed8c602e6/abece3c3-b9c6-47f4-8040-f3eed8c602e6-1080-fragmented.mp4",
                    "mediaType" => "video/mp4",
-                   "type" => "Link",
-                   "width" => nil,
-                   "height" => nil
+                   "type" => "Link"
                  }
                ]
              }