Browse Source

Handle new-style mastodon follow lists

Fixes https://git.pleroma.social/pleroma/pleroma/issues/814
tags/v1.1.4
Normandy kaniini 5 years ago
parent
commit
d4a749cfb2
2 changed files with 21 additions and 1 deletions
  1. +6
    -1
      lib/pleroma/web/twitter_api/controllers/util_controller.ex
  2. +15
    -0
      test/web/twitter_api/util_controller_test.exs

+ 6
- 1
lib/pleroma/web/twitter_api/controllers/util_controller.ex View 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


+ 15
- 0
test/web/twitter_api/util_controller_test.exs View 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"])


Loading…
Cancel
Save