Admin API: Render whole status in grouped reports
This commit is contained in:
parent
937d6c6b32
commit
2b341627da
|
@ -35,6 +35,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
||||||
- Mastodon API: `pleroma.thread_muted` to the Status entity
|
- Mastodon API: `pleroma.thread_muted` to the Status entity
|
||||||
- Mastodon API: Mark the direct conversation as read for the author when they send a new direct message
|
- Mastodon API: Mark the direct conversation as read for the author when they send a new direct message
|
||||||
- Mastodon API, streaming: Add `pleroma.direct_conversation_id` to the `conversation` stream event payload.
|
- Mastodon API, streaming: Add `pleroma.direct_conversation_id` to the `conversation` stream event payload.
|
||||||
|
- Admin API: Render whole status in grouped reports
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
|
@ -822,20 +822,33 @@ def parse_report_group(activity) do
|
||||||
reports = get_reports_by_status_id(activity["id"])
|
reports = get_reports_by_status_id(activity["id"])
|
||||||
max_date = Enum.max_by(reports, &NaiveDateTime.from_iso8601!(&1.data["published"]))
|
max_date = Enum.max_by(reports, &NaiveDateTime.from_iso8601!(&1.data["published"]))
|
||||||
actors = Enum.map(reports, & &1.user_actor)
|
actors = Enum.map(reports, & &1.user_actor)
|
||||||
|
{deleted, status} = get_status_data(activity)
|
||||||
|
|
||||||
%{
|
%{
|
||||||
date: max_date.data["published"],
|
date: max_date.data["published"],
|
||||||
account: activity["actor"],
|
account: activity["actor"],
|
||||||
status: %{
|
status: status,
|
||||||
id: activity["id"],
|
status_deleted: deleted,
|
||||||
content: activity["content"],
|
|
||||||
published: activity["published"]
|
|
||||||
},
|
|
||||||
actors: Enum.uniq(actors),
|
actors: Enum.uniq(actors),
|
||||||
reports: reports
|
reports: reports
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp get_status_data(activity) do
|
||||||
|
case Activity.get_by_ap_id(activity["id"]) do
|
||||||
|
%Activity{} = act ->
|
||||||
|
{false, act}
|
||||||
|
|
||||||
|
_ ->
|
||||||
|
{true,
|
||||||
|
%{
|
||||||
|
id: activity["id"],
|
||||||
|
content: activity["content"],
|
||||||
|
published: activity["published"]
|
||||||
|
}}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def get_reports_by_status_id(ap_id) do
|
def get_reports_by_status_id(ap_id) do
|
||||||
from(a in Activity,
|
from(a in Activity,
|
||||||
where: fragment("(?)->>'type' = 'Flag'", a.data),
|
where: fragment("(?)->>'type' = 'Flag'", a.data),
|
||||||
|
|
|
@ -45,10 +45,16 @@ def render("show.json", %{report: report, user: user, account: account, statuses
|
||||||
def render("index_grouped.json", %{groups: groups}) do
|
def render("index_grouped.json", %{groups: groups}) do
|
||||||
reports =
|
reports =
|
||||||
Enum.map(groups, fn group ->
|
Enum.map(groups, fn group ->
|
||||||
|
status =
|
||||||
|
if group[:status_deleted],
|
||||||
|
do: group[:status],
|
||||||
|
else: StatusView.render("show.json", %{activity: group[:status]})
|
||||||
|
|
||||||
%{
|
%{
|
||||||
date: group[:date],
|
date: group[:date],
|
||||||
account: group[:account],
|
account: group[:account],
|
||||||
status: group[:status],
|
status: status,
|
||||||
|
status_deleted: status_deleted,
|
||||||
actors: Enum.map(group[:actors], &merge_account_views/1),
|
actors: Enum.map(group[:actors], &merge_account_views/1),
|
||||||
reports:
|
reports:
|
||||||
group[:reports]
|
group[:reports]
|
||||||
|
|
|
@ -15,6 +15,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
||||||
alias Pleroma.UserInviteToken
|
alias Pleroma.UserInviteToken
|
||||||
alias Pleroma.Web.ActivityPub.Relay
|
alias Pleroma.Web.ActivityPub.Relay
|
||||||
alias Pleroma.Web.CommonAPI
|
alias Pleroma.Web.CommonAPI
|
||||||
|
alias Pleroma.Web.MastodonAPI.StatusView
|
||||||
alias Pleroma.Web.MediaProxy
|
alias Pleroma.Web.MediaProxy
|
||||||
import Pleroma.Factory
|
import Pleroma.Factory
|
||||||
|
|
||||||
|
@ -1616,14 +1617,11 @@ test "returns reports grouped by status", %{
|
||||||
|
|
||||||
assert length(response["reports"]) == 3
|
assert length(response["reports"]) == 3
|
||||||
|
|
||||||
first_group =
|
first_group = Enum.find(response["reports"], &(&1["status"]["id"] == first_status.id))
|
||||||
Enum.find(response["reports"], &(&1["status"]["id"] == first_status.data["id"]))
|
|
||||||
|
|
||||||
second_group =
|
second_group = Enum.find(response["reports"], &(&1["status"]["id"] == second_status.id))
|
||||||
Enum.find(response["reports"], &(&1["status"]["id"] == second_status.data["id"]))
|
|
||||||
|
|
||||||
third_group =
|
third_group = Enum.find(response["reports"], &(&1["status"]["id"] == third_status.id))
|
||||||
Enum.find(response["reports"], &(&1["status"]["id"] == third_status.data["id"]))
|
|
||||||
|
|
||||||
assert length(first_group["reports"]) == 3
|
assert length(first_group["reports"]) == 3
|
||||||
assert length(second_group["reports"]) == 2
|
assert length(second_group["reports"]) == 2
|
||||||
|
@ -1634,11 +1632,7 @@ test "returns reports grouped by status", %{
|
||||||
NaiveDateTime.from_iso8601!(act.data["published"])
|
NaiveDateTime.from_iso8601!(act.data["published"])
|
||||||
end).data["published"]
|
end).data["published"]
|
||||||
|
|
||||||
assert first_group["status"] == %{
|
assert first_group["status"] == StatusView.render("show.json", %{activity: first_status})
|
||||||
"id" => first_status.data["id"],
|
|
||||||
"content" => first_status.object.data["content"],
|
|
||||||
"published" => first_status.object.data["published"]
|
|
||||||
}
|
|
||||||
|
|
||||||
assert first_group["account"]["id"] == target_user.id
|
assert first_group["account"]["id"] == target_user.id
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue