From 3533bf7eacaceb493bd4bef4ae5625f7c99021b9 Mon Sep 17 00:00:00 2001 From: eal Date: Tue, 14 Nov 2017 16:04:58 +0200 Subject: [PATCH 1/3] TwitterAPI: Add /friends/ids. --- lib/pleroma/web/router.ex | 1 + .../web/twitter_api/twitter_api_controller.ex | 12 ++++++++++++ .../twitter_api_controller_test.exs | 19 +++++++++++++++++++ 3 files changed, 32 insertions(+) diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex index 8fe1d8ec6..7a5c78867 100644 --- a/lib/pleroma/web/router.ex +++ b/lib/pleroma/web/router.ex @@ -189,6 +189,7 @@ def user_fetcher(username) 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 diff --git a/lib/pleroma/web/twitter_api/twitter_api_controller.ex b/lib/pleroma/web/twitter_api/twitter_api_controller.ex index 125eb8a1e..887474a23 100644 --- a/lib/pleroma/web/twitter_api/twitter_api_controller.ex +++ b/lib/pleroma/web/twitter_api/twitter_api_controller.ex @@ -265,6 +265,18 @@ def friends(%{assigns: %{user: user}} = conn, _params) 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) diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs index 6bdf29a13..d0c9a1b6d 100644 --- a/test/web/twitter_api/twitter_api_controller_test.exs +++ b/test/web/twitter_api/twitter_api_controller_test.exs @@ -494,6 +494,25 @@ test "it returns a user's friends", %{conn: conn} 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) From 22bbe271154731902f94ce9a8b035cb18c58e437 Mon Sep 17 00:00:00 2001 From: eal Date: Tue, 14 Nov 2017 16:10:13 +0200 Subject: [PATCH 2/3] TwitterAPI: Add unimplemented /friendships/no_retweets/ids. --- lib/pleroma/web/router.ex | 1 + lib/pleroma/web/twitter_api/twitter_api_controller.ex | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex index 7a5c78867..1fb8cb51a 100644 --- a/lib/pleroma/web/router.ex +++ b/lib/pleroma/web/router.ex @@ -190,6 +190,7 @@ def user_fetcher(username) do get "/statuses/followers", TwitterAPI.Controller, :followers get "/statuses/friends", TwitterAPI.Controller, :friends get "/friends/ids", TwitterAPI.Controller, :friends_ids + get "/friendships/no_retweets/ids", TwitterAPI.Controller, :empty_array get "/externalprofile/show", TwitterAPI.Controller, :external_profile end diff --git a/lib/pleroma/web/twitter_api/twitter_api_controller.ex b/lib/pleroma/web/twitter_api/twitter_api_controller.ex index 887474a23..9ea0773c9 100644 --- a/lib/pleroma/web/twitter_api/twitter_api_controller.ex +++ b/lib/pleroma/web/twitter_api/twitter_api_controller.ex @@ -270,12 +270,16 @@ def friends_ids(%{assigns: %{user: user}} = conn, _params) 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 empty_array(conn, _params) do + json(conn, Poison.encode!([])) + end def update_profile(%{assigns: %{user: user}} = conn, params) do params = if bio = params["description"] do From 163c65820265de5d5dbed50831c218444ebbbed1 Mon Sep 17 00:00:00 2001 From: eal Date: Tue, 14 Nov 2017 16:12:52 +0200 Subject: [PATCH 3/3] TwitterAPI: Add unimplemented /mutes/users/ids. --- lib/pleroma/web/router.ex | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex index 1fb8cb51a..339c10a66 100644 --- a/lib/pleroma/web/router.ex +++ b/lib/pleroma/web/router.ex @@ -192,6 +192,8 @@ def user_fetcher(username) do get "/friends/ids", TwitterAPI.Controller, :friends_ids get "/friendships/no_retweets/ids", TwitterAPI.Controller, :empty_array + get "/mutes/users/ids", TwitterAPI.Controller, :empty_array + get "/externalprofile/show", TwitterAPI.Controller, :external_profile end