From a69e9ae2ef943f57faf803441c25aee09a86f9ca Mon Sep 17 00:00:00 2001 From: tusooa Date: Sat, 19 Nov 2022 23:51:43 -0500 Subject: [PATCH] Flag an Object, not an Activity --- lib/pleroma/web/activity_pub/utils.ex | 15 ++++++++------- .../controllers/report_controller_test.exs | 2 +- test/pleroma/web/common_api_test.exs | 10 ++++++---- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/lib/pleroma/web/activity_pub/utils.ex b/lib/pleroma/web/activity_pub/utils.ex index 57a2f53c4..dacacb83b 100644 --- a/lib/pleroma/web/activity_pub/utils.ex +++ b/lib/pleroma/web/activity_pub/utils.ex @@ -695,8 +695,9 @@ defmodule Pleroma.Web.ActivityPub.Utils do Enum.map(statuses || [], &build_flag_object/1) end - defp build_flag_object(%Activity{data: %{"id" => id}, object: %{data: data}}) do - activity_actor = User.get_by_ap_id(data["actor"]) + defp build_flag_object(%Object{data: data}) do + actor = User.get_by_ap_id(data["actor"]) + id = data["id"] %{ "type" => "Note", @@ -706,7 +707,7 @@ defmodule Pleroma.Web.ActivityPub.Utils do "actor" => AccountView.render( "show.json", - %{user: activity_actor, skip_visibility_check: true} + %{user: actor, skip_visibility_check: true} ) } end @@ -720,12 +721,12 @@ defmodule Pleroma.Web.ActivityPub.Utils do end case Activity.get_by_ap_id_with_object(id) do - %Activity{} = activity -> - build_flag_object(activity) + %Activity{object: object} = _ -> + build_flag_object(object) nil -> - if activity = Activity.get_by_object_ap_id_with_object(id) do - build_flag_object(activity) + if %Object{} = object = Object.get_by_ap_id(id) do + build_flag_object(object) else %{"id" => id, "deleted" => true} end diff --git a/test/pleroma/web/admin_api/controllers/report_controller_test.exs b/test/pleroma/web/admin_api/controllers/report_controller_test.exs index 164cbb95b..6fd3fbe5a 100644 --- a/test/pleroma/web/admin_api/controllers/report_controller_test.exs +++ b/test/pleroma/web/admin_api/controllers/report_controller_test.exs @@ -76,7 +76,7 @@ defmodule Pleroma.Web.AdminAPI.ReportControllerTest do assert response["id"] == report_id assert [status] = response["statuses"] - assert activity.data["id"] == status["uri"] + assert activity.object.data["id"] == status["uri"] assert activity.object.data["content"] == status["content"] end diff --git a/test/pleroma/web/common_api_test.exs b/test/pleroma/web/common_api_test.exs index 4dc0d9cbe..9d52bd93e 100644 --- a/test/pleroma/web/common_api_test.exs +++ b/test/pleroma/web/common_api_test.exs @@ -1100,10 +1100,11 @@ defmodule Pleroma.Web.CommonAPITest do target_user = insert(:user) {:ok, activity} = CommonAPI.post(target_user, %{status: "foobar"}) + activity = Activity.normalize(activity) reporter_ap_id = reporter.ap_id target_ap_id = target_user.ap_id - activity_ap_id = activity.data["id"] + reported_object_ap_id = activity.object.data["id"] comment = "foobar" report_data = %{ @@ -1114,7 +1115,7 @@ defmodule Pleroma.Web.CommonAPITest do note_obj = %{ "type" => "Note", - "id" => activity_ap_id, + "id" => reported_object_ap_id, "content" => "foobar", "published" => activity.object.data["published"], "actor" => AccountView.render("show.json", %{user: target_user}) @@ -1136,6 +1137,7 @@ defmodule Pleroma.Web.CommonAPITest do test "updates report state" do [reporter, target_user] = insert_pair(:user) activity = insert(:note_activity, user: target_user) + object = Object.normalize(activity) {:ok, %Activity{id: report_id}} = CommonAPI.report(reporter, %{ @@ -1148,10 +1150,10 @@ defmodule Pleroma.Web.CommonAPITest do assert report.data["state"] == "resolved" - [reported_user, activity_id] = report.data["object"] + [reported_user, object_id] = report.data["object"] assert reported_user == target_user.ap_id - assert activity_id == activity.data["id"] + assert object_id == object.data["id"] end test "updates report state, don't strip when report_strip_status is false" do