Merge branch 'develop' of git.pleroma.social:pleroma/pleroma into features/poll-valid...
[akkoma] / lib / pleroma / web / activity_pub / object_validators / common_validations.ex
index 140555a45e6ab8706f76058eeaeddbd2f636dd86..e981dacaa8e166585f1b095dce992d3eae3e7e95 100644 (file)
@@ -115,4 +115,22 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.CommonValidations do
       end)
     end
   end
+
+  def validate_fields_match(cng, fields) do
+    unique_fields =
+      fields
+      |> Enum.map(fn field -> get_field(cng, field) end)
+      |> Enum.uniq()
+      |> Enum.count()
+
+    if unique_fields == 1 do
+      cng
+    else
+      fields
+      |> Enum.reduce(cng, fn field, cng ->
+        cng
+        |> add_error(field, "Fields #{inspect(fields)} aren't matching")
+      end)
+    end
+  end
 end