aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAlexander Strizhakov <alex.strizhakov@gmail.com>2021-01-21 18:51:21 +0300
committerAlexander Strizhakov <alex.strizhakov@gmail.com>2021-01-27 07:45:02 +0300
commit6806c03e8543c57ef85393eafdc6117d9776049f (patch)
treec6028508d82e59f70645df687bae411446e2fca8 /lib
parentd7af0294e6a3a690524e0a08a35c9c6dafbb9f79 (diff)
downloadpleroma-6806c03e8543c57ef85393eafdc6117d9776049f.tar.gz
added total
to the user statuses adminAPI endpoint
Diffstat (limited to 'lib')
-rw-r--r--lib/pleroma/web/activity_pub/activity_pub.ex17
-rw-r--r--lib/pleroma/web/admin_api/controllers/admin_api_controller.ex7
-rw-r--r--lib/pleroma/web/admin_api/views/status_view.ex4
3 files changed, 23 insertions, 5 deletions
diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex
index d0bb07aab..9ec106749 100644
--- a/lib/pleroma/web/activity_pub/activity_pub.ex
+++ b/lib/pleroma/web/activity_pub/activity_pub.ex
@@ -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,7 +630,6 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
}
|> user_activities_recipients()
|> fetch_activities(params, pagination_type)
- |> Enum.reverse()
end
def fetch_statuses(reading_user, params) do
diff --git a/lib/pleroma/web/admin_api/controllers/admin_api_controller.ex b/lib/pleroma/web/admin_api/controllers/admin_api_controller.ex
index 709c863ec..500556710 100644
--- a/lib/pleroma/web/admin_api/controllers/admin_api_controller.ex
+++ b/lib/pleroma/web/admin_api/controllers/admin_api_controller.ex
@@ -105,18 +105,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
diff --git a/lib/pleroma/web/admin_api/views/status_view.ex b/lib/pleroma/web/admin_api/views/status_view.ex
index 361fa5b0d..48d639b41 100644
--- a/lib/pleroma/web/admin_api/views/status_view.ex
+++ b/lib/pleroma/web/admin_api/views/status_view.ex
@@ -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