1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.User.Import do
9 alias Pleroma.Web.CommonAPI
10 alias Pleroma.Workers.BackgroundWorker
14 @spec perform(atom(), User.t(), list()) :: :ok | list() | {:error, any()}
15 def perform(:mutes_import, %User{} = user, [_ | _] = identifiers) do
19 with {:ok, %User{} = muted_user} <- User.get_or_fetch(identifier),
20 {:ok, _} <- User.mute(user, muted_user) do
23 error -> handle_error(:mutes_import, identifier, error)
29 def perform(:blocks_import, %User{} = blocker, [_ | _] = identifiers) do
33 with {:ok, %User{} = blocked} <- User.get_or_fetch(identifier),
34 {:ok, _block} <- CommonAPI.block(blocker, blocked) do
37 error -> handle_error(:blocks_import, identifier, error)
43 def perform(:follow_import, %User{} = follower, [_ | _] = identifiers) do
47 with {:ok, %User{} = followed} <- User.get_or_fetch(identifier),
48 {:ok, follower, followed} <- User.maybe_direct_follow(follower, followed),
49 {:ok, _, _, _} <- CommonAPI.follow(follower, followed) do
52 error -> handle_error(:follow_import, identifier, error)
58 def perform(_, _, _), do: :ok
60 defp handle_error(op, user_id, error) do
61 Logger.debug("#{op} failed for #{user_id} with: #{inspect(error)}")
65 def blocks_import(%User{} = blocker, [_ | _] = identifiers) do
66 BackgroundWorker.enqueue(
68 %{"user_id" => blocker.id, "identifiers" => identifiers}
72 def follow_import(%User{} = follower, [_ | _] = identifiers) do
73 BackgroundWorker.enqueue(
75 %{"user_id" => follower.id, "identifiers" => identifiers}
79 def mutes_import(%User{} = user, [_ | _] = identifiers) do
80 BackgroundWorker.enqueue(
82 %{"user_id" => user.id, "identifiers" => identifiers}