[#483] Blocked users list import (TwitterAPI).

This commit is contained in:
Ivan Tashkinov 2018-12-28 23:01:03 +03:00
parent 6e9a15b181
commit 700661b761
2 changed files with 30 additions and 2 deletions

View File

@ -137,6 +137,7 @@ defmodule Pleroma.Web.Router do
scope "/api/pleroma", Pleroma.Web.TwitterAPI do
pipe_through(:authenticated_api)
post("/blocks_import", UtilController, :blocks_import)
post("/follow_import", UtilController, :follow_import)
post("/change_password", UtilController, :change_password)
post("/delete_account", UtilController, :delete_account)

View File

@ -242,9 +242,12 @@ defmodule Pleroma.Web.TwitterAPI.UtilController do
def follow_import(%{assigns: %{user: user}} = conn, %{"list" => list}) do
Task.start(fn ->
String.split(list)
follower = User.get_cached_by_ap_id(user.ap_id)
list
|> String.split()
|> Enum.map(fn account ->
with %User{} = follower <- User.get_cached_by_ap_id(user.ap_id),
with %User{} <- follower,
%User{} = followed <- User.get_or_fetch(account),
{:ok, follower} <- User.maybe_direct_follow(follower, followed) do
ActivityPub.follow(follower, followed)
@ -257,6 +260,30 @@ defmodule Pleroma.Web.TwitterAPI.UtilController do
json(conn, "job started")
end
def blocks_import(conn, %{"list" => %Plug.Upload{} = listfile}) do
blocks_import(conn, %{"list" => File.read!(listfile.path)})
end
def blocks_import(%{assigns: %{user: user}} = conn, %{"list" => list}) do
Task.start(fn ->
blocker = User.get_cached_by_ap_id(user.ap_id)
list
|> String.split()
|> Enum.map(fn account ->
with %User{} <- blocker,
%User{} = blocked <- User.get_or_fetch(account),
{:ok, blocker} <- User.block(blocker, blocked) do
ActivityPub.block(blocker, blocked)
else
err -> Logger.debug("blocks_import: blocking #{account} failed with #{inspect(err)}")
end
end)
end)
json(conn, "job started")
end
def change_password(%{assigns: %{user: user}} = conn, params) do
case CommonAPI.Utils.confirm_current_password(user, params["password"]) do
{:ok, user} ->