aboutsummaryrefslogtreecommitdiff
path: root/lib/pleroma/web/common_api/common_api.ex
diff options
context:
space:
mode:
authorMike Verdone <spiral@arcseconds.net>2019-07-22 16:46:20 +0200
committerMike Verdone <spiral@arcseconds.net>2019-07-24 14:45:14 +0200
commit704960b3c135d2e050308c68f5ccf5d7b7df40f8 (patch)
tree85c5e602683014b42147dd582113fafff578c4eb /lib/pleroma/web/common_api/common_api.ex
parent378f5f0fbe21c2533719fed9afe8313586fda5d5 (diff)
downloadpleroma-704960b3c135d2e050308c68f5ccf5d7b7df40f8.tar.gz
Add support for activity expiration to common and Masto API
The "expires_at" parameter accepts an ISO8601-formatted date which defines when the activity will expire. At this point the API will not give you any feedback about if your post will expire or not.
Diffstat (limited to 'lib/pleroma/web/common_api/common_api.ex')
-rw-r--r--lib/pleroma/web/common_api/common_api.ex29
1 files changed, 20 insertions, 9 deletions
diff --git a/lib/pleroma/web/common_api/common_api.ex b/lib/pleroma/web/common_api/common_api.ex
index 44af6a773..0f287af4e 100644
--- a/lib/pleroma/web/common_api/common_api.ex
+++ b/lib/pleroma/web/common_api/common_api.ex
@@ -4,6 +4,7 @@
defmodule Pleroma.Web.CommonAPI do
alias Pleroma.Activity
+ alias Pleroma.ActivityExpiration
alias Pleroma.Formatter
alias Pleroma.Object
alias Pleroma.ThreadMute
@@ -218,6 +219,7 @@ defmodule Pleroma.Web.CommonAPI do
context <- make_context(in_reply_to),
cw <- data["spoiler_text"] || "",
sensitive <- data["sensitive"] || Enum.member?(tags, {"#nsfw", "nsfw"}),
+ {:ok, expires_at} <- Ecto.Type.cast(:naive_datetime, data["expires_at"]),
full_payload <- String.trim(status <> cw),
:ok <- validate_character_limit(full_payload, attachments, limit),
object <-
@@ -243,15 +245,24 @@ defmodule Pleroma.Web.CommonAPI do
preview? = Pleroma.Web.ControllerHelper.truthy_param?(data["preview"]) || false
direct? = visibility == "direct"
- %{
- to: to,
- actor: user,
- context: context,
- object: object,
- additional: %{"cc" => cc, "directMessage" => direct?}
- }
- |> maybe_add_list_data(user, visibility)
- |> ActivityPub.create(preview?)
+ result =
+ %{
+ to: to,
+ actor: user,
+ context: context,
+ object: object,
+ additional: %{"cc" => cc, "directMessage" => direct?}
+ }
+ |> maybe_add_list_data(user, visibility)
+ |> ActivityPub.create(preview?)
+
+ if expires_at do
+ with {:ok, activity} <- result do
+ ActivityExpiration.create(activity, expires_at)
+ end
+ end
+
+ result
else
{:private_to_public, true} ->
{:error, dgettext("errors", "The message visibility must be direct")}