2019-08-13 19:20:26 +02:00
|
|
|
# Pleroma: A lightweight social networking server
|
2020-03-02 06:08:45 +01:00
|
|
|
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
2019-08-13 19:20:26 +02:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
defmodule Pleroma.Workers.BackgroundWorker do
|
|
|
|
alias Pleroma.Activity
|
|
|
|
alias Pleroma.User
|
|
|
|
alias Pleroma.Web.ActivityPub.MRF.MediaProxyWarmingPolicy
|
|
|
|
|
2019-08-31 20:58:42 +02:00
|
|
|
use Pleroma.Workers.WorkerHelper, queue: "background"
|
|
|
|
|
2019-08-13 19:20:26 +02:00
|
|
|
@impl Oban.Worker
|
|
|
|
|
2019-08-23 08:23:10 +02:00
|
|
|
def perform(%{"op" => "deactivate_user", "user_id" => user_id, "status" => status}, _job) do
|
2019-08-31 18:08:56 +02:00
|
|
|
user = User.get_cached_by_id(user_id)
|
2019-08-13 19:20:26 +02:00
|
|
|
User.perform(:deactivate_async, user, status)
|
|
|
|
end
|
|
|
|
|
2019-08-23 08:23:10 +02:00
|
|
|
def perform(%{"op" => "delete_user", "user_id" => user_id}, _job) do
|
2019-08-31 18:08:56 +02:00
|
|
|
user = User.get_cached_by_id(user_id)
|
2019-08-13 19:20:26 +02:00
|
|
|
User.perform(:delete, user)
|
|
|
|
end
|
|
|
|
|
2019-09-22 15:08:07 +02:00
|
|
|
def perform(%{"op" => "force_password_reset", "user_id" => user_id}, _job) do
|
|
|
|
user = User.get_cached_by_id(user_id)
|
|
|
|
User.perform(:force_password_reset, user)
|
|
|
|
end
|
|
|
|
|
2019-08-23 08:23:10 +02:00
|
|
|
def perform(
|
|
|
|
%{
|
|
|
|
"op" => "blocks_import",
|
|
|
|
"blocker_id" => blocker_id,
|
|
|
|
"blocked_identifiers" => blocked_identifiers
|
|
|
|
},
|
|
|
|
_job
|
|
|
|
) do
|
2019-08-31 18:08:56 +02:00
|
|
|
blocker = User.get_cached_by_id(blocker_id)
|
2020-04-22 17:46:04 +02:00
|
|
|
{:ok, User.perform(:blocks_import, blocker, blocked_identifiers)}
|
2019-08-13 19:20:26 +02:00
|
|
|
end
|
|
|
|
|
2019-08-23 08:23:10 +02:00
|
|
|
def perform(
|
|
|
|
%{
|
|
|
|
"op" => "follow_import",
|
|
|
|
"follower_id" => follower_id,
|
|
|
|
"followed_identifiers" => followed_identifiers
|
|
|
|
},
|
|
|
|
_job
|
|
|
|
) do
|
2019-08-31 18:08:56 +02:00
|
|
|
follower = User.get_cached_by_id(follower_id)
|
2020-04-22 17:46:04 +02:00
|
|
|
{:ok, User.perform(:follow_import, follower, followed_identifiers)}
|
2019-08-13 19:20:26 +02:00
|
|
|
end
|
|
|
|
|
2019-08-23 08:23:10 +02:00
|
|
|
def perform(%{"op" => "media_proxy_preload", "message" => message}, _job) do
|
2019-08-13 19:20:26 +02:00
|
|
|
MediaProxyWarmingPolicy.perform(:preload, message)
|
|
|
|
end
|
|
|
|
|
2019-08-23 08:23:10 +02:00
|
|
|
def perform(%{"op" => "media_proxy_prefetch", "url" => url}, _job) do
|
2019-08-13 19:20:26 +02:00
|
|
|
MediaProxyWarmingPolicy.perform(:prefetch, url)
|
|
|
|
end
|
|
|
|
|
2019-08-23 08:23:10 +02:00
|
|
|
def perform(%{"op" => "fetch_data_for_activity", "activity_id" => activity_id}, _job) do
|
2019-08-13 19:20:26 +02:00
|
|
|
activity = Activity.get_by_id(activity_id)
|
|
|
|
Pleroma.Web.RichMedia.Helpers.perform(:fetch, activity)
|
|
|
|
end
|
2019-10-30 12:21:49 +01:00
|
|
|
|
|
|
|
def perform(%{"op" => "move_following", "origin_id" => origin_id, "target_id" => target_id}, _) do
|
|
|
|
origin = User.get_cached_by_id(origin_id)
|
|
|
|
target = User.get_cached_by_id(target_id)
|
|
|
|
|
|
|
|
Pleroma.FollowingRelationship.move_following(origin, target)
|
|
|
|
end
|
2019-08-13 19:20:26 +02:00
|
|
|
end
|