logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma
commit: 5f31e7ec6b6c0d5e6e4a5ee9397c0d3954329982
parent: 0d4afdc6e620b3e8fa01ea90b359cf58a736465d
Author: kaniini <nenolod@gmail.com>
Date:   Tue, 16 Apr 2019 18:35:38 +0000

Merge branch 'fix/follow-imports' into 'develop'

Handle new-style mastodon follow lists

Closes #814

See merge request pleroma/pleroma!1067

Diffstat:

Mlib/pleroma/web/twitter_api/controllers/util_controller.ex7++++++-
Mtest/web/twitter_api/util_controller_test.exs15+++++++++++++++
2 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/lib/pleroma/web/twitter_api/controllers/util_controller.ex b/lib/pleroma/web/twitter_api/controllers/util_controller.ex @@ -304,7 +304,12 @@ defmodule Pleroma.Web.TwitterAPI.UtilController do end def follow_import(%{assigns: %{user: follower}} = conn, %{"list" => list}) do - with followed_identifiers <- String.split(list), + with lines <- String.split(list, "\n"), + followed_identifiers <- + Enum.map(lines, fn line -> + String.split(line, ",") |> List.first() + end) + |> List.delete("Account address"), {:ok, _} = Task.start(fn -> User.follow_import(follower, followed_identifiers) end) do json(conn, "job started") end diff --git a/test/web/twitter_api/util_controller_test.exs b/test/web/twitter_api/util_controller_test.exs @@ -26,6 +26,21 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do assert response == "job started" end + test "it imports new-style mastodon follow lists", %{conn: conn} do + user1 = insert(:user) + user2 = insert(:user) + + response = + conn + |> assign(:user, user1) + |> post("/api/pleroma/follow_import", %{ + "list" => "Account address,Show boosts\n#{user2.ap_id},true" + }) + |> json_response(:ok) + + assert response == "job started" + end + test "requires 'follow' permission", %{conn: conn} do token1 = insert(:oauth_token, scopes: ["read", "write"]) token2 = insert(:oauth_token, scopes: ["follow"])