TwitterAPI: Add /friends/ids.
authoreal <eal@waifu.club>
Tue, 14 Nov 2017 14:04:58 +0000 (16:04 +0200)
committereal <eal@waifu.club>
Tue, 14 Nov 2017 14:04:58 +0000 (16:04 +0200)
lib/pleroma/web/router.ex
lib/pleroma/web/twitter_api/twitter_api_controller.ex
test/web/twitter_api/twitter_api_controller_test.exs

index 8fe1d8ec63345a3c51846760129c32f4bcce8110..7a5c78867dcb4026eb83ae7f7215a30e1fed737d 100644 (file)
@@ -189,6 +189,7 @@ defmodule Pleroma.Web.Router do
 
     get "/statuses/followers", TwitterAPI.Controller, :followers
     get "/statuses/friends", TwitterAPI.Controller, :friends
+    get "/friends/ids", TwitterAPI.Controller, :friends_ids
 
     get "/externalprofile/show", TwitterAPI.Controller, :external_profile
   end
index 125eb8a1e9393f22dff4547ceef6faa96a671a09..887474a2350c0c363d95765a5e3080c73cf90b0f 100644 (file)
@@ -265,6 +265,18 @@ defmodule Pleroma.Web.TwitterAPI.Controller do
     end
   end
 
+  def friends_ids(%{assigns: %{user: user}} = conn, _params) do
+    with {:ok, friends} <- User.get_friends(user) do
+      ids = friends
+      |> Enum.map(fn x -> x.id end)
+      |> Poison.encode!
+      json(conn, ids)
+    else
+      _e -> bad_request_reply(conn, "Can't get friends")
+    end
+  end
+
+
   def update_profile(%{assigns: %{user: user}} = conn, params) do
     params = if bio = params["description"] do
       Map.put(params, "bio", bio)
index 6bdf29a132c54b14bcb72dfedba61f059fec94d8..d0c9a1b6d6f1a5de581019aeb5287e4e261f40f7 100644 (file)
@@ -494,6 +494,25 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
     end
   end
 
+  describe "GET /friends/ids" do
+    test "it returns a user's friends", %{conn: conn} do
+      user = insert(:user)
+      followed_one = insert(:user)
+      followed_two = insert(:user)
+      not_followed = insert(:user)
+
+      {:ok, user} = User.follow(user, followed_one)
+      {:ok, user} = User.follow(user, followed_two)
+
+      conn = conn
+      |> assign(:user, user)
+      |> get("/api/friends/ids")
+
+      expected = Poison.encode!([followed_one.id, followed_two.id])
+      assert json_response(conn, 200) == expected
+    end
+  end
+
   describe "POST /api/account/update_profile.json" do
     test "it updates a user's profile" do
       user = insert(:user)