Merge branch 'feature/2438-users-posts-total-count' into 'develop'
Feature/2438 users/instances posts total count Closes #2438 See merge request pleroma/pleroma!3270
This commit is contained in:
commit
8d2ea95402
6 changed files with 125 additions and 64 deletions
|
|
@ -591,7 +591,21 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
|
|||
|> Enum.reverse()
|
||||
end
|
||||
|
||||
def fetch_user_activities(user, reading_user, params \\ %{}) do
|
||||
def fetch_user_activities(user, reading_user, params \\ %{})
|
||||
|
||||
def fetch_user_activities(user, reading_user, %{total: true} = params) do
|
||||
result = fetch_activities_for_user(user, reading_user, params)
|
||||
|
||||
Keyword.put(result, :items, Enum.reverse(result[:items]))
|
||||
end
|
||||
|
||||
def fetch_user_activities(user, reading_user, params) do
|
||||
user
|
||||
|> fetch_activities_for_user(reading_user, params)
|
||||
|> Enum.reverse()
|
||||
end
|
||||
|
||||
defp fetch_activities_for_user(user, reading_user, params) do
|
||||
params =
|
||||
params
|
||||
|> Map.put(:type, ["Create", "Announce"])
|
||||
|
|
@ -616,10 +630,20 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
|
|||
}
|
||||
|> user_activities_recipients()
|
||||
|> fetch_activities(params, pagination_type)
|
||||
|> Enum.reverse()
|
||||
end
|
||||
|
||||
def fetch_statuses(reading_user, %{total: true} = params) do
|
||||
result = fetch_activities_for_reading_user(reading_user, params)
|
||||
Keyword.put(result, :items, Enum.reverse(result[:items]))
|
||||
end
|
||||
|
||||
def fetch_statuses(reading_user, params) do
|
||||
reading_user
|
||||
|> fetch_activities_for_reading_user(params)
|
||||
|> Enum.reverse()
|
||||
end
|
||||
|
||||
defp fetch_activities_for_reading_user(reading_user, params) do
|
||||
params = Map.put(params, :type, ["Create", "Announce"])
|
||||
|
||||
%{
|
||||
|
|
@ -628,7 +652,6 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
|
|||
}
|
||||
|> user_activities_recipients()
|
||||
|> fetch_activities(params, :offset)
|
||||
|> Enum.reverse()
|
||||
end
|
||||
|
||||
defp user_activities_recipients(%{godmode: true}), do: []
|
||||
|
|
|
|||
|
|
@ -85,17 +85,18 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do
|
|||
with_reblogs = params["with_reblogs"] == "true" || params["with_reblogs"] == true
|
||||
{page, page_size} = page_params(params)
|
||||
|
||||
activities =
|
||||
result =
|
||||
ActivityPub.fetch_statuses(nil, %{
|
||||
instance: instance,
|
||||
limit: page_size,
|
||||
offset: (page - 1) * page_size,
|
||||
exclude_reblogs: not with_reblogs
|
||||
exclude_reblogs: not with_reblogs,
|
||||
total: true
|
||||
})
|
||||
|
||||
conn
|
||||
|> put_view(AdminAPI.StatusView)
|
||||
|> render("index.json", %{activities: activities, as: :activity})
|
||||
|> render("index.json", %{total: result[:total], activities: result[:items], as: :activity})
|
||||
end
|
||||
|
||||
def list_user_statuses(%{assigns: %{user: admin}} = conn, %{"nickname" => nickname} = params) do
|
||||
|
|
@ -105,18 +106,19 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do
|
|||
with %User{} = user <- User.get_cached_by_nickname_or_id(nickname, for: admin) do
|
||||
{page, page_size} = page_params(params)
|
||||
|
||||
activities =
|
||||
result =
|
||||
ActivityPub.fetch_user_activities(user, nil, %{
|
||||
limit: page_size,
|
||||
offset: (page - 1) * page_size,
|
||||
godmode: godmode,
|
||||
exclude_reblogs: not with_reblogs,
|
||||
pagination_type: :offset
|
||||
pagination_type: :offset,
|
||||
total: true
|
||||
})
|
||||
|
||||
conn
|
||||
|> put_view(AdminAPI.StatusView)
|
||||
|> render("index.json", %{activities: activities, as: :activity})
|
||||
|> render("index.json", %{total: result[:total], activities: result[:items], as: :activity})
|
||||
else
|
||||
_ -> {:error, :not_found}
|
||||
end
|
||||
|
|
|
|||
|
|
@ -13,6 +13,10 @@ defmodule Pleroma.Web.AdminAPI.StatusView do
|
|||
|
||||
defdelegate merge_account_views(user), to: AdminAPI.AccountView
|
||||
|
||||
def render("index.json", %{total: total} = opts) do
|
||||
%{total: total, activities: safe_render_many(opts.activities, __MODULE__, "show.json", opts)}
|
||||
end
|
||||
|
||||
def render("index.json", opts) do
|
||||
safe_render_many(opts.activities, __MODULE__, "show.json", opts)
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue