mirror of
https://akkoma.dev/AkkomaGang/akkoma.git
synced 2024-11-27 08:16:16 +00:00
TwitterAPI: Implement hide_network.
This commit is contained in:
parent
2a639de9b3
commit
8c9a4e8b40
|
@ -343,6 +343,7 @@ defmodule Pleroma.Web.TwitterAPI.Controller do
|
||||||
def followers(conn, params) do
|
def followers(conn, params) do
|
||||||
with {:ok, user} <- TwitterAPI.get_user(conn.assigns[:user], params),
|
with {:ok, user} <- TwitterAPI.get_user(conn.assigns[:user], params),
|
||||||
{:ok, followers} <- User.get_followers(user) do
|
{:ok, followers} <- User.get_followers(user) do
|
||||||
|
followers = if(user.info.hide_network, do: [], else: followers)
|
||||||
render(conn, UserView, "index.json", %{users: followers, for: conn.assigns[:user]})
|
render(conn, UserView, "index.json", %{users: followers, for: conn.assigns[:user]})
|
||||||
else
|
else
|
||||||
_e -> bad_request_reply(conn, "Can't get followers")
|
_e -> bad_request_reply(conn, "Can't get followers")
|
||||||
|
@ -352,6 +353,7 @@ defmodule Pleroma.Web.TwitterAPI.Controller do
|
||||||
def friends(conn, params) do
|
def friends(conn, params) do
|
||||||
with {:ok, user} <- TwitterAPI.get_user(conn.assigns[:user], params),
|
with {:ok, user} <- TwitterAPI.get_user(conn.assigns[:user], params),
|
||||||
{:ok, friends} <- User.get_friends(user) do
|
{:ok, friends} <- User.get_friends(user) do
|
||||||
|
friends = if(user.info.hide_network, do: [], else: friends)
|
||||||
render(conn, UserView, "index.json", %{users: friends, for: conn.assigns[:user]})
|
render(conn, UserView, "index.json", %{users: friends, for: conn.assigns[:user]})
|
||||||
else
|
else
|
||||||
_e -> bad_request_reply(conn, "Can't get friends")
|
_e -> bad_request_reply(conn, "Can't get friends")
|
||||||
|
|
|
@ -855,6 +855,48 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|
||||||
result = json_response(conn, 200)
|
result = json_response(conn, 200)
|
||||||
assert Enum.sort(expected) == Enum.sort(result)
|
assert Enum.sort(expected) == Enum.sort(result)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "it returns a given user's followers with user_id", %{conn: conn} do
|
||||||
|
user = insert(:user)
|
||||||
|
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, not_follower)
|
||||||
|
|> get("/api/statuses/followers", %{"user_id" => user.id})
|
||||||
|
|
||||||
|
assert MapSet.equal?(
|
||||||
|
MapSet.new(json_response(conn, 200)),
|
||||||
|
MapSet.new(
|
||||||
|
UserView.render("index.json", %{
|
||||||
|
users: [follower_one, follower_two],
|
||||||
|
for: not_follower
|
||||||
|
})
|
||||||
|
)
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
test "it returns empty for a hidden network", %{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, not_follower)
|
||||||
|
|> get("/api/statuses/followers", %{"user_id" => user.id})
|
||||||
|
|
||||||
|
assert [] == json_response(conn, 200)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "GET /api/statuses/friends" do
|
describe "GET /api/statuses/friends" do
|
||||||
|
@ -899,6 +941,23 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "it returns empty for a hidden network", %{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, not_followed)
|
||||||
|
|> get("/api/statuses/friends", %{"user_id" => user.id})
|
||||||
|
|
||||||
|
assert [] == json_response(conn, 200)
|
||||||
|
end
|
||||||
|
|
||||||
test "it returns a given user's friends with screen_name", %{conn: conn} do
|
test "it returns a given user's friends with screen_name", %{conn: conn} do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
followed_one = insert(:user)
|
followed_one = insert(:user)
|
||||||
|
|
Loading…
Reference in a new issue