Flag an Object, not an Activity

This commit is contained in:
tusooa 2022-11-19 23:51:43 -05:00
parent f40ccce7e9
commit a69e9ae2ef
No known key found for this signature in database
GPG Key ID: 7B467EDE43A08224
3 changed files with 15 additions and 12 deletions

View File

@ -695,8 +695,9 @@ defmodule Pleroma.Web.ActivityPub.Utils do
Enum.map(statuses || [], &build_flag_object/1) Enum.map(statuses || [], &build_flag_object/1)
end end
defp build_flag_object(%Activity{data: %{"id" => id}, object: %{data: data}}) do defp build_flag_object(%Object{data: data}) do
activity_actor = User.get_by_ap_id(data["actor"]) actor = User.get_by_ap_id(data["actor"])
id = data["id"]
%{ %{
"type" => "Note", "type" => "Note",
@ -706,7 +707,7 @@ defmodule Pleroma.Web.ActivityPub.Utils do
"actor" => "actor" =>
AccountView.render( AccountView.render(
"show.json", "show.json",
%{user: activity_actor, skip_visibility_check: true} %{user: actor, skip_visibility_check: true}
) )
} }
end end
@ -720,12 +721,12 @@ defmodule Pleroma.Web.ActivityPub.Utils do
end end
case Activity.get_by_ap_id_with_object(id) do case Activity.get_by_ap_id_with_object(id) do
%Activity{} = activity -> %Activity{object: object} = _ ->
build_flag_object(activity) build_flag_object(object)
nil -> nil ->
if activity = Activity.get_by_object_ap_id_with_object(id) do if %Object{} = object = Object.get_by_ap_id(id) do
build_flag_object(activity) build_flag_object(object)
else else
%{"id" => id, "deleted" => true} %{"id" => id, "deleted" => true}
end end

View File

@ -76,7 +76,7 @@ defmodule Pleroma.Web.AdminAPI.ReportControllerTest do
assert response["id"] == report_id assert response["id"] == report_id
assert [status] = response["statuses"] assert [status] = response["statuses"]
assert activity.data["id"] == status["uri"] assert activity.object.data["id"] == status["uri"]
assert activity.object.data["content"] == status["content"] assert activity.object.data["content"] == status["content"]
end end

View File

@ -1100,10 +1100,11 @@ defmodule Pleroma.Web.CommonAPITest do
target_user = insert(:user) target_user = insert(:user)
{:ok, activity} = CommonAPI.post(target_user, %{status: "foobar"}) {:ok, activity} = CommonAPI.post(target_user, %{status: "foobar"})
activity = Activity.normalize(activity)
reporter_ap_id = reporter.ap_id reporter_ap_id = reporter.ap_id
target_ap_id = target_user.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" comment = "foobar"
report_data = %{ report_data = %{
@ -1114,7 +1115,7 @@ defmodule Pleroma.Web.CommonAPITest do
note_obj = %{ note_obj = %{
"type" => "Note", "type" => "Note",
"id" => activity_ap_id, "id" => reported_object_ap_id,
"content" => "foobar", "content" => "foobar",
"published" => activity.object.data["published"], "published" => activity.object.data["published"],
"actor" => AccountView.render("show.json", %{user: target_user}) "actor" => AccountView.render("show.json", %{user: target_user})
@ -1136,6 +1137,7 @@ defmodule Pleroma.Web.CommonAPITest do
test "updates report state" do test "updates report state" do
[reporter, target_user] = insert_pair(:user) [reporter, target_user] = insert_pair(:user)
activity = insert(:note_activity, user: target_user) activity = insert(:note_activity, user: target_user)
object = Object.normalize(activity)
{:ok, %Activity{id: report_id}} = {:ok, %Activity{id: report_id}} =
CommonAPI.report(reporter, %{ CommonAPI.report(reporter, %{
@ -1148,10 +1150,10 @@ defmodule Pleroma.Web.CommonAPITest do
assert report.data["state"] == "resolved" 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 reported_user == target_user.ap_id
assert activity_id == activity.data["id"] assert object_id == object.data["id"]
end end
test "updates report state, don't strip when report_strip_status is false" do test "updates report state, don't strip when report_strip_status is false" do