2019-08-13 11:20:26 -06:00
|
|
|
# Pleroma: A lightweight social networking server
|
2020-03-01 22:08:45 -07:00
|
|
|
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
2019-08-13 11:20:26 -06: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 12:58:42 -06:00
|
|
|
use Pleroma.Workers.WorkerHelper, queue: "background"
|
|
|
|
|
2019-08-13 11:20:26 -06:00
|
|
|
@impl Oban.Worker
|
|
|
|
|
2020-06-23 06:09:01 -06:00
|
|
|
def perform(%Job{args: %{"op" => "deactivate_user", "user_id" => user_id, "status" => status}}) do
|
2019-08-31 10:08:56 -06:00
|
|
|
user = User.get_cached_by_id(user_id)
|
2019-08-13 11:20:26 -06:00
|
|
|
User.perform(:deactivate_async, user, status)
|
|
|
|
end
|
|
|
|
|
2020-06-23 06:09:01 -06:00
|
|
|
def perform(%Job{args: %{"op" => "delete_user", "user_id" => user_id}}) do
|
2019-08-31 10:08:56 -06:00
|
|
|
user = User.get_cached_by_id(user_id)
|
2019-08-13 11:20:26 -06:00
|
|
|
User.perform(:delete, user)
|
|
|
|
end
|
|
|
|
|
2020-06-23 06:09:01 -06:00
|
|
|
def perform(%Job{args: %{"op" => "force_password_reset", "user_id" => user_id}}) do
|
2019-09-22 07:08:07 -06:00
|
|
|
user = User.get_cached_by_id(user_id)
|
|
|
|
User.perform(:force_password_reset, user)
|
|
|
|
end
|
|
|
|
|
2020-09-17 00:13:43 -06:00
|
|
|
def perform(%Job{args: %{"op" => op, "user_id" => user_id, "identifiers" => identifiers}})
|
|
|
|
when op in ["blocks_import", "follow_import", "mutes_import"] do
|
2020-09-06 12:42:51 -06:00
|
|
|
user = User.get_cached_by_id(user_id)
|
2020-09-17 00:13:43 -06:00
|
|
|
{:ok, User.Import.perform(String.to_atom(op), user, identifiers)}
|
2019-08-13 11:20:26 -06:00
|
|
|
end
|
|
|
|
|
2020-06-23 06:09:01 -06:00
|
|
|
def perform(%Job{args: %{"op" => "media_proxy_preload", "message" => message}}) do
|
2019-08-13 11:20:26 -06:00
|
|
|
MediaProxyWarmingPolicy.perform(:preload, message)
|
|
|
|
end
|
|
|
|
|
2020-06-23 06:09:01 -06:00
|
|
|
def perform(%Job{args: %{"op" => "media_proxy_prefetch", "url" => url}}) do
|
2019-08-13 11:20:26 -06:00
|
|
|
MediaProxyWarmingPolicy.perform(:prefetch, url)
|
|
|
|
end
|
|
|
|
|
2020-06-23 06:09:01 -06:00
|
|
|
def perform(%Job{args: %{"op" => "fetch_data_for_activity", "activity_id" => activity_id}}) do
|
2019-08-13 11:20:26 -06:00
|
|
|
activity = Activity.get_by_id(activity_id)
|
|
|
|
Pleroma.Web.RichMedia.Helpers.perform(:fetch, activity)
|
|
|
|
end
|
2019-10-30 05:21:49 -06:00
|
|
|
|
2020-06-23 06:09:01 -06:00
|
|
|
def perform(%Job{
|
|
|
|
args: %{"op" => "move_following", "origin_id" => origin_id, "target_id" => target_id}
|
|
|
|
}) do
|
2019-10-30 05:21:49 -06:00
|
|
|
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 11:20:26 -06:00
|
|
|
end
|