summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authortusooa <tusooa@kazv.moe>2023-03-25 23:20:07 -0400
committertusooa <tusooa@kazv.moe>2023-03-25 23:20:07 -0400
commit10930f7507412fb1bea760723ee466774f95c6f3 (patch)
tree736a0b6be20c234de472fed877ff0d7aceefe7c3 /lib
parent6d0cc8fa2af293280f1816410794d2afdbc2294b (diff)
downloadpleroma-10930f7507412fb1bea760723ee466774f95c6f3.tar.gz
pleroma-10930f7507412fb1bea760723ee466774f95c6f3.zip
Dedupe poll options
Diffstat (limited to 'lib')
-rw-r--r--lib/pleroma/web/common_api/utils.ex15
1 files changed, 11 insertions, 4 deletions
diff --git a/lib/pleroma/web/common_api/utils.ex b/lib/pleroma/web/common_api/utils.ex
index ff0814329..a93c97e1e 100644
--- a/lib/pleroma/web/common_api/utils.ex
+++ b/lib/pleroma/web/common_api/utils.ex
@@ -145,6 +145,8 @@ defmodule Pleroma.Web.CommonAPI.Utils do
when is_list(options) do
limits = Config.get([:instance, :poll_limits])
+ options = options |> Enum.uniq()
+
with :ok <- validate_poll_expiration(expires_in, limits),
:ok <- validate_poll_options_amount(options, limits),
:ok <- validate_poll_options_length(options, limits) do
@@ -180,10 +182,15 @@ defmodule Pleroma.Web.CommonAPI.Utils do
end
defp validate_poll_options_amount(options, %{max_options: max_options}) do
- if Enum.count(options) > max_options do
- {:error, "Poll can't contain more than #{max_options} options"}
- else
- :ok
+ cond do
+ Enum.count(options) < 2 ->
+ {:error, "Poll must contain at least 2 options"}
+
+ Enum.count(options) > max_options ->
+ {:error, "Poll can't contain more than #{max_options} options"}
+
+ true ->
+ :ok
end
end