aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMaxim Filippov <colixer@gmail.com>2019-11-22 13:35:21 +0900
committerMaxim Filippov <colixer@gmail.com>2019-11-26 00:20:46 +0900
commitb3b4e5ca805780f278b6239973d6d497b1697fbd (patch)
tree9101553a4a5075b031d7098472cf648425a96bd2 /lib
parent1364d303f8e4dcd4d9f7913d4755c58b0f4b87ef (diff)
downloadpleroma-b3b4e5ca805780f278b6239973d6d497b1697fbd.tar.gz
AdminAPI: Grouped reports old/new fix
If some status received reports both in the "new" format and "old" format it was considered reports on two different statuses (in the context of grouped reports)
Diffstat (limited to 'lib')
-rw-r--r--lib/pleroma/web/activity_pub/utils.ex78
1 files changed, 40 insertions, 38 deletions
diff --git a/lib/pleroma/web/activity_pub/utils.ex b/lib/pleroma/web/activity_pub/utils.ex
index 9e460b604..718e3328d 100644
--- a/lib/pleroma/web/activity_pub/utils.ex
+++ b/lib/pleroma/web/activity_pub/utils.ex
@@ -788,36 +788,6 @@ defmodule Pleroma.Web.ActivityPub.Utils do
ActivityPub.fetch_activities([], params, :offset)
end
- @spec get_reports_grouped_by_status(%{required(:activity) => String.t()}) :: %{
- required(:groups) => [
- %{
- required(:date) => String.t(),
- required(:account) => %{},
- required(:status) => %{},
- required(:actors) => [%User{}],
- required(:reports) => [%Activity{}]
- }
- ],
- required(:total) => integer
- }
- def get_reports_grouped_by_status(groups) do
- parsed_groups =
- groups
- |> Enum.map(fn entry ->
- activity =
- case Jason.decode(entry.activity) do
- {:ok, activity} -> activity
- _ -> build_flag_object(entry.activity)
- end
-
- parse_report_group(activity)
- end)
-
- %{
- groups: parsed_groups
- }
- end
-
def parse_report_group(activity) do
reports = get_reports_by_status_id(activity["id"])
max_date = Enum.max_by(reports, &NaiveDateTime.from_iso8601!(&1.data["published"]))
@@ -859,6 +829,32 @@ defmodule Pleroma.Web.ActivityPub.Utils do
|> Repo.all()
end
+ @spec get_reports_grouped_by_status(%{required(:activity) => String.t()}) :: %{
+ required(:groups) => [
+ %{
+ required(:date) => String.t(),
+ required(:account) => %{},
+ required(:status) => %{},
+ required(:actors) => [%User{}],
+ required(:reports) => [%Activity{}]
+ }
+ ],
+ required(:total) => integer
+ }
+ def get_reports_grouped_by_status(activity_ids) do
+ parsed_groups =
+ activity_ids
+ |> Enum.map(fn id ->
+ id
+ |> build_flag_object()
+ |> parse_report_group()
+ end)
+
+ %{
+ groups: parsed_groups
+ }
+ end
+
@spec get_reported_activities() :: [
%{
required(:activity) => String.t(),
@@ -866,17 +862,23 @@ defmodule Pleroma.Web.ActivityPub.Utils do
}
]
def get_reported_activities do
- from(a in Activity,
- where: fragment("(?)->>'type' = 'Flag'", a.data),
+ reported_activities_query =
+ from(a in Activity,
+ where: fragment("(?)->>'type' = 'Flag'", a.data),
+ select: %{
+ activity: fragment("jsonb_array_elements((? #- '{object,0}')->'object')", a.data)
+ },
+ group_by: fragment("activity")
+ )
+
+ from(a in subquery(reported_activities_query),
+ distinct: true,
select: %{
- date: fragment("max(?->>'published') date", a.data),
- activity:
- fragment("jsonb_array_elements_text((? #- '{object,0}')->'object') activity", a.data)
- },
- group_by: fragment("activity"),
- order_by: fragment("date DESC")
+ id: fragment("COALESCE(?->>'id'::text, ? #>> '{}')", a.activity, a.activity)
+ }
)
|> Repo.all()
+ |> Enum.map(& &1.id)
end
def update_report_state(%Activity{} = activity, state)