mirror of
https://akkoma.dev/AkkomaGang/akkoma.git
synced 2024-11-18 15:14:42 +00:00
Run follow import in the background.
This commit is contained in:
parent
d89193a8d7
commit
fdfb508259
1 changed files with 12 additions and 12 deletions
|
@ -1,5 +1,6 @@
|
||||||
defmodule Pleroma.Web.TwitterAPI.UtilController do
|
defmodule Pleroma.Web.TwitterAPI.UtilController do
|
||||||
use Pleroma.Web, :controller
|
use Pleroma.Web, :controller
|
||||||
|
require Logger
|
||||||
alias Pleroma.Web
|
alias Pleroma.Web
|
||||||
alias Pleroma.Formatter
|
alias Pleroma.Formatter
|
||||||
alias Pleroma.Web.ActivityPub.ActivityPub
|
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||||
|
@ -78,20 +79,19 @@ defmodule Pleroma.Web.TwitterAPI.UtilController do
|
||||||
follow_import(conn, %{"list" => File.read!(listfile.path)})
|
follow_import(conn, %{"list" => File.read!(listfile.path)})
|
||||||
end
|
end
|
||||||
def follow_import(%{assigns: %{user: user}} = conn, %{"list" => list}) do
|
def follow_import(%{assigns: %{user: user}} = conn, %{"list" => list}) do
|
||||||
errors = list
|
Task.start_link(fn ->
|
||||||
|> String.split()
|
String.split(list)
|
||||||
|> Enum.map(fn nick ->
|
|> Enum.map(fn nick ->
|
||||||
with %User{} = follower <- User.get_cached_by_ap_id(user.ap_id),
|
with %User{} = follower <- User.get_cached_by_ap_id(user.ap_id),
|
||||||
%User{} = followed <- User.get_or_fetch_by_nickname(nick),
|
%User{} = followed <- User.get_or_fetch_by_nickname(nick),
|
||||||
{:ok, follower} <- User.follow(follower, followed),
|
{:ok, follower} <- User.follow(follower, followed) do
|
||||||
{:ok, _activity} <- ActivityPub.follow(follower, followed) do
|
ActivityPub.follow(follower, followed)
|
||||||
:ok
|
else
|
||||||
else
|
_e -> Logger.debug "follow_import: following #{nick} failed"
|
||||||
_e -> nick
|
end
|
||||||
end
|
end)
|
||||||
end)
|
end)
|
||||||
|> Enum.reject(fn x -> x == :ok end)
|
|
||||||
|
|
||||||
json conn, %{"failed follows" => errors}
|
json conn, "job started"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue