forked from AkkomaGang/akkoma
Merge branch 'hide-followers-count' into 'develop'
Hide follower counter when hiding is activated Closes #1450 See merge request pleroma/pleroma!2072
This commit is contained in:
commit
38ad407395
2 changed files with 8 additions and 2 deletions
|
@ -201,7 +201,6 @@ def render("followers.json", %{user: user} = opts) do
|
||||||
%{
|
%{
|
||||||
"id" => "#{user.ap_id}/followers",
|
"id" => "#{user.ap_id}/followers",
|
||||||
"type" => "OrderedCollection",
|
"type" => "OrderedCollection",
|
||||||
"totalItems" => total,
|
|
||||||
"first" =>
|
"first" =>
|
||||||
if showing_items do
|
if showing_items do
|
||||||
collection(followers, "#{user.ap_id}/followers", 1, showing_items, total)
|
collection(followers, "#{user.ap_id}/followers", 1, showing_items, total)
|
||||||
|
@ -209,6 +208,7 @@ def render("followers.json", %{user: user} = opts) do
|
||||||
"#{user.ap_id}/followers?page=1"
|
"#{user.ap_id}/followers?page=1"
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
|
|> maybe_put_total_items(showing_count, total)
|
||||||
|> Map.merge(Utils.make_json_ld_header())
|
|> Map.merge(Utils.make_json_ld_header())
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -251,6 +251,12 @@ def render("activity_collection_page.json", %{activities: activities, iri: iri})
|
||||||
|> Map.merge(Utils.make_json_ld_header())
|
|> Map.merge(Utils.make_json_ld_header())
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp maybe_put_total_items(map, false, _total), do: map
|
||||||
|
|
||||||
|
defp maybe_put_total_items(map, true, total) do
|
||||||
|
Map.put(map, "totalItems", total)
|
||||||
|
end
|
||||||
|
|
||||||
def collection(collection, iri, page, show_items \\ true, total \\ nil) do
|
def collection(collection, iri, page, show_items \\ true, total \\ nil) do
|
||||||
offset = (page - 1) * 10
|
offset = (page - 1) * 10
|
||||||
items = Enum.slice(collection, offset, 10)
|
items = Enum.slice(collection, offset, 10)
|
||||||
|
|
|
@ -126,7 +126,7 @@ test "sets totalItems to zero when followers are hidden" do
|
||||||
{:ok, _other_user, user, _activity} = CommonAPI.follow(other_user, user)
|
{:ok, _other_user, user, _activity} = CommonAPI.follow(other_user, user)
|
||||||
assert %{"totalItems" => 1} = UserView.render("followers.json", %{user: user})
|
assert %{"totalItems" => 1} = UserView.render("followers.json", %{user: user})
|
||||||
user = Map.merge(user, %{hide_followers_count: true, hide_followers: true})
|
user = Map.merge(user, %{hide_followers_count: true, hide_followers: true})
|
||||||
assert %{"totalItems" => 0} = UserView.render("followers.json", %{user: user})
|
refute UserView.render("followers.json", %{user: user}) |> Map.has_key?("totalItems")
|
||||||
end
|
end
|
||||||
|
|
||||||
test "sets correct totalItems when followers are hidden but the follower counter is not" do
|
test "sets correct totalItems when followers are hidden but the follower counter is not" do
|
||||||
|
|
Loading…
Reference in a new issue