aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMaxim Filippov <colixer@gmail.com>2019-11-07 22:45:36 +1000
committerMaxim Filippov <colixer@gmail.com>2019-11-08 18:21:29 +0900
commit7258db023e88d5aee5eac06525c42dcb073abd46 (patch)
tree6fb9034a486557e483b05985360eb158a9574c29 /lib
parentf171095960d172d54015b28e8da302b5745dca86 (diff)
downloadpleroma-7258db023e88d5aee5eac06525c42dcb073abd46.tar.gz
Support old flag format
Diffstat (limited to 'lib')
-rw-r--r--lib/pleroma/web/activity_pub/utils.ex94
-rw-r--r--lib/pleroma/web/admin_api/admin_api_controller.ex4
2 files changed, 57 insertions, 41 deletions
diff --git a/lib/pleroma/web/activity_pub/utils.ex b/lib/pleroma/web/activity_pub/utils.ex
index 5a51b7884..5e7f76bb6 100644
--- a/lib/pleroma/web/activity_pub/utils.ex
+++ b/lib/pleroma/web/activity_pub/utils.ex
@@ -616,26 +616,31 @@ defmodule Pleroma.Web.ActivityPub.Utils do
def make_flag_data(_, _), do: %{}
defp build_flag_object(%{account: account, statuses: statuses} = _) do
- [account.ap_id] ++
- Enum.map(statuses || [], fn act ->
- id =
- case act do
- %Activity{} = act -> act.data["id"]
- act when is_map(act) -> act["id"]
- act when is_binary(act) -> act
- end
+ [account.ap_id] ++ build_flag_object(%{statuses: statuses})
+ end
- activity = Activity.get_by_ap_id_with_object(id)
- actor = User.get_by_ap_id(activity.object.data["actor"])
+ defp build_flag_object(%{statuses: statuses}) do
+ Enum.map(statuses || [], &build_flag_object/1)
+ end
- %{
- "type" => "Note",
- "id" => activity.data["id"],
- "content" => activity.object.data["content"],
- "published" => activity.object.data["published"],
- "actor" => AccountView.render("show.json", %{user: actor})
- }
- end)
+ defp build_flag_object(act) when is_map(act) or is_binary(act) do
+ id =
+ case act do
+ %Activity{} = act -> act.data["id"]
+ act when is_map(act) -> act["id"]
+ act when is_binary(act) -> act
+ end
+
+ activity = Activity.get_by_ap_id_with_object(id)
+ actor = User.get_by_ap_id(activity.object.data["actor"])
+
+ %{
+ "type" => "Note",
+ "id" => activity.data["id"],
+ "content" => activity.object.data["content"],
+ "published" => activity.object.data["published"],
+ "actor" => AccountView.render("show.json", %{user: actor})
+ }
end
defp build_flag_object(_), do: []
@@ -692,7 +697,7 @@ defmodule Pleroma.Web.ActivityPub.Utils do
ActivityPub.fetch_activities([], params, :offset)
end
- @spec get_reports_grouped_by_status() :: %{
+ @spec get_reports_grouped_by_status(%{required(:activity) => String.t()}) :: %{
required(:groups) => [
%{
required(:date) => String.t(),
@@ -704,30 +709,39 @@ defmodule Pleroma.Web.ActivityPub.Utils do
],
required(:total) => integer
}
- def get_reports_grouped_by_status do
- groups =
- get_reported_status_ids()
+ def get_reports_grouped_by_status(groups) do
+ parsed_groups =
+ groups
|> Enum.map(fn entry ->
- activity = Jason.decode!(entry.activity)
- reports = get_reports_by_status_id(activity["id"])
- max_date = Enum.max_by(reports, &NaiveDateTime.from_iso8601!(&1.data["published"]))
- actors = Enum.map(reports, & &1.user_actor)
+ activity =
+ case Jason.decode(entry.activity) do
+ {:ok, activity} -> activity
+ _ -> build_flag_object(entry.activity)
+ end
- %{
- date: max_date.data["published"],
- account: activity["actor"],
- status: %{
- id: activity["id"],
- content: activity["content"],
- published: activity["published"]
- },
- actors: Enum.uniq(actors),
- reports: reports
- }
+ parse_report_group(activity)
end)
%{
- groups: groups
+ 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"]))
+ actors = Enum.map(reports, & &1.user_actor)
+
+ %{
+ date: max_date.data["published"],
+ account: activity["actor"],
+ status: %{
+ id: activity["id"],
+ content: activity["content"],
+ published: activity["published"]
+ },
+ actors: Enum.uniq(actors),
+ reports: reports
}
end
@@ -740,13 +754,13 @@ defmodule Pleroma.Web.ActivityPub.Utils do
|> Repo.all()
end
- @spec get_reported_status_ids() :: [
+ @spec get_reported_activities() :: [
%{
required(:activity) => String.t(),
required(:date) => String.t()
}
]
- def get_reported_status_ids do
+ def get_reported_activities do
from(a in Activity,
where: fragment("(?)->>'type' = 'Flag'", a.data),
select: %{
diff --git a/lib/pleroma/web/admin_api/admin_api_controller.ex b/lib/pleroma/web/admin_api/admin_api_controller.ex
index 1f48ce8c1..7d5ff7629 100644
--- a/lib/pleroma/web/admin_api/admin_api_controller.ex
+++ b/lib/pleroma/web/admin_api/admin_api_controller.ex
@@ -625,9 +625,11 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do
end
def list_grouped_reports(conn, _params) do
+ reports = Utils.get_reported_activities()
+
conn
|> put_view(ReportView)
- |> render("index_grouped.json", Utils.get_reports_grouped_by_status())
+ |> render("index_grouped.json", Utils.get_reports_grouped_by_status(reports))
end
def report_show(conn, %{"id" => id}) do