1
0
mirror of https://git.pleroma.social/sjw/pleroma.git synced 2024-12-27 13:15:32 +01:00

Merge branch 'bugfix/activitypub-totalitems-removal' into 'develop'

activitypub: user inbox/outbox: `totalItems` removal

See merge request pleroma/pleroma!827
This commit is contained in:
Haelwenn 2019-02-14 03:40:33 +00:00
commit 6652389e80
2 changed files with 36 additions and 14 deletions

View File

@ -105,7 +105,14 @@ defmodule Pleroma.Web.ActivityPub.UserView do
query = from(user in query, select: [:ap_id]) query = from(user in query, select: [:ap_id])
following = Repo.all(query) following = Repo.all(query)
collection(following, "#{user.ap_id}/following", page, !user.info.hide_follows) total =
if !user.info.hide_follows do
length(following)
else
0
end
collection(following, "#{user.ap_id}/following", page, !user.info.hide_follows, total)
|> Map.merge(Utils.make_json_ld_header()) |> Map.merge(Utils.make_json_ld_header())
end end
@ -114,10 +121,17 @@ defmodule Pleroma.Web.ActivityPub.UserView do
query = from(user in query, select: [:ap_id]) query = from(user in query, select: [:ap_id])
following = Repo.all(query) following = Repo.all(query)
total =
if !user.info.hide_follows do
length(following)
else
0
end
%{ %{
"id" => "#{user.ap_id}/following", "id" => "#{user.ap_id}/following",
"type" => "OrderedCollection", "type" => "OrderedCollection",
"totalItems" => length(following), "totalItems" => total,
"first" => collection(following, "#{user.ap_id}/following", 1, !user.info.hide_follows) "first" => collection(following, "#{user.ap_id}/following", 1, !user.info.hide_follows)
} }
|> Map.merge(Utils.make_json_ld_header()) |> Map.merge(Utils.make_json_ld_header())
@ -128,7 +142,14 @@ defmodule Pleroma.Web.ActivityPub.UserView do
query = from(user in query, select: [:ap_id]) query = from(user in query, select: [:ap_id])
followers = Repo.all(query) followers = Repo.all(query)
collection(followers, "#{user.ap_id}/followers", page, !user.info.hide_followers) total =
if !user.info.hide_followers do
length(followers)
else
0
end
collection(followers, "#{user.ap_id}/followers", page, !user.info.hide_followers, total)
|> Map.merge(Utils.make_json_ld_header()) |> Map.merge(Utils.make_json_ld_header())
end end
@ -137,19 +158,24 @@ defmodule Pleroma.Web.ActivityPub.UserView do
query = from(user in query, select: [:ap_id]) query = from(user in query, select: [:ap_id])
followers = Repo.all(query) followers = Repo.all(query)
total =
if !user.info.hide_followers do
length(followers)
else
0
end
%{ %{
"id" => "#{user.ap_id}/followers", "id" => "#{user.ap_id}/followers",
"type" => "OrderedCollection", "type" => "OrderedCollection",
"totalItems" => length(followers), "totalItems" => total,
"first" => collection(followers, "#{user.ap_id}/followers", 1, !user.info.hide_followers) "first" =>
collection(followers, "#{user.ap_id}/followers", 1, !user.info.hide_followers, total)
} }
|> Map.merge(Utils.make_json_ld_header()) |> Map.merge(Utils.make_json_ld_header())
end end
def render("outbox.json", %{user: user, max_id: max_qid}) do def render("outbox.json", %{user: user, max_id: max_qid}) do
# XXX: technically note_count is wrong for this, but it's better than nothing
info = User.user_info(user)
params = %{ params = %{
"limit" => "10" "limit" => "10"
} }
@ -177,7 +203,6 @@ defmodule Pleroma.Web.ActivityPub.UserView do
"id" => "#{iri}?max_id=#{max_id}", "id" => "#{iri}?max_id=#{max_id}",
"type" => "OrderedCollectionPage", "type" => "OrderedCollectionPage",
"partOf" => iri, "partOf" => iri,
"totalItems" => info.note_count,
"orderedItems" => collection, "orderedItems" => collection,
"next" => "#{iri}?max_id=#{min_id}" "next" => "#{iri}?max_id=#{min_id}"
} }
@ -186,7 +211,6 @@ defmodule Pleroma.Web.ActivityPub.UserView do
%{ %{
"id" => iri, "id" => iri,
"type" => "OrderedCollection", "type" => "OrderedCollection",
"totalItems" => info.note_count,
"first" => page "first" => page
} }
|> Map.merge(Utils.make_json_ld_header()) |> Map.merge(Utils.make_json_ld_header())
@ -224,7 +248,6 @@ defmodule Pleroma.Web.ActivityPub.UserView do
"id" => "#{iri}?max_id=#{max_id}", "id" => "#{iri}?max_id=#{max_id}",
"type" => "OrderedCollectionPage", "type" => "OrderedCollectionPage",
"partOf" => iri, "partOf" => iri,
"totalItems" => -1,
"orderedItems" => collection, "orderedItems" => collection,
"next" => "#{iri}?max_id=#{min_id}" "next" => "#{iri}?max_id=#{min_id}"
} }
@ -233,7 +256,6 @@ defmodule Pleroma.Web.ActivityPub.UserView do
%{ %{
"id" => iri, "id" => iri,
"type" => "OrderedCollection", "type" => "OrderedCollection",
"totalItems" => -1,
"first" => page "first" => page
} }
|> Map.merge(Utils.make_json_ld_header()) |> Map.merge(Utils.make_json_ld_header())

View File

@ -397,7 +397,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|> json_response(200) |> json_response(200)
assert result["first"]["orderedItems"] == [] assert result["first"]["orderedItems"] == []
assert result["totalItems"] == 1 assert result["totalItems"] == 0
end end
test "it works for more than 10 users", %{conn: conn} do test "it works for more than 10 users", %{conn: conn} do
@ -452,7 +452,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|> json_response(200) |> json_response(200)
assert result["first"]["orderedItems"] == [] assert result["first"]["orderedItems"] == []
assert result["totalItems"] == 1 assert result["totalItems"] == 0
end end
test "it works for more than 10 users", %{conn: conn} do test "it works for more than 10 users", %{conn: conn} do