EnsureRePrepended: Don't break on chat messages.
authorlain <lain@soykaf.club>
Wed, 29 Jul 2020 08:53:08 +0000 (10:53 +0200)
committerlain <lain@soykaf.club>
Wed, 29 Jul 2020 08:53:08 +0000 (10:53 +0200)
lib/pleroma/web/activity_pub/mrf/ensure_re_prepended.ex
test/web/activity_pub/mrf/ensure_re_prepended_test.exs

index 2627a00073428d38dd2df75f07ec3d679351a740..3bf70b8946b90f9248607d15ceaecbb3e63cc7e2 100644 (file)
@@ -27,7 +27,8 @@ defmodule Pleroma.Web.ActivityPub.MRF.EnsureRePrepended do
 
   def filter_by_summary(_in_reply_to, child), do: child
 
-  def filter(%{"type" => "Create", "object" => child_object} = object) do
+  def filter(%{"type" => "Create", "object" => child_object} = object)
+      when is_map(child_object) do
     child =
       child_object["inReplyTo"]
       |> Object.normalize(child_object["inReplyTo"])
index 38ddec5bb7e8f4ff9275a032936326ed0b1ed4c3..9a283f27d6b3330532e06ed5fd525a56f022eb96 100644 (file)
@@ -78,5 +78,15 @@ defmodule Pleroma.Web.ActivityPub.MRF.EnsureRePrependedTest do
       assert {:ok, res} = EnsureRePrepended.filter(message)
       assert res == message
     end
+
+    test "it skips if the object is only a reference" do
+      message = %{
+        "type" => "Create",
+        "object" => "somereference"
+      }
+
+      assert {:ok, res} = EnsureRePrepended.filter(message)
+      assert res == message
+    end
   end
 end