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 ba005300883d15d1edfa1d984eefd250c5ef86a3..01256831bc6490a93f18475bfc5b114db234fecc 100644
(file)
--- a/
lib/pleroma/workers/purge_expired_activity.ex
+++ b/
lib/pleroma/workers/purge_expired_activity.ex
@@
-1,3
+1,7
@@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.Workers.PurgeExpiredActivity do
@moduledoc """
Worker which purges expired activity.
defmodule Pleroma.Workers.PurgeExpiredActivity do
@moduledoc """
Worker which purges expired activity.
@@
-7,32
+11,27
@@
defmodule Pleroma.Workers.PurgeExpiredActivity do
import Ecto.Query
import Ecto.Query
+ alias Pleroma.Activity
+
+ @spec enqueue(map()) ::
+ {:ok, Oban.Job.t()}
+ | {:error, :expired_activities_disabled}
+ | {:error, :expiration_too_close}
def enqueue(args) do
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
@impl true
def perform(%Oban.Job{args: %{"activity_id" => id}}) do
|> Oban.insert()
end
end
@impl true
def perform(%Oban.Job{args: %{"activity_id" => id}}) do
- with %Pleroma.Activity{} = activity <- find_activity(id),
- %Pleroma.User{} = user <- find_user(activity.object.data["actor"]),
- false <- pinned_by_actor?(activity, user) do
+ with %Activity{} = activity <- find_activity(id),
+ %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
@@
-42,18
+41,8
@@
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
defp find_activity(id) do
- with nil <-
Pleroma.
Activity.get_by_id_with_object(id) do
+ with nil <- Activity.get_by_id_with_object(id) do
{:error, :activity_not_found}
end
end
{:error, :activity_not_found}
end
end
@@
-64,12
+53,6
@@
defmodule Pleroma.Workers.PurgeExpiredActivity do
end
end
end
end
- defp pinned_by_actor?(activity, user) do
- with true <- Pleroma.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",
@@
-83,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