diff --git a/lib/pleroma/web/activity_pub/importer.ex b/lib/pleroma/web/activity_pub/importer.ex index e8adf8250f..e17867ff68 100644 --- a/lib/pleroma/web/activity_pub/importer.ex +++ b/lib/pleroma/web/activity_pub/importer.ex @@ -49,11 +49,13 @@ def import_object( end end + def import_object(_, _, _), do: {:ok, nil} + def import_activity(%{"type" => "Create", "object" => object} = _activity, %User{} = user, opts) do import_object(object, user, opts) end - def import_activity(_, _, _), do: nil + def import_activity(_, _, _), do: {:ok, nil} def import_one(%{"type" => type} = object, %User{} = user, opts \\ []) do if type in Pleroma.Constants.status_types() do diff --git a/test/pleroma/web/activity_pub/importer_test.exs b/test/pleroma/web/activity_pub/importer_test.exs index 9f24236121..954eb0e5fd 100644 --- a/test/pleroma/web/activity_pub/importer_test.exs +++ b/test/pleroma/web/activity_pub/importer_test.exs @@ -108,5 +108,28 @@ test "it keeps public and unlisted posts unlisted with keep_unlisted option" do verify_with_visibility.("private", false) verify_with_visibility.("direct", false) end + + test "ignores on non-Create" do + importing_user = insert(:user) + + assert {:ok, nil} = + Importer.import_one(%{"type" => "Announce", "object" => %{}}, importing_user) + end + + test "ignores on non-status types" do + importing_user = insert(:user) + + assert {:ok, nil} = + Importer.import_one( + %{"type" => "Create", "object" => %{"type" => "ChatMessage"}}, + importing_user + ) + + assert {:ok, nil} = + Importer.import_one( + %{"type" => "Create", "object" => %{"type" => "Answer"}}, + importing_user + ) + end end end