Improve readability
[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.User
7
8 use Pleroma.Workers.WorkerHelper, queue: "background"
9
10 @impl Oban.Worker
11
12 def perform(%Job{args: %{"op" => "user_activation", "user_id" => user_id, "status" => status}}) do
13 user = User.get_cached_by_id(user_id)
14 User.perform(:set_activation_async, user, status)
15 end
16
17 def perform(%Job{args: %{"op" => "delete_user", "user_id" => user_id}}) do
18 user = User.get_cached_by_id(user_id)
19 User.perform(:delete, user)
20 end
21
22 def perform(%Job{args: %{"op" => "force_password_reset", "user_id" => user_id}}) do
23 user = User.get_cached_by_id(user_id)
24 User.perform(:force_password_reset, user)
25 end
26
27 def perform(%Job{args: %{"op" => op, "user_id" => user_id, "identifiers" => identifiers}})
28 when op in ["blocks_import", "follow_import", "mutes_import"] do
29 user = User.get_cached_by_id(user_id)
30 {:ok, User.Import.perform(String.to_atom(op), user, identifiers)}
31 end
32
33 def perform(%Job{
34 args: %{"op" => "move_following", "origin_id" => origin_id, "target_id" => target_id}
35 }) do
36 origin = User.get_cached_by_id(origin_id)
37 target = User.get_cached_by_id(target_id)
38
39 Pleroma.FollowingRelationship.move_following(origin, target)
40 end
41 end