configurable lifetime for ephemeral activities

This commit is contained in:
Alexander Strizhakov 2020-09-07 20:57:38 +03:00 committed by rinpatch
parent 4954667fb2
commit 2c2094d4b2
5 changed files with 26 additions and 6 deletions

View File

@ -654,7 +654,7 @@
account_confirmation_resend: {8_640_000, 5}, account_confirmation_resend: {8_640_000, 5},
ap_routes: {60_000, 15} ap_routes: {60_000, 15}
config :pleroma, Pleroma.Workers.PurgeExpiredActivity, enabled: true config :pleroma, Pleroma.Workers.PurgeExpiredActivity, enabled: true, min_lifetime: 600
config :pleroma, Pleroma.Plugs.RemoteIp, enabled: true config :pleroma, Pleroma.Plugs.RemoteIp, enabled: true

View File

@ -2480,6 +2480,12 @@
key: :enabled, key: :enabled,
type: :boolean, type: :boolean,
description: "Enables expired activities addition & deletion" description: "Enables expired activities addition & deletion"
},
%{
key: :min_lifetime,
type: :integer,
description: "Minimum lifetime for ephemeral activity (in seconds)",
suggestions: [600]
} }
] ]
}, },

View File

@ -1091,3 +1091,16 @@ config :pleroma, :frontends,
``` ```
This would serve the frontend from the the folder at `$instance_static/frontends/pleroma/stable`. You have to copy the frontend into this folder yourself. You can choose the name and ref any way you like, but they will be used by mix tasks to automate installation in the future, the name referring to the project and the ref referring to a commit. This would serve the frontend from the the folder at `$instance_static/frontends/pleroma/stable`. You have to copy the frontend into this folder yourself. You can choose the name and ref any way you like, but they will be used by mix tasks to automate installation in the future, the name referring to the project and the ref referring to a commit.
## Ephemeral activities
Settings to enable and configure expiration for ephemeral activities
* `:enabled` - enables ephemeral activities creation
* `:min_lifetime` - minimum lifetime for ephemeral activities (in seconds). Default: 10 minutes.
Example:
```elixir
config :pleroma, Pleroma.Workers.PurgeExpiredActivity, enabled: true, min_lifetime: 600
```

View File

@ -77,6 +77,7 @@ def get_expiration(id) do
def expires_late_enough?(scheduled_at) do def expires_late_enough?(scheduled_at) do
now = DateTime.utc_now() now = DateTime.utc_now()
diff = DateTime.diff(scheduled_at, now, :millisecond) diff = DateTime.diff(scheduled_at, now, :millisecond)
diff > :timer.hours(1) min_lifetime = Pleroma.Config.get([__MODULE__, :min_lifetime], 600)
diff > :timer.seconds(min_lifetime)
end end
end end

View File

@ -129,8 +129,8 @@ test "posting a status", %{conn: conn} do
test "it fails to create a status if `expires_in` is less or equal than an hour", %{ test "it fails to create a status if `expires_in` is less or equal than an hour", %{
conn: conn conn: conn
} do } do
# 1 hour # 1 minute
expires_in = 60 * 60 expires_in = 1 * 60
assert %{"error" => "Expiry date is too soon"} = assert %{"error" => "Expiry date is too soon"} =
conn conn
@ -141,8 +141,8 @@ test "it fails to create a status if `expires_in` is less or equal than an hour"
}) })
|> json_response_and_validate_schema(422) |> json_response_and_validate_schema(422)
# 30 minutes # 5 minutes
expires_in = 30 * 60 expires_in = 5 * 60
assert %{"error" => "Expiry date is too soon"} = assert %{"error" => "Expiry date is too soon"} =
conn conn