Merge branch 'bugfix/1629-fav-race-condition' into 'develop'
[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(%{"op" => "deactivate_user", "user_id" => user_id, "status" => status}, _job) do
15 user = User.get_cached_by_id(user_id)
16 User.perform(:deactivate_async, user, status)
17 end
18
19 def perform(%{"op" => "delete_user", "user_id" => user_id}, _job) do
20 user = User.get_cached_by_id(user_id)
21 User.perform(:delete, user)
22 end
23
24 def perform(%{"op" => "force_password_reset", "user_id" => user_id}, _job) do
25 user = User.get_cached_by_id(user_id)
26 User.perform(:force_password_reset, user)
27 end
28
29 def perform(
30 %{
31 "op" => "blocks_import",
32 "blocker_id" => blocker_id,
33 "blocked_identifiers" => blocked_identifiers
34 },
35 _job
36 ) do
37 blocker = User.get_cached_by_id(blocker_id)
38 {:ok, User.perform(:blocks_import, blocker, blocked_identifiers)}
39 end
40
41 def perform(
42 %{
43 "op" => "follow_import",
44 "follower_id" => follower_id,
45 "followed_identifiers" => followed_identifiers
46 },
47 _job
48 ) do
49 follower = User.get_cached_by_id(follower_id)
50 {:ok, User.perform(:follow_import, follower, followed_identifiers)}
51 end
52
53 def perform(%{"op" => "media_proxy_preload", "message" => message}, _job) do
54 MediaProxyWarmingPolicy.perform(:preload, message)
55 end
56
57 def perform(%{"op" => "media_proxy_prefetch", "url" => url}, _job) do
58 MediaProxyWarmingPolicy.perform(:prefetch, url)
59 end
60
61 def perform(%{"op" => "fetch_data_for_activity", "activity_id" => activity_id}, _job) do
62 activity = Activity.get_by_id(activity_id)
63 Pleroma.Web.RichMedia.Helpers.perform(:fetch, activity)
64 end
65
66 def perform(%{"op" => "move_following", "origin_id" => origin_id, "target_id" => target_id}, _) do
67 origin = User.get_cached_by_id(origin_id)
68 target = User.get_cached_by_id(target_id)
69
70 Pleroma.FollowingRelationship.move_following(origin, target)
71 end
72 end