Merge branch 'fix/twitterapi-follow-lists' into 'develop'

Fix follower/following lists.

Closes #29

See merge request pleroma/pleroma!41
This commit is contained in:
lambda 2017-12-18 22:44:15 +00:00
commit 29c9812789
3 changed files with 39 additions and 7 deletions

View File

@ -147,6 +147,8 @@ def user_fetcher(username) do
get "/qvitter/statuses/user_timeline", TwitterAPI.Controller, :user_timeline get "/qvitter/statuses/user_timeline", TwitterAPI.Controller, :user_timeline
get "/users/show", TwitterAPI.Controller, :show_user get "/users/show", TwitterAPI.Controller, :show_user
get "/statuses/followers", TwitterAPI.Controller, :followers
get "/statuses/friends", TwitterAPI.Controller, :friends
get "/statuses/show/:id", TwitterAPI.Controller, :fetch_status get "/statuses/show/:id", TwitterAPI.Controller, :fetch_status
get "/statusnet/conversation/:id", TwitterAPI.Controller, :fetch_conversation get "/statusnet/conversation/:id", TwitterAPI.Controller, :fetch_conversation
@ -193,8 +195,6 @@ def user_fetcher(username) do
post "/qvitter/update_avatar", TwitterAPI.Controller, :update_avatar post "/qvitter/update_avatar", TwitterAPI.Controller, :update_avatar
get "/statuses/followers", TwitterAPI.Controller, :followers
get "/statuses/friends", TwitterAPI.Controller, :friends
get "/friends/ids", TwitterAPI.Controller, :friends_ids get "/friends/ids", TwitterAPI.Controller, :friends_ids
get "/friendships/no_retweets/ids", TwitterAPI.Controller, :empty_array get "/friendships/no_retweets/ids", TwitterAPI.Controller, :empty_array

View File

@ -263,16 +263,18 @@ def update_most_recent_notification(%{assigns: %{user: user}} = conn, %{"id" =>
end end
end end
def followers(%{assigns: %{user: user}} = conn, _params) do def followers(conn, params) do
with {:ok, followers} <- User.get_followers(user) do with {:ok, user} <- TwitterAPI.get_user(conn.assigns.user, params),
{:ok, followers} <- User.get_followers(user) do
render(conn, UserView, "index.json", %{users: followers, for: user}) render(conn, UserView, "index.json", %{users: followers, for: user})
else else
_e -> bad_request_reply(conn, "Can't get followers") _e -> bad_request_reply(conn, "Can't get followers")
end end
end end
def friends(%{assigns: %{user: user}} = conn, _params) do def friends(conn, params) do
with {:ok, friends} <- User.get_friends(user) do with {:ok, user} <- TwitterAPI.get_user(conn.assigns.user, params),
{:ok, friends} <- User.get_friends(user) do
render(conn, UserView, "index.json", %{users: friends, for: user}) render(conn, UserView, "index.json", %{users: friends, for: user})
else else
_e -> bad_request_reply(conn, "Can't get friends") _e -> bad_request_reply(conn, "Can't get friends")

View File

@ -518,7 +518,7 @@ test "it returns a user's followers", %{conn: conn} do
end end
describe "GET /api/statuses/friends" do describe "GET /api/statuses/friends" do
test "it returns a user's friends", %{conn: conn} do test "it returns the logged in user's friends", %{conn: conn} do
user = insert(:user) user = insert(:user)
followed_one = insert(:user) followed_one = insert(:user)
followed_two = insert(:user) followed_two = insert(:user)
@ -533,6 +533,36 @@ test "it returns a user's friends", %{conn: conn} do
assert MapSet.equal?(MapSet.new(json_response(conn, 200)), MapSet.new(UserView.render("index.json", %{users: [followed_one, followed_two], for: user}))) assert MapSet.equal?(MapSet.new(json_response(conn, 200)), MapSet.new(UserView.render("index.json", %{users: [followed_one, followed_two], for: user})))
end end
test "it returns a given user's friends with user_id", %{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
|> get("/api/statuses/friends", %{"user_id" => user.id})
assert MapSet.equal?(MapSet.new(json_response(conn, 200)), MapSet.new(UserView.render("index.json", %{users: [followed_one, followed_two], for: user})))
end
test "it returns a given user's friends with screen_name", %{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
|> get("/api/statuses/friends", %{"screen_name" => user.nickname})
assert MapSet.equal?(MapSet.new(json_response(conn, 200)), MapSet.new(UserView.render("index.json", %{users: [followed_one, followed_two], for: user})))
end
end end
describe "GET /friends/ids" do describe "GET /friends/ids" do