|> Map.merge(Utils.make_json_ld_header())
end
- def render("following.json", %{user: user, page: page}) do
+ def render("following.json", %{user: user, page: page} = opts) do
+ showing = (opts[:for] && opts[:for] == user) || !user.info.hide_follows
query = User.get_friends_query(user)
query = from(user in query, select: [:ap_id])
following = Repo.all(query)
total =
- if !user.info.hide_follows do
+ if showing do
length(following)
else
0
end
- collection(following, "#{user.ap_id}/following", page, !user.info.hide_follows, total)
+ collection(following, "#{user.ap_id}/following", page, showing, total)
|> Map.merge(Utils.make_json_ld_header())
end
- def render("following.json", %{user: user}) do
+ def render("following.json", %{user: user} = opts) do
+ showing = (opts[:for] && opts[:for] == user) || !user.info.hide_follows
query = User.get_friends_query(user)
query = from(user in query, select: [:ap_id])
following = Repo.all(query)
total =
- if !user.info.hide_follows do
+ if showing do
length(following)
else
0
"id" => "#{user.ap_id}/following",
"type" => "OrderedCollection",
"totalItems" => total,
- "first" => collection(following, "#{user.ap_id}/following", 1, !user.info.hide_follows)
+ "first" =>
+ if showing do
+ collection(following, "#{user.ap_id}/following", 1, !user.info.hide_follows)
+ else
+ "#{user.ap_id}/following?page=1"
+ end
}
|> Map.merge(Utils.make_json_ld_header())
end
- def render("followers.json", %{user: user, page: page}) do
+ def render("followers.json", %{user: user, page: page} = opts) do
+ showing = (opts[:for] && opts[:for] == user) || !user.info.hide_followers
+
query = User.get_followers_query(user)
query = from(user in query, select: [:ap_id])
followers = Repo.all(query)
total =
- if !user.info.hide_followers do
+ if showing do
length(followers)
else
0
end
- collection(followers, "#{user.ap_id}/followers", page, !user.info.hide_followers, total)
+ collection(followers, "#{user.ap_id}/followers", page, showing, total)
|> Map.merge(Utils.make_json_ld_header())
end
- def render("followers.json", %{user: user}) do
+ def render("followers.json", %{user: user} = opts) do
+ showing = (opts[:for] && opts[:for] == user) || !user.info.hide_followers
+
query = User.get_followers_query(user)
query = from(user in query, select: [:ap_id])
followers = Repo.all(query)
total =
- if !user.info.hide_followers do
+ if showing do
length(followers)
else
0
"type" => "OrderedCollection",
"totalItems" => total,
"first" =>
- collection(followers, "#{user.ap_id}/followers", 1, !user.info.hide_followers, total)
+ if showing do
+ collection(followers, "#{user.ap_id}/followers", 1, showing, total)
+ else
+ "#{user.ap_id}/followers?page=1"
+ end
}
|> Map.merge(Utils.make_json_ld_header())
end
assert result["first"]["orderedItems"] == [user.ap_id]
end
- test "it returns returns empty if the user has 'hide_followers' set", %{conn: conn} do
+ test "it returns returns a uri if the user has 'hide_followers' set", %{conn: conn} do
user = insert(:user)
user_two = insert(:user, %{info: %{hide_followers: true}})
User.follow(user, user_two)
|> get("/users/#{user_two.nickname}/followers")
|> json_response(200)
- assert result["first"]["orderedItems"] == []
- assert result["totalItems"] == 0
+ assert is_binary(result["first"])
end
test "it works for more than 10 users", %{conn: conn} do
assert result["first"]["orderedItems"] == [user_two.ap_id]
end
- test "it returns returns empty if the user has 'hide_follows' set", %{conn: conn} do
+ test "it returns a uri if the user has 'hide_follows' set", %{conn: conn} do
user = insert(:user, %{info: %{hide_follows: true}})
user_two = insert(:user)
User.follow(user, user_two)
|> get("/users/#{user.nickname}/following")
|> json_response(200)
- assert result["first"]["orderedItems"] == []
- assert result["totalItems"] == 0
+ assert is_binary(result["first"])
end
test "it works for more than 10 users", %{conn: conn} do