Merge branch 'delete-account-fix' into 'develop'
[akkoma] / lib / pleroma / workers / background_worker.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Workers.BackgroundWorker do
6 alias Pleroma.Instances.Instance
7 alias Pleroma.User
8
9 use Pleroma.Workers.WorkerHelper, queue: "background"
10
11 @impl Oban.Worker
12
13 def perform(%Job{args: %{"op" => "user_activation", "user_id" => user_id, "status" => status}}) do
14 user = User.get_cached_by_id(user_id)
15 User.perform(:set_activation_async, user, status)
16 end
17
18 def perform(%Job{args: %{"op" => "delete_user", "user_id" => user_id}}) do
19 user = User.get_cached_by_id(user_id)
20 User.perform(:delete, user)
21 end
22
23 def perform(%Job{args: %{"op" => "force_password_reset", "user_id" => user_id}}) do
24 user = User.get_cached_by_id(user_id)
25 User.perform(:force_password_reset, user)
26 end
27
28 def perform(%Job{args: %{"op" => op, "user_id" => user_id, "identifiers" => identifiers}})
29 when op in ["blocks_import", "follow_import", "mutes_import"] do
30 user = User.get_cached_by_id(user_id)
31 {:ok, User.Import.perform(String.to_atom(op), user, identifiers)}
32 end
33
34 def perform(%Job{
35 args: %{"op" => "move_following", "origin_id" => origin_id, "target_id" => target_id}
36 }) do
37 origin = User.get_cached_by_id(origin_id)
38 target = User.get_cached_by_id(target_id)
39
40 Pleroma.FollowingRelationship.move_following(origin, target)
41 end
42
43 def perform(%Job{args: %{"op" => "delete_instance", "host" => host}}) do
44 Instance.perform(:delete_instance, host)
45 end
46 end