commit: 4339230f64b05fee1c4d7313c1dc9adc45827a5d
parent 72833c84b583057ed0e757f35b65f90af40496df
Author: Haelwenn <contact+git.pleroma.social@hacktivis.me>
Date:   Tue, 23 May 2023 01:57:07 +0000
Merge branch 'tusooa/fix-object-test' into 'develop'
Fix ObjectTest
See merge request pleroma/pleroma!3887
Diffstat:
2 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/changelog.d/fix-object-test.fix b/changelog.d/fix-object-test.fix
@@ -0,0 +1 @@
+Correctly handle the situation when a poll has both "anyOf" and "oneOf" but one of them being empty
diff --git a/lib/pleroma/object/updater.ex b/lib/pleroma/object/updater.ex
@@ -100,12 +100,14 @@ defmodule Pleroma.Object.Updater do
   end
 
   defp maybe_update_poll(to_be_updated, updated_object) do
-    choice_key = fn data ->
-      if Map.has_key?(data, "anyOf"), do: "anyOf", else: "oneOf"
+    choice_key = fn
+      %{"anyOf" => [_ | _]} -> "anyOf"
+      %{"oneOf" => [_ | _]} -> "oneOf"
+      _ -> nil
     end
 
     with true <- to_be_updated["type"] == "Question",
-         key <- choice_key.(updated_object),
+         key when not is_nil(key) <- choice_key.(updated_object),
          true <- key == choice_key.(to_be_updated),
          orig_choices <- to_be_updated[key] |> Enum.map(&Map.drop(&1, ["replies"])),
          new_choices <- updated_object[key] |> Enum.map(&Map.drop(&1, ["replies"])),