expires_in in scheduled status params
authorAlexander Strizhakov <alex.strizhakov@gmail.com>
Thu, 11 Feb 2021 10:01:48 +0000 (13:01 +0300)
committerAlexander Strizhakov <alex.strizhakov@gmail.com>
Thu, 18 Feb 2021 11:59:22 +0000 (14:59 +0300)
CHANGELOG.md
docs/development/API/differences_in_mastoapi_responses.md
lib/pleroma/web/api_spec/schemas/scheduled_status.ex
lib/pleroma/web/mastodon_api/views/scheduled_activity_view.ex
test/pleroma/web/mastodon_api/controllers/status_controller_test.exs
test/pleroma/web/mastodon_api/views/scheduled_activity_view_test.exs

index 74473b3d080b32b887983e0c7ff41ab701c18e1a..508a6ea1543277d00174bcdf4a2d4708084b9d02 100644 (file)
@@ -74,6 +74,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
 - Mastodon API: Home, public, hashtag & list timelines accept `only_media`, `remote` & `local` parameters for filtration.
 - Mastodon API: `/api/v1/accounts/:id` & `/api/v1/mutes` endpoints accept `with_relationships` parameter and return filled `pleroma.relationship` field.
 - Mastodon API: Endpoint to remove a conversation (`DELETE /api/v1/conversations/:id`).
+- Mastodon API: `expires_in` in the scheduled post `params` field on `/api/v1/statuses` and `/api/v1/scheduled_statuses/:id` endpoints.
 </details>
 
 ### Fixed
index 38d70fa78e188757590423639a73f38165cf9478..6288ad33dd06bf5ebc30c87327c3313be689f555 100644 (file)
@@ -39,6 +39,12 @@ Has these additional fields under the `pleroma` object:
 - `emoji_reactions`: A list with emoji / reaction maps. The format is `{name: "☕", count: 1, me: true}`. Contains no information about the reacting users, for that use the `/statuses/:id/reactions` endpoint.
 - `parent_visible`: If the parent of this post is visible to the user or not.
 
+## Scheduled statuses
+
+Has these additional fields in `params`:
+
+- `expires_in`: the number of seconds the posted activity should expire in.
+
 ## Media Attachments
 
 Has these additional fields under the `pleroma` object:
index cc051046a9906e52a79b6237c072e32c5d9135fb..607586e32600ac88fc2d751bf9da4de118145013 100644 (file)
@@ -30,7 +30,8 @@ defmodule Pleroma.Web.ApiSpec.Schemas.ScheduledStatus do
           visibility: %Schema{allOf: [VisibilityScope], nullable: true},
           scheduled_at: %Schema{type: :string, format: :"date-time", nullable: true},
           poll: StatusOperation.poll_params(),
-          in_reply_to_id: %Schema{type: :string, nullable: true}
+          in_reply_to_id: %Schema{type: :string, nullable: true},
+          expires_in: %Schema{type: :integer, nullable: true}
         }
       }
     },
@@ -46,7 +47,8 @@ defmodule Pleroma.Web.ApiSpec.Schemas.ScheduledStatus do
         scheduled_at: nil,
         poll: nil,
         idempotency: nil,
-        in_reply_to_id: nil
+        in_reply_to_id: nil,
+        expires_in: nil
       },
       media_attachments: [Attachment.schema().example]
     }
index 13774d23709705b19bba1f93d5b13ba9f54a6670..453221f4123b5ae83c08221f6a74160cd7c1655b 100644 (file)
@@ -37,7 +37,8 @@ defmodule Pleroma.Web.MastodonAPI.ScheduledActivityView do
       visibility: params["visibility"],
       scheduled_at: params["scheduled_at"],
       poll: params["poll"],
-      in_reply_to_id: params["in_reply_to_id"]
+      in_reply_to_id: params["in_reply_to_id"],
+      expires_in: params["expires_in"]
     }
     |> Pleroma.Maps.put_if_present(:media_ids, params["media_ids"])
   end
index dcd1e6d5b8bfa78fd1b12dc8e58168fa559dec25..c59b156bf44c929430922dbb5b66acdff4e5a67d 100644 (file)
@@ -383,6 +383,31 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
       assert [] == Repo.all(Activity)
     end
 
+    test "with expiration" do
+      %{conn: conn} = oauth_access(["write:statuses", "read:statuses"])
+
+      scheduled_at =
+        NaiveDateTime.add(NaiveDateTime.utc_now(), :timer.minutes(6), :millisecond)
+        |> NaiveDateTime.to_iso8601()
+        |> Kernel.<>("Z")
+
+      assert %{"id" => status_id, "params" => %{"expires_in" => 300}} =
+               conn
+               |> put_req_header("content-type", "application/json")
+               |> post("/api/v1/statuses", %{
+                 "status" => "scheduled",
+                 "scheduled_at" => scheduled_at,
+                 "expires_in" => 300
+               })
+               |> json_response_and_validate_schema(200)
+
+      assert %{"id" => ^status_id, "params" => %{"expires_in" => 300}} =
+               conn
+               |> put_req_header("content-type", "application/json")
+               |> get("/api/v1/scheduled_statuses/#{status_id}")
+               |> json_response_and_validate_schema(200)
+    end
+
     test "ignores nil values", %{conn: conn} do
       conn =
         conn
index c3b7f0f41f9d2e6df3bea1fbeefbcd7aa0abda99..e323f3a1f0fc35c69cb5fc30b33b7ad3c78b06ae 100644 (file)
@@ -58,7 +58,8 @@ defmodule Pleroma.Web.MastodonAPI.ScheduledActivityViewTest do
         sensitive: true,
         spoiler_text: "spoiler",
         text: "hi",
-        visibility: "unlisted"
+        visibility: "unlisted",
+        expires_in: nil
       },
       scheduled_at: Utils.to_masto_date(scheduled_activity.scheduled_at)
     }