From: Ivan Tashkinov Date: Fri, 28 Dec 2018 20:01:03 +0000 (+0300) Subject: [#483] Blocked users list import (TwitterAPI). X-Git-Url: https://git.squeep.com/?a=commitdiff_plain;h=700661b761117e6673ad254877ebba902b9d751b;p=akkoma [#483] Blocked users list import (TwitterAPI). --- diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex index a7f78ba81..43b04e508 100644 --- a/lib/pleroma/web/router.ex +++ b/lib/pleroma/web/router.ex @@ -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) diff --git a/lib/pleroma/web/twitter_api/controllers/util_controller.ex b/lib/pleroma/web/twitter_api/controllers/util_controller.ex index c872aec2b..6a9325afe 100644 --- a/lib/pleroma/web/twitter_api/controllers/util_controller.ex +++ b/lib/pleroma/web/twitter_api/controllers/util_controller.ex @@ -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} ->