projects
/
akkoma
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Fix Reblog API
[akkoma]
/
lib
/
pleroma
/
workers
/
purge_expired_activity.ex
diff --git
a/lib/pleroma/workers/purge_expired_activity.ex
b/lib/pleroma/workers/purge_expired_activity.ex
index c70587b47f041f02baf8a81e9cbd8b16d2c02046..01256831bc6490a93f18475bfc5b114db234fecc 100644
(file)
--- a/
lib/pleroma/workers/purge_expired_activity.ex
+++ b/
lib/pleroma/workers/purge_expired_activity.ex
@@
-1,5
+1,5
@@
# Pleroma: A lightweight social networking server
# Pleroma: A lightweight social networking server
-# Copyright © 2017-202
0
Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-202
1
Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Workers.PurgeExpiredActivity do
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Workers.PurgeExpiredActivity do
@@
-18,12
+18,11
@@
defmodule Pleroma.Workers.PurgeExpiredActivity do
| {:error, :expired_activities_disabled}
| {:error, :expiration_too_close}
def enqueue(args) do
| {:error, :expired_activities_disabled}
| {:error, :expiration_too_close}
def enqueue(args) do
- with true <- enabled?(),
- args when is_map(args) <- validate_expires_at(args) do
+ with true <- enabled?() do
{scheduled_at, args} = Map.pop(args, :expires_at)
args
{scheduled_at, args} = Map.pop(args, :expires_at)
args
- |>
__MODULE__.
new(scheduled_at: scheduled_at)
+ |> new(scheduled_at: scheduled_at)
|> Oban.insert()
end
end
|> Oban.insert()
end
end
@@
-31,18
+30,8
@@
defmodule Pleroma.Workers.PurgeExpiredActivity do
@impl true
def perform(%Oban.Job{args: %{"activity_id" => id}}) do
with %Activity{} = activity <- find_activity(id),
@impl true
def perform(%Oban.Job{args: %{"activity_id" => id}}) do
with %Activity{} = activity <- find_activity(id),
- %Pleroma.User{} = user <- find_user(activity.object.data["actor"]),
- false <- pinned_by_actor?(activity, user) do
+ %Pleroma.User{} = user <- find_user(activity.object.data["actor"]) do
Pleroma.Web.CommonAPI.delete(activity.id, user)
Pleroma.Web.CommonAPI.delete(activity.id, user)
- else
- :pinned_by_actor ->
- # if activity is pinned, schedule deletion on next day
- enqueue(%{activity_id: id, expires_at: DateTime.add(DateTime.utc_now(), 24 * 3600)})
-
- :ok
-
- error ->
- error
end
end
end
end
@@
-52,16
+41,6
@@
defmodule Pleroma.Workers.PurgeExpiredActivity do
end
end
end
end
- defp validate_expires_at(%{validate: false} = args), do: Map.delete(args, :validate)
-
- defp validate_expires_at(args) do
- if expires_late_enough?(args[:expires_at]) do
- args
- else
- {:error, :expiration_too_close}
- end
- end
-
defp find_activity(id) do
with nil <- Activity.get_by_id_with_object(id) do
{:error, :activity_not_found}
defp find_activity(id) do
with nil <- Activity.get_by_id_with_object(id) do
{:error, :activity_not_found}
@@
-74,12
+53,6
@@
defmodule Pleroma.Workers.PurgeExpiredActivity do
end
end
end
end
- defp pinned_by_actor?(activity, user) do
- with true <- Activity.pinned_by_actor?(activity, user) do
- :pinned_by_actor
- end
- end
-
def get_expiration(id) do
from(j in Oban.Job,
where: j.state == "scheduled",
def get_expiration(id) do
from(j in Oban.Job,
where: j.state == "scheduled",
@@
-93,6
+66,7
@@
defmodule Pleroma.Workers.PurgeExpiredActivity do
def expires_late_enough?(scheduled_at) do
now = DateTime.utc_now()
diff = DateTime.diff(scheduled_at, now, :millisecond)
def expires_late_enough?(scheduled_at) do
now = DateTime.utc_now()
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