TwitterAPI: Show users their own network.
This commit is contained in:
parent
839526a913
commit
fdac215091
|
@ -340,20 +340,32 @@ def external_profile(%{assigns: %{user: current_user}} = conn, %{"profileurl" =>
|
|||
end
|
||||
end
|
||||
|
||||
def followers(conn, params) do
|
||||
with {:ok, user} <- TwitterAPI.get_user(conn.assigns[:user], params),
|
||||
def followers(%{assigns: %{user: for_user}} = conn, params) do
|
||||
with {:ok, user} <- TwitterAPI.get_user(for_user, params),
|
||||
{:ok, followers} <- User.get_followers(user) do
|
||||
followers = if(user.info.hide_network, do: [], else: followers)
|
||||
followers =
|
||||
cond do
|
||||
for_user && user.id == for_user.id -> followers
|
||||
user.info.hide_network -> []
|
||||
true -> followers
|
||||
end
|
||||
|
||||
render(conn, UserView, "index.json", %{users: followers, for: conn.assigns[:user]})
|
||||
else
|
||||
_e -> bad_request_reply(conn, "Can't get followers")
|
||||
end
|
||||
end
|
||||
|
||||
def friends(conn, params) do
|
||||
def friends(%{assigns: %{user: for_user}} = conn, params) do
|
||||
with {:ok, user} <- TwitterAPI.get_user(conn.assigns[:user], params),
|
||||
{:ok, friends} <- User.get_friends(user) do
|
||||
friends = if(user.info.hide_network, do: [], else: friends)
|
||||
friends =
|
||||
cond do
|
||||
for_user && user.id == for_user.id -> friends
|
||||
user.info.hide_network -> []
|
||||
true -> friends
|
||||
end
|
||||
|
||||
render(conn, UserView, "index.json", %{users: friends, for: conn.assigns[:user]})
|
||||
else
|
||||
_e -> bad_request_reply(conn, "Can't get friends")
|
||||
|
|
|
@ -897,6 +897,25 @@ test "it returns empty for a hidden network", %{conn: conn} do
|
|||
|
||||
assert [] == json_response(conn, 200)
|
||||
end
|
||||
|
||||
test "it returns the followers for a hidden network if requested by the user themselves", %{
|
||||
conn: conn
|
||||
} do
|
||||
user = insert(:user, %{info: %{hide_network: true}})
|
||||
follower_one = insert(:user)
|
||||
follower_two = insert(:user)
|
||||
not_follower = insert(:user)
|
||||
|
||||
{:ok, follower_one} = User.follow(follower_one, user)
|
||||
{:ok, follower_two} = User.follow(follower_two, user)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> get("/api/statuses/followers", %{"user_id" => user.id})
|
||||
|
||||
refute [] == json_response(conn, 200)
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET /api/statuses/friends" do
|
||||
|
@ -958,6 +977,25 @@ test "it returns empty for a hidden network", %{conn: conn} do
|
|||
assert [] == json_response(conn, 200)
|
||||
end
|
||||
|
||||
test "it returns friends for a hidden network if the user themselves request it", %{
|
||||
conn: conn
|
||||
} do
|
||||
user = insert(:user, %{info: %{hide_network: true}})
|
||||
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/statuses/friends", %{"user_id" => user.id})
|
||||
|
||||
refute [] == json_response(conn, 200)
|
||||
end
|
||||
|
||||
test "it returns a given user's friends with screen_name", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
followed_one = insert(:user)
|
||||
|
|
Loading…
Reference in New Issue