mirror of
https://akkoma.dev/AkkomaGang/akkoma.git
synced 2024-11-18 19:14:03 +00:00
Pipeline: Unify embedded_object / object_data, move to validator.
This commit is contained in:
parent
762c9ea564
commit
9e6f4694dd
|
@ -9,6 +9,7 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidator do
|
|||
the system.
|
||||
"""
|
||||
|
||||
alias Pleroma.Activity
|
||||
alias Pleroma.EctoType.ActivityPub.ObjectValidators
|
||||
alias Pleroma.Object
|
||||
alias Pleroma.User
|
||||
|
@ -71,6 +72,12 @@ def validate(%{"type" => "Undo"} = object, meta) do
|
|||
|> UndoValidator.cast_and_validate()
|
||||
|> Ecto.Changeset.apply_action(:insert) do
|
||||
object = stringify_keys(object)
|
||||
undone_object = Activity.get_by_ap_id(object["object"])
|
||||
|
||||
meta =
|
||||
meta
|
||||
|> Keyword.put(:object_data, undone_object.data)
|
||||
|
||||
{:ok, object, meta}
|
||||
end
|
||||
end
|
||||
|
|
|
@ -53,7 +53,7 @@ defp maybe_federate(%Activity{} = activity, meta) do
|
|||
|
||||
if !do_not_federate && local do
|
||||
activity =
|
||||
if object = Keyword.get(meta, :embedded_object) do
|
||||
if object = Keyword.get(meta, :object_data) do
|
||||
%{activity | data: Map.put(activity.data, "object", object)}
|
||||
else
|
||||
activity
|
||||
|
|
|
@ -174,10 +174,6 @@ def handle(%{data: %{"type" => "Announce"}} = object, meta) do
|
|||
def handle(%{data: %{"type" => "Undo", "object" => undone_object}} = object, meta) do
|
||||
with undone_object <- Activity.get_by_ap_id(undone_object),
|
||||
:ok <- handle_undoing(undone_object) do
|
||||
meta =
|
||||
meta
|
||||
|> Keyword.put(:embedded_object, undone_object.data)
|
||||
|
||||
{:ok, object, meta}
|
||||
end
|
||||
end
|
||||
|
|
|
@ -14,10 +14,10 @@ defmodule Pleroma.Web.ActivityPub.PipelineTest do
|
|||
:ok
|
||||
end
|
||||
|
||||
test "when given an `embedded_object` in meta, Federation will receive a the original activity with the `object` field set to this embedded object" do
|
||||
test "when given an `object_data` in meta, Federation will receive a the original activity with the `object` field set to this embedded object" do
|
||||
activity = insert(:note_activity)
|
||||
object = %{"id" => "1", "type" => "Love"}
|
||||
meta = [local: true, embedded_object: object]
|
||||
meta = [local: true, object_data: object]
|
||||
|
||||
activity_with_object = %{activity | data: Map.put(activity.data, "object", object)}
|
||||
|
||||
|
|
|
@ -312,13 +312,12 @@ test "when activation is required", %{delete: delete, user: user} do
|
|||
}
|
||||
end
|
||||
|
||||
test "deletes the original block, but sets `embedded_object`", %{
|
||||
test "deletes the original block", %{
|
||||
block_undo: block_undo,
|
||||
block: block
|
||||
} do
|
||||
{:ok, _block_undo, meta} = SideEffects.handle(block_undo)
|
||||
{:ok, _block_undo, _meta} = SideEffects.handle(block_undo)
|
||||
|
||||
assert meta[:embedded_object] == block.data
|
||||
refute Activity.get_by_id(block.id)
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue