2019-08-13 11:20:26 -06:00
|
|
|
# Pleroma: A lightweight social networking server
|
|
|
|
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
defmodule Pleroma.Workers.BackgroundWorker do
|
|
|
|
alias Pleroma.Activity
|
|
|
|
alias Pleroma.User
|
|
|
|
alias Pleroma.Web.ActivityPub.MRF.MediaProxyWarmingPolicy
|
|
|
|
alias Pleroma.Web.OAuth.Token.CleanWorker
|
|
|
|
|
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
|
2019-08-23 00:23:10 -06:00
|
|
|
def perform(%{"op" => "fetch_initial_posts", "user_id" => user_id}, _job) 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(:fetch_initial_posts, user)
|
|
|
|
end
|
|
|
|
|
2019-08-23 00:23:10 -06:00
|
|
|
def perform(%{"op" => "deactivate_user", "user_id" => user_id, "status" => status}, _job) 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
|
|
|
|
|
2019-08-23 00:23:10 -06:00
|
|
|
def perform(%{"op" => "delete_user", "user_id" => user_id}, _job) 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
|
|
|
|
|
2019-08-23 00:23:10 -06:00
|
|
|
def perform(
|
|
|
|
%{
|
|
|
|
"op" => "blocks_import",
|
|
|
|
"blocker_id" => blocker_id,
|
|
|
|
"blocked_identifiers" => blocked_identifiers
|
|
|
|
},
|
|
|
|
_job
|
|
|
|
) do
|
2019-08-31 10:08:56 -06:00
|
|
|
blocker = User.get_cached_by_id(blocker_id)
|
2019-08-13 11:20:26 -06:00
|
|
|
User.perform(:blocks_import, blocker, blocked_identifiers)
|
|
|
|
end
|
|
|
|
|
2019-08-23 00:23:10 -06:00
|
|
|
def perform(
|
|
|
|
%{
|
|
|
|
"op" => "follow_import",
|
|
|
|
"follower_id" => follower_id,
|
|
|
|
"followed_identifiers" => followed_identifiers
|
|
|
|
},
|
|
|
|
_job
|
|
|
|
) do
|
2019-08-31 10:08:56 -06:00
|
|
|
follower = User.get_cached_by_id(follower_id)
|
2019-08-13 11:20:26 -06:00
|
|
|
User.perform(:follow_import, follower, followed_identifiers)
|
|
|
|
end
|
|
|
|
|
2019-08-23 00:23:10 -06:00
|
|
|
def perform(%{"op" => "clean_expired_tokens"}, _job) do
|
2019-08-13 11:20:26 -06:00
|
|
|
CleanWorker.perform(:clean)
|
|
|
|
end
|
|
|
|
|
2019-08-23 00:23:10 -06:00
|
|
|
def perform(%{"op" => "media_proxy_preload", "message" => message}, _job) do
|
2019-08-13 11:20:26 -06:00
|
|
|
MediaProxyWarmingPolicy.perform(:preload, message)
|
|
|
|
end
|
|
|
|
|
2019-08-23 00:23:10 -06:00
|
|
|
def perform(%{"op" => "media_proxy_prefetch", "url" => url}, _job) do
|
2019-08-13 11:20:26 -06:00
|
|
|
MediaProxyWarmingPolicy.perform(:prefetch, url)
|
|
|
|
end
|
|
|
|
|
2019-08-23 00:23:10 -06:00
|
|
|
def perform(%{"op" => "fetch_data_for_activity", "activity_id" => activity_id}, _job) do
|
2019-08-13 11:20:26 -06:00
|
|
|
activity = Activity.get_by_id(activity_id)
|
|
|
|
Pleroma.Web.RichMedia.Helpers.perform(:fetch, activity)
|
|
|
|
end
|
|
|
|
end
|