Store status data inside Flag activity

This commit is contained in:
Maxim Filippov 2019-10-23 21:27:22 +02:00
parent 90d516d42b
commit b08b1d5d91
6 changed files with 62 additions and 33 deletions

View file

@ -12,6 +12,7 @@ defmodule Pleroma.Web.ActivityPub.Utils do
alias Pleroma.User alias Pleroma.User
alias Pleroma.Web alias Pleroma.Web
alias Pleroma.Web.ActivityPub.Visibility alias Pleroma.Web.ActivityPub.Visibility
alias Pleroma.Web.AdminAPI.AccountView
alias Pleroma.Web.Endpoint alias Pleroma.Web.Endpoint
alias Pleroma.Web.Router.Helpers alias Pleroma.Web.Router.Helpers
@ -608,34 +609,24 @@ defmodule Pleroma.Web.ActivityPub.Utils do
defp build_flag_object(%{account: account, statuses: statuses} = _) do defp build_flag_object(%{account: account, statuses: statuses} = _) do
[account.ap_id] ++ [account.ap_id] ++
Enum.map(statuses || [], fn Enum.map(statuses || [], fn act ->
%Activity{} = act -> id =
obj = Object.get_by_ap_id(act.data["object"]) 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)
"type" => "Note", actor = User.get_by_ap_id(activity.object.data["actor"])
"id" => act.data["id"],
"content" => obj.data["content"]
}
act when is_map(act) -> %{
obj = Object.get_by_ap_id(act["object"]) "type" => "Note",
"id" => activity.data["id"],
%{ "content" => activity.object.data["content"],
"type" => "Note", "published" => activity.object.data["published"],
"id" => act["id"], "actor" => AccountView.render("show.json", %{user: actor})
"content" => obj.data["content"] }
}
act
when is_binary(act) ->
activity = Activity.get_by_ap_id_with_object(act)
%{
"type" => "Note",
"id" => activity.data["id"],
"content" => activity.data["object"]["content"]
}
end) end)
end end

View file

@ -13,8 +13,8 @@ defmodule Pleroma.Web.AdminAPI.Report do
account = User.get_cached_by_ap_id(account_ap_id) account = User.get_cached_by_ap_id(account_ap_id)
statuses = statuses =
Enum.map(status_ap_ids, fn ap_id -> Enum.map(status_ap_ids, fn act ->
Activity.get_by_ap_id_with_object(ap_id) Activity.get_by_ap_id_with_object(act["id"])
end) end)
%{report: report, user: user, account: account, statuses: statuses} %{report: report, user: user, account: account, statuses: statuses}

View file

@ -10,6 +10,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
alias Pleroma.User alias Pleroma.User
alias Pleroma.Web.ActivityPub.ActivityPub alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.ActivityPub.Utils alias Pleroma.Web.ActivityPub.Utils
alias Pleroma.Web.AdminAPI.AccountView
alias Pleroma.Web.CommonAPI alias Pleroma.Web.CommonAPI
import Pleroma.Factory import Pleroma.Factory
@ -1265,6 +1266,8 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
target_ap_id = target_account.ap_id target_ap_id = target_account.ap_id
activity_ap_id = activity.data["id"] activity_ap_id = activity.data["id"]
activity_with_object = Activity.get_by_ap_id_with_object(activity_ap_id)
assert {:ok, activity} = assert {:ok, activity} =
ActivityPub.flag(%{ ActivityPub.flag(%{
actor: reporter, actor: reporter,
@ -1274,13 +1277,21 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
content: content content: content
}) })
note_obj = %{
"type" => "Note",
"id" => activity_ap_id,
"content" => content,
"published" => activity_with_object.object.data["published"],
"actor" => AccountView.render("show.json", %{user: target_account})
}
assert %Activity{ assert %Activity{
actor: ^reporter_ap_id, actor: ^reporter_ap_id,
data: %{ data: %{
"type" => "Flag", "type" => "Flag",
"content" => ^content, "content" => ^content,
"context" => ^context, "context" => ^context,
"object" => [^target_ap_id, ^activity_ap_id] "object" => [^target_ap_id, ^note_obj]
} }
} = activity } = activity
end end

View file

@ -12,6 +12,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
alias Pleroma.User alias Pleroma.User
alias Pleroma.Web.ActivityPub.ActivityPub alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.ActivityPub.Transmogrifier alias Pleroma.Web.ActivityPub.Transmogrifier
alias Pleroma.Web.AdminAPI.AccountView
alias Pleroma.Web.CommonAPI alias Pleroma.Web.CommonAPI
alias Pleroma.Web.OStatus alias Pleroma.Web.OStatus
alias Pleroma.Web.Websub.WebsubClientSubscription alias Pleroma.Web.Websub.WebsubClientSubscription
@ -1093,10 +1094,18 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
{:ok, activity} = CommonAPI.post(user, %{"status" => "test post"}) {:ok, activity} = CommonAPI.post(user, %{"status" => "test post"})
object = Object.normalize(activity) object = Object.normalize(activity)
note_obj = %{
"type" => "Note",
"id" => activity.data["id"],
"content" => "test post",
"published" => object.data["published"],
"actor" => AccountView.render("show.json", %{user: user})
}
message = %{ message = %{
"@context" => "https://www.w3.org/ns/activitystreams", "@context" => "https://www.w3.org/ns/activitystreams",
"cc" => [user.ap_id], "cc" => [user.ap_id],
"object" => [user.ap_id, object.data["id"]], "object" => [user.ap_id, activity],
"type" => "Flag", "type" => "Flag",
"content" => "blocked AND reported!!!", "content" => "blocked AND reported!!!",
"actor" => other_user.ap_id "actor" => other_user.ap_id
@ -1104,7 +1113,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
assert {:ok, activity} = Transmogrifier.handle_incoming(message) assert {:ok, activity} = Transmogrifier.handle_incoming(message)
assert activity.data["object"] == [user.ap_id, object.data["id"]] assert activity.data["object"] == [user.ap_id, note_obj]
assert activity.data["content"] == "blocked AND reported!!!" assert activity.data["content"] == "blocked AND reported!!!"
assert activity.data["actor"] == other_user.ap_id assert activity.data["actor"] == other_user.ap_id
assert activity.data["cc"] == [user.ap_id] assert activity.data["cc"] == [user.ap_id]

View file

@ -10,6 +10,7 @@ defmodule Pleroma.Web.ActivityPub.UtilsTest do
alias Pleroma.User alias Pleroma.User
alias Pleroma.Web.ActivityPub.ActivityPub alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.ActivityPub.Utils alias Pleroma.Web.ActivityPub.Utils
alias Pleroma.Web.AdminAPI.AccountView
alias Pleroma.Web.CommonAPI alias Pleroma.Web.CommonAPI
import Pleroma.Factory import Pleroma.Factory
@ -581,11 +582,19 @@ defmodule Pleroma.Web.ActivityPub.UtilsTest do
%{} %{}
) )
note_obj = %{
"type" => "Note",
"id" => activity_ap_id,
"content" => content,
"published" => activity.object.data["published"],
"actor" => AccountView.render("show.json", %{user: target_account})
}
assert %{ assert %{
"type" => "Flag", "type" => "Flag",
"content" => ^content, "content" => ^content,
"context" => ^context, "context" => ^context,
"object" => [^target_ap_id, ^activity_ap_id], "object" => [^target_ap_id, ^note_obj],
"state" => "open" "state" => "open"
} = res } = res
end end

View file

@ -10,6 +10,7 @@ defmodule Pleroma.Web.CommonAPITest do
alias Pleroma.User alias Pleroma.User
alias Pleroma.Web.ActivityPub.ActivityPub alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.ActivityPub.Visibility alias Pleroma.Web.ActivityPub.Visibility
alias Pleroma.Web.AdminAPI.AccountView
alias Pleroma.Web.CommonAPI alias Pleroma.Web.CommonAPI
import Pleroma.Factory import Pleroma.Factory
@ -385,6 +386,14 @@ defmodule Pleroma.Web.CommonAPITest do
"status_ids" => [activity.id] "status_ids" => [activity.id]
} }
note_obj = %{
"type" => "Note",
"id" => activity_ap_id,
"content" => "foobar",
"published" => activity.object.data["published"],
"actor" => AccountView.render("show.json", %{user: target_user})
}
assert {:ok, flag_activity} = CommonAPI.report(reporter, report_data) assert {:ok, flag_activity} = CommonAPI.report(reporter, report_data)
assert %Activity{ assert %Activity{
@ -392,7 +401,7 @@ defmodule Pleroma.Web.CommonAPITest do
data: %{ data: %{
"type" => "Flag", "type" => "Flag",
"content" => ^comment, "content" => ^comment,
"object" => [^target_ap_id, ^activity_ap_id], "object" => [^target_ap_id, ^note_obj],
"state" => "open" "state" => "open"
} }
} = flag_activity } = flag_activity