2019-08-13 17:20:26 +00:00
|
|
|
# Pleroma: A lightweight social networking server
|
2023-01-02 20:38:50 +00:00
|
|
|
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
|
2019-08-13 17:20:26 +00:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
defmodule Pleroma.Workers.BackgroundWorker do
|
2021-07-17 19:06:35 +00:00
|
|
|
alias Pleroma.Instances.Instance
|
2019-08-13 17:20:26 +00:00
|
|
|
alias Pleroma.User
|
|
|
|
|
2019-08-31 18:58:42 +00:00
|
|
|
use Pleroma.Workers.WorkerHelper, queue: "background"
|
|
|
|
|
2019-08-13 17:20:26 +00:00
|
|
|
@impl Oban.Worker
|
|
|
|
|
2020-10-13 22:16:03 +00:00
|
|
|
def perform(%Job{args: %{"op" => "user_activation", "user_id" => user_id, "status" => status}}) do
|
2019-08-31 16:08:56 +00:00
|
|
|
user = User.get_cached_by_id(user_id)
|
2020-10-13 22:16:03 +00:00
|
|
|
User.perform(:set_activation_async, user, status)
|
2019-08-13 17:20:26 +00:00
|
|
|
end
|
|
|
|
|
2020-06-23 12:09:01 +00:00
|
|
|
def perform(%Job{args: %{"op" => "delete_user", "user_id" => user_id}}) do
|
2019-08-31 16:08:56 +00:00
|
|
|
user = User.get_cached_by_id(user_id)
|
2019-08-13 17:20:26 +00:00
|
|
|
User.perform(:delete, user)
|
|
|
|
end
|
|
|
|
|
2020-06-23 12:09:01 +00:00
|
|
|
def perform(%Job{args: %{"op" => "force_password_reset", "user_id" => user_id}}) do
|
2019-09-22 13:08:07 +00:00
|
|
|
user = User.get_cached_by_id(user_id)
|
|
|
|
User.perform(:force_password_reset, user)
|
|
|
|
end
|
|
|
|
|
2020-09-17 06:13:43 +00:00
|
|
|
def perform(%Job{args: %{"op" => op, "user_id" => user_id, "identifiers" => identifiers}})
|
|
|
|
when op in ["blocks_import", "follow_import", "mutes_import"] do
|
2020-09-06 18:42:51 +00:00
|
|
|
user = User.get_cached_by_id(user_id)
|
2020-09-17 06:13:43 +00:00
|
|
|
{:ok, User.Import.perform(String.to_atom(op), user, identifiers)}
|
2019-08-13 17:20:26 +00:00
|
|
|
end
|
|
|
|
|
2020-06-23 12:09:01 +00:00
|
|
|
def perform(%Job{
|
|
|
|
args: %{"op" => "move_following", "origin_id" => origin_id, "target_id" => target_id}
|
|
|
|
}) do
|
2019-10-30 11:21:49 +00:00
|
|
|
origin = User.get_cached_by_id(origin_id)
|
|
|
|
target = User.get_cached_by_id(target_id)
|
|
|
|
|
|
|
|
Pleroma.FollowingRelationship.move_following(origin, target)
|
|
|
|
end
|
2021-07-17 19:06:35 +00:00
|
|
|
|
|
|
|
def perform(%Job{args: %{"op" => "delete_instance", "host" => host}}) do
|
|
|
|
Instance.perform(:delete_instance, host)
|
|
|
|
end
|
2022-11-11 18:42:29 +00:00
|
|
|
|
|
|
|
@impl Oban.Worker
|
|
|
|
def timeout(_job), do: :timer.seconds(5)
|
2019-08-13 17:20:26 +00:00
|
|
|
end
|