Merge branch 'feature/move-activity' into 'develop'
[akkoma] / lib / pleroma / workers / background_worker.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 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 alias Pleroma.Web.OAuth.Token.CleanWorker
10
11 use Pleroma.Workers.WorkerHelper, queue: "background"
12
13 @impl Oban.Worker
14 def perform(%{"op" => "fetch_initial_posts", "user_id" => user_id}, _job) do
15 user = User.get_cached_by_id(user_id)
16 User.perform(:fetch_initial_posts, user)
17 end
18
19 def perform(%{"op" => "deactivate_user", "user_id" => user_id, "status" => status}, _job) do
20 user = User.get_cached_by_id(user_id)
21 User.perform(:deactivate_async, user, status)
22 end
23
24 def perform(%{"op" => "delete_user", "user_id" => user_id}, _job) do
25 user = User.get_cached_by_id(user_id)
26 User.perform(:delete, user)
27 end
28
29 def perform(%{"op" => "force_password_reset", "user_id" => user_id}, _job) do
30 user = User.get_cached_by_id(user_id)
31 User.perform(:force_password_reset, user)
32 end
33
34 def perform(
35 %{
36 "op" => "blocks_import",
37 "blocker_id" => blocker_id,
38 "blocked_identifiers" => blocked_identifiers
39 },
40 _job
41 ) do
42 blocker = User.get_cached_by_id(blocker_id)
43 User.perform(:blocks_import, blocker, blocked_identifiers)
44 end
45
46 def perform(
47 %{
48 "op" => "follow_import",
49 "follower_id" => follower_id,
50 "followed_identifiers" => followed_identifiers
51 },
52 _job
53 ) do
54 follower = User.get_cached_by_id(follower_id)
55 User.perform(:follow_import, follower, followed_identifiers)
56 end
57
58 def perform(%{"op" => "clean_expired_tokens"}, _job) do
59 CleanWorker.perform(:clean)
60 end
61
62 def perform(%{"op" => "media_proxy_preload", "message" => message}, _job) do
63 MediaProxyWarmingPolicy.perform(:preload, message)
64 end
65
66 def perform(%{"op" => "media_proxy_prefetch", "url" => url}, _job) do
67 MediaProxyWarmingPolicy.perform(:prefetch, url)
68 end
69
70 def perform(%{"op" => "fetch_data_for_activity", "activity_id" => activity_id}, _job) do
71 activity = Activity.get_by_id(activity_id)
72 Pleroma.Web.RichMedia.Helpers.perform(:fetch, activity)
73 end
74
75 def perform(%{"op" => "move_following", "origin_id" => origin_id, "target_id" => target_id}, _) do
76 origin = User.get_cached_by_id(origin_id)
77 target = User.get_cached_by_id(target_id)
78
79 Pleroma.FollowingRelationship.move_following(origin, target)
80 end
81 end