1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Workers.BackgroundWorker do
8 alias Pleroma.Web.ActivityPub.MRF.MediaProxyWarmingPolicy
9 alias Pleroma.Web.OAuth.Token.CleanWorker
11 use Pleroma.Workers.WorkerHelper, queue: "background"
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)
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)
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)
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)
36 "op" => "blocks_import",
37 "blocker_id" => blocker_id,
38 "blocked_identifiers" => blocked_identifiers
42 blocker = User.get_cached_by_id(blocker_id)
43 User.perform(:blocks_import, blocker, blocked_identifiers)
48 "op" => "follow_import",
49 "follower_id" => follower_id,
50 "followed_identifiers" => followed_identifiers
54 follower = User.get_cached_by_id(follower_id)
55 User.perform(:follow_import, follower, followed_identifiers)
58 def perform(%{"op" => "clean_expired_tokens"}, _job) do
59 CleanWorker.perform(:clean)
62 def perform(%{"op" => "media_proxy_preload", "message" => message}, _job) do
63 MediaProxyWarmingPolicy.perform(:preload, message)
66 def perform(%{"op" => "media_proxy_prefetch", "url" => url}, _job) do
67 MediaProxyWarmingPolicy.perform(:prefetch, url)
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)
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)
79 Pleroma.FollowingRelationship.move_following(origin, target)