Merge branch 'develop' into issue/2099
[akkoma] / lib / pleroma / workers / background_worker.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Workers.BackgroundWorker do
6 alias Pleroma.Activity
7 alias Pleroma.User
8 alias Pleroma.Web.ActivityPub.MRF.MediaProxyWarmingPolicy
9
10 use Pleroma.Workers.WorkerHelper, queue: "background"
11
12 @impl Oban.Worker
13
14 def perform(%Job{args: %{"op" => "deactivate_user", "user_id" => user_id, "status" => status}}) do
15 user = User.get_cached_by_id(user_id)
16 User.perform(:deactivate_async, user, status)
17 end
18
19 def perform(%Job{args: %{"op" => "delete_user", "user_id" => user_id}}) do
20 user = User.get_cached_by_id(user_id)
21 User.perform(:delete, user)
22 end
23
24 def perform(%Job{args: %{"op" => "force_password_reset", "user_id" => user_id}}) do
25 user = User.get_cached_by_id(user_id)
26 User.perform(:force_password_reset, user)
27 end
28
29 def perform(%Job{args: %{"op" => op, "user_id" => user_id, "identifiers" => identifiers}})
30 when op in ["blocks_import", "follow_import", "mutes_import"] do
31 user = User.get_cached_by_id(user_id)
32 {:ok, User.Import.perform(String.to_atom(op), user, identifiers)}
33 end
34
35 def perform(%Job{args: %{"op" => "media_proxy_preload", "message" => message}}) do
36 MediaProxyWarmingPolicy.perform(:preload, message)
37 end
38
39 def perform(%Job{args: %{"op" => "media_proxy_prefetch", "url" => url}}) do
40 MediaProxyWarmingPolicy.perform(:prefetch, url)
41 end
42
43 def perform(%Job{args: %{"op" => "fetch_data_for_activity", "activity_id" => activity_id}}) do
44 activity = Activity.get_by_id(activity_id)
45 Pleroma.Web.RichMedia.Helpers.perform(:fetch, activity)
46 end
47
48 def perform(%Job{
49 args: %{"op" => "move_following", "origin_id" => origin_id, "target_id" => target_id}
50 }) do
51 origin = User.get_cached_by_id(origin_id)
52 target = User.get_cached_by_id(target_id)
53
54 Pleroma.FollowingRelationship.move_following(origin, target)
55 end
56 end