aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/pleroma/web/common_api/common_api.ex15
1 files changed, 11 insertions, 4 deletions
diff --git a/lib/pleroma/web/common_api/common_api.ex b/lib/pleroma/web/common_api/common_api.ex
index 69120cc19..5faddc9f4 100644
--- a/lib/pleroma/web/common_api/common_api.ex
+++ b/lib/pleroma/web/common_api/common_api.ex
@@ -201,16 +201,23 @@ defmodule Pleroma.Web.CommonAPI do
end
end
- defp check_expiry_date(expiry_str) do
- {:ok, expiry} = Ecto.Type.cast(:naive_datetime, expiry_str)
+ defp check_expiry_date({:ok, nil} = res), do: res
+
+ defp check_expiry_date({:ok, in_seconds}) do
+ expiry = NaiveDateTime.utc_now() |> NaiveDateTime.add(in_seconds)
- if is_nil(expiry) || ActivityExpiration.expires_late_enough?(expiry) do
+ if ActivityExpiration.expires_late_enough?(expiry) do
{:ok, expiry}
else
{:error, "Expiry date is too soon"}
end
end
+ defp check_expiry_date(expiry_str) do
+ Ecto.Type.cast(:integer, expiry_str)
+ |> check_expiry_date()
+ end
+
def post(user, %{"status" => status} = data) do
limit = Pleroma.Config.get([:instance, :limit])
@@ -237,7 +244,7 @@ defmodule Pleroma.Web.CommonAPI do
context <- make_context(in_reply_to, in_reply_to_conversation),
cw <- data["spoiler_text"] || "",
sensitive <- data["sensitive"] || Enum.member?(tags, {"#nsfw", "nsfw"}),
- {:ok, expires_at} <- check_expiry_date(data["expires_at"]),
+ {:ok, expires_at} <- check_expiry_date(data["expires_in"]),
full_payload <- String.trim(status <> cw),
:ok <- validate_character_limit(full_payload, attachments, limit),
object <-