Handle new-style mastodon follow lists
authorNormandy <archaeme@biribiri.dev>
Tue, 16 Apr 2019 18:35:38 +0000 (18:35 +0000)
committerkaniini <nenolod@gmail.com>
Tue, 16 Apr 2019 18:35:38 +0000 (18:35 +0000)
Fixes https://git.pleroma.social/pleroma/pleroma/issues/814

lib/pleroma/web/twitter_api/controllers/util_controller.ex
test/web/twitter_api/util_controller_test.exs

index d066d35f5c129b0463b9a094506c0f24b9553a63..ed45ca73574fc62b407ff0429f08beb3f88c107f 100644 (file)
@@ -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
index a4b3d651af1a2b5a491e90a3a1744d15431fec10..c58b49ea4cad746c484a1befe66e459bfe6bd7f6 100644 (file)
@@ -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"])