MastodonAPI: Show users their own network.
This commit is contained in:
parent
fdac215091
commit
3ea4476445
@ -502,18 +502,30 @@ def hashtag_timeline(%{assigns: %{user: user}} = conn, params) do
|
|||||||
|> render(StatusView, "index.json", %{activities: activities, for: user, as: :activity})
|
|> render(StatusView, "index.json", %{activities: activities, for: user, as: :activity})
|
||||||
end
|
end
|
||||||
|
|
||||||
def followers(conn, %{"id" => id}) do
|
def followers(%{assigns: %{user: for_user}} = conn, %{"id" => id}) do
|
||||||
with %User{} = user <- Repo.get(User, id),
|
with %User{} = user <- Repo.get(User, id),
|
||||||
{:ok, followers} <- User.get_followers(user) do
|
{: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, AccountView, "accounts.json", %{users: followers, as: :user})
|
render(conn, AccountView, "accounts.json", %{users: followers, as: :user})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def following(conn, %{"id" => id}) do
|
def following(%{assigns: %{user: for_user}} = conn, %{"id" => id}) do
|
||||||
with %User{} = user <- Repo.get(User, id),
|
with %User{} = user <- Repo.get(User, id),
|
||||||
{:ok, followers} <- User.get_friends(user) do
|
{:ok, followers} <- User.get_friends(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, AccountView, "accounts.json", %{users: followers, as: :user})
|
render(conn, AccountView, "accounts.json", %{users: followers, as: :user})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1014,6 +1014,19 @@ test "getting followers, hide_network", %{conn: conn} do
|
|||||||
assert [] == json_response(conn, 200)
|
assert [] == json_response(conn, 200)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "getting followers, hide_network, same user requesting", %{conn: conn} do
|
||||||
|
user = insert(:user)
|
||||||
|
other_user = insert(:user, %{info: %{hide_network: true}})
|
||||||
|
{:ok, user} = User.follow(user, other_user)
|
||||||
|
|
||||||
|
conn =
|
||||||
|
conn
|
||||||
|
|> assign(:user, other_user)
|
||||||
|
|> get("/api/v1/accounts/#{other_user.id}/followers")
|
||||||
|
|
||||||
|
refute [] == json_response(conn, 200)
|
||||||
|
end
|
||||||
|
|
||||||
test "getting following", %{conn: conn} do
|
test "getting following", %{conn: conn} do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
other_user = insert(:user)
|
other_user = insert(:user)
|
||||||
@ -1039,6 +1052,19 @@ test "getting following, hide_network", %{conn: conn} do
|
|||||||
assert [] == json_response(conn, 200)
|
assert [] == json_response(conn, 200)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "getting following, hide_network, same user requesting", %{conn: conn} do
|
||||||
|
user = insert(:user, %{info: %{hide_network: true}})
|
||||||
|
other_user = insert(:user)
|
||||||
|
{:ok, user} = User.follow(user, other_user)
|
||||||
|
|
||||||
|
conn =
|
||||||
|
conn
|
||||||
|
|> assign(:user, user)
|
||||||
|
|> get("/api/v1/accounts/#{user.id}/following")
|
||||||
|
|
||||||
|
refute [] == json_response(conn, 200)
|
||||||
|
end
|
||||||
|
|
||||||
test "following / unfollowing a user", %{conn: conn} do
|
test "following / unfollowing a user", %{conn: conn} do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
other_user = insert(:user)
|
other_user = insert(:user)
|
||||||
|
Loading…
Reference in New Issue
Block a user