summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorlain <lain@soykaf.club>2019-08-24 17:22:48 +0200
committerlain <lain@soykaf.club>2019-08-24 17:22:48 +0200
commitefb8818e9ee280b53eac17699e8114e8af82b03b (patch)
treeb9869667be16769d30e83d67455236f862e51c7c /lib
parent1692fa89458f0f83f69ffa2f85a998869b8fe454 (diff)
downloadpleroma-efb8818e9ee280b53eac17699e8114e8af82b03b.tar.gz
pleroma-efb8818e9ee280b53eac17699e8114e8af82b03b.zip
Activity Expiration: Switch to 'expires_in' system.
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 <-