summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Strizhakov <alex.strizhakov@gmail.com>2021-02-11 13:01:48 +0300
committerAlexander Strizhakov <alex.strizhakov@gmail.com>2021-02-18 14:59:22 +0300
commit1e6c27181e0bbfad3fbd964d770cd4d547c10236 (patch)
tree86096be50d4ed4dc75f9e62487efa411525651c6
parent8829a408ecf3bfffaf59af415817220fd63a81b7 (diff)
expires_in in scheduled status params
-rw-r--r--CHANGELOG.md1
-rw-r--r--docs/development/API/differences_in_mastoapi_responses.md6
-rw-r--r--lib/pleroma/web/api_spec/schemas/scheduled_status.ex6
-rw-r--r--lib/pleroma/web/mastodon_api/views/scheduled_activity_view.ex3
-rw-r--r--test/pleroma/web/mastodon_api/controllers/status_controller_test.exs25
-rw-r--r--test/pleroma/web/mastodon_api/views/scheduled_activity_view_test.exs3
6 files changed, 40 insertions, 4 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 74473b3d0..508a6ea15 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -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
diff --git a/docs/development/API/differences_in_mastoapi_responses.md b/docs/development/API/differences_in_mastoapi_responses.md
index 38d70fa78..6288ad33d 100644
--- a/docs/development/API/differences_in_mastoapi_responses.md
+++ b/docs/development/API/differences_in_mastoapi_responses.md
@@ -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:
diff --git a/lib/pleroma/web/api_spec/schemas/scheduled_status.ex b/lib/pleroma/web/api_spec/schemas/scheduled_status.ex
index cc051046a..607586e32 100644
--- a/lib/pleroma/web/api_spec/schemas/scheduled_status.ex
+++ b/lib/pleroma/web/api_spec/schemas/scheduled_status.ex
@@ -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]
}
diff --git a/lib/pleroma/web/mastodon_api/views/scheduled_activity_view.ex b/lib/pleroma/web/mastodon_api/views/scheduled_activity_view.ex
index 13774d237..453221f41 100644
--- a/lib/pleroma/web/mastodon_api/views/scheduled_activity_view.ex
+++ b/lib/pleroma/web/mastodon_api/views/scheduled_activity_view.ex
@@ -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
diff --git a/test/pleroma/web/mastodon_api/controllers/status_controller_test.exs b/test/pleroma/web/mastodon_api/controllers/status_controller_test.exs
index dcd1e6d5b..c59b156bf 100644
--- a/test/pleroma/web/mastodon_api/controllers/status_controller_test.exs
+++ b/test/pleroma/web/mastodon_api/controllers/status_controller_test.exs
@@ -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
diff --git a/test/pleroma/web/mastodon_api/views/scheduled_activity_view_test.exs b/test/pleroma/web/mastodon_api/views/scheduled_activity_view_test.exs
index c3b7f0f41..e323f3a1f 100644
--- a/test/pleroma/web/mastodon_api/views/scheduled_activity_view_test.exs
+++ b/test/pleroma/web/mastodon_api/views/scheduled_activity_view_test.exs
@@ -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)
}