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.
This commit is contained in:
parent
378f5f0fbe
commit
704960b3c1
6 changed files with 82 additions and 13 deletions
|
|
@ -143,12 +143,14 @@ defmodule Pleroma.Factory do
|
|||
end
|
||||
|
||||
defp expiration_offset_by_minutes(attrs, minutes) do
|
||||
scheduled_at =
|
||||
NaiveDateTime.utc_now()
|
||||
|> NaiveDateTime.add(:timer.minutes(minutes), :millisecond)
|
||||
|> NaiveDateTime.truncate(:second)
|
||||
|
||||
%Pleroma.ActivityExpiration{}
|
||||
|> Map.merge(attrs)
|
||||
|> Map.put(
|
||||
:scheduled_at,
|
||||
NaiveDateTime.add(NaiveDateTime.utc_now(), :timer.minutes(minutes), :millisecond)
|
||||
)
|
||||
|> Map.put(:scheduled_at, scheduled_at)
|
||||
end
|
||||
|
||||
def expiration_in_the_past_factory(attrs \\ %{}) do
|
||||
|
|
|
|||
|
|
@ -160,6 +160,23 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
|
||||
Pleroma.Config.put([:instance, :limit], limit)
|
||||
end
|
||||
|
||||
test "it can handle activities that expire" do
|
||||
user = insert(:user)
|
||||
|
||||
expires_at =
|
||||
NaiveDateTime.utc_now()
|
||||
|> NaiveDateTime.truncate(:second)
|
||||
|> NaiveDateTime.add(1_000_000, :second)
|
||||
|
||||
expires_at_iso8601 = expires_at |> NaiveDateTime.to_iso8601()
|
||||
|
||||
assert {:ok, activity} =
|
||||
CommonAPI.post(user, %{"status" => "chai", "expires_at" => expires_at_iso8601})
|
||||
|
||||
assert expiration = Pleroma.ActivityExpiration.get_by_activity_id(activity.id)
|
||||
assert expiration.scheduled_at == expires_at
|
||||
end
|
||||
end
|
||||
|
||||
describe "reactions" do
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
|||
|
||||
alias Ecto.Changeset
|
||||
alias Pleroma.Activity
|
||||
alias Pleroma.ActivityExpiration
|
||||
alias Pleroma.Notification
|
||||
alias Pleroma.Object
|
||||
alias Pleroma.Repo
|
||||
|
|
@ -151,6 +152,24 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
|||
|
||||
assert %{"id" => third_id} = json_response(conn_three, 200)
|
||||
refute id == third_id
|
||||
|
||||
# An activity that will expire:
|
||||
expires_at =
|
||||
NaiveDateTime.utc_now()
|
||||
|> NaiveDateTime.add(:timer.minutes(120), :millisecond)
|
||||
|> NaiveDateTime.truncate(:second)
|
||||
|
||||
conn_four =
|
||||
conn
|
||||
|> post("api/v1/statuses", %{
|
||||
"status" => "oolong",
|
||||
"expires_at" => expires_at
|
||||
})
|
||||
|
||||
assert %{"id" => fourth_id} = json_response(conn_four, 200)
|
||||
assert activity = Activity.get_by_id(fourth_id)
|
||||
assert expiration = ActivityExpiration.get_by_activity_id(fourth_id)
|
||||
assert expiration.scheduled_at == expires_at
|
||||
end
|
||||
|
||||
test "replying to a status", %{conn: conn} do
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue