Merge branch 'develop' into 'fix/2412-filters'
# Conflicts: # CHANGELOG.md
This commit is contained in:
commit
008499f65a
245 changed files with 1917 additions and 905 deletions
|
|
@ -17,12 +17,14 @@ defmodule Pleroma.Workers.AttachmentsCleanupWorker do
|
|||
"object" => %{"data" => %{"attachment" => [_ | _] = attachments, "actor" => actor}}
|
||||
}
|
||||
}) do
|
||||
attachments
|
||||
|> Enum.flat_map(fn item -> Enum.map(item["url"], & &1["href"]) end)
|
||||
|> fetch_objects
|
||||
|> prepare_objects(actor, Enum.map(attachments, & &1["name"]))
|
||||
|> filter_objects
|
||||
|> do_clean
|
||||
if Pleroma.Config.get([:instance, :cleanup_attachments], false) do
|
||||
attachments
|
||||
|> Enum.flat_map(fn item -> Enum.map(item["url"], & &1["href"]) end)
|
||||
|> fetch_objects
|
||||
|> prepare_objects(actor, Enum.map(attachments, & &1["name"]))
|
||||
|> filter_objects
|
||||
|> do_clean
|
||||
end
|
||||
|
||||
{:ok, :success}
|
||||
end
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ defmodule Pleroma.Workers.PurgeExpiredActivity do
|
|||
Worker which purges expired activity.
|
||||
"""
|
||||
|
||||
use Oban.Worker, queue: :activity_expiration, max_attempts: 1
|
||||
use Oban.Worker, queue: :activity_expiration, max_attempts: 1, unique: [period: :infinity]
|
||||
|
||||
import Ecto.Query
|
||||
|
||||
|
|
|
|||
|
|
@ -9,38 +9,50 @@ defmodule Pleroma.Workers.ScheduledActivityWorker do
|
|||
|
||||
use Pleroma.Workers.WorkerHelper, queue: "scheduled_activities"
|
||||
|
||||
alias Pleroma.Config
|
||||
alias Pleroma.Repo
|
||||
alias Pleroma.ScheduledActivity
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.CommonAPI
|
||||
|
||||
require Logger
|
||||
|
||||
@impl Oban.Worker
|
||||
def perform(%Job{args: %{"activity_id" => activity_id}}) do
|
||||
if Config.get([ScheduledActivity, :enabled]) do
|
||||
case Pleroma.Repo.get(ScheduledActivity, activity_id) do
|
||||
%ScheduledActivity{} = scheduled_activity ->
|
||||
post_activity(scheduled_activity)
|
||||
with %ScheduledActivity{} = scheduled_activity <- find_scheduled_activity(activity_id),
|
||||
%User{} = user <- find_user(scheduled_activity.user_id) do
|
||||
params = atomize_keys(scheduled_activity.params)
|
||||
|
||||
_ ->
|
||||
Logger.error("#{__MODULE__} Couldn't find scheduled activity: #{activity_id}")
|
||||
end
|
||||
Repo.transaction(fn ->
|
||||
{:ok, activity} = Pleroma.Web.CommonAPI.post(user, params)
|
||||
{:ok, _} = ScheduledActivity.delete(scheduled_activity)
|
||||
activity
|
||||
end)
|
||||
else
|
||||
{:error, :scheduled_activity_not_found} = error ->
|
||||
Logger.error("#{__MODULE__} Couldn't find scheduled activity: #{activity_id}")
|
||||
error
|
||||
|
||||
{:error, :user_not_found} = error ->
|
||||
Logger.error("#{__MODULE__} Couldn't find user for scheduled activity: #{activity_id}")
|
||||
error
|
||||
end
|
||||
end
|
||||
|
||||
defp post_activity(%ScheduledActivity{user_id: user_id, params: params} = scheduled_activity) do
|
||||
params = Map.new(params, fn {key, value} -> {String.to_existing_atom(key), value} end)
|
||||
|
||||
with {:delete, {:ok, _}} <- {:delete, ScheduledActivity.delete(scheduled_activity)},
|
||||
{:user, %User{} = user} <- {:user, User.get_cached_by_id(user_id)},
|
||||
{:post, {:ok, _}} <- {:post, CommonAPI.post(user, params)} do
|
||||
:ok
|
||||
else
|
||||
error ->
|
||||
Logger.error(
|
||||
"#{__MODULE__} Couldn't create a status from the scheduled activity: #{inspect(error)}"
|
||||
)
|
||||
defp find_scheduled_activity(id) do
|
||||
with nil <- Repo.get(ScheduledActivity, id) do
|
||||
{:error, :scheduled_activity_not_found}
|
||||
end
|
||||
end
|
||||
|
||||
defp find_user(id) do
|
||||
with nil <- User.get_cached_by_id(id) do
|
||||
{:error, :user_not_found}
|
||||
end
|
||||
end
|
||||
|
||||
defp atomize_keys(map) do
|
||||
Map.new(map, fn
|
||||
{key, value} when is_map(value) -> {String.to_existing_atom(key), atomize_keys(value)}
|
||||
{key, value} -> {String.to_existing_atom(key), value}
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue