Fix cannot get full history on object fetch
This commit is contained in:
parent
5ce118d970
commit
f84ed44cea
2 changed files with 91 additions and 2 deletions
|
@ -103,8 +103,8 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidator do
|
||||||
meta
|
meta
|
||||||
)
|
)
|
||||||
when objtype in ~w[Question Answer Audio Video Event Article Note Page] do
|
when objtype in ~w[Question Answer Audio Video Event Article Note Page] do
|
||||||
with {:ok, object_data} <- cast_and_apply(object),
|
with {:ok, object_data} <- cast_and_apply_and_stringify_with_history(object),
|
||||||
meta = Keyword.put(meta, :object_data, object_data |> stringify_keys),
|
meta = Keyword.put(meta, :object_data, object_data),
|
||||||
{:ok, create_activity} <-
|
{:ok, create_activity} <-
|
||||||
create_activity
|
create_activity
|
||||||
|> CreateGenericValidator.cast_and_validate(meta)
|
|> CreateGenericValidator.cast_and_validate(meta)
|
||||||
|
@ -212,6 +212,15 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidator do
|
||||||
|
|
||||||
def validate(o, m), do: {:error, {:validator_not_set, {o, m}}}
|
def validate(o, m), do: {:error, {:validator_not_set, {o, m}}}
|
||||||
|
|
||||||
|
def cast_and_apply_and_stringify_with_history(object) do
|
||||||
|
do_separate_with_history(object, fn object ->
|
||||||
|
with {:ok, object_data} <- cast_and_apply(object),
|
||||||
|
object_data <- object_data |> stringify_keys() do
|
||||||
|
{:ok, object_data}
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
def cast_and_apply(%{"type" => "ChatMessage"} = object) do
|
def cast_and_apply(%{"type" => "ChatMessage"} = object) do
|
||||||
ChatMessageValidator.cast_and_apply(object)
|
ChatMessageValidator.cast_and_apply(object)
|
||||||
end
|
end
|
||||||
|
|
|
@ -456,4 +456,84 @@ defmodule Pleroma.Object.FetcherTest do
|
||||||
} = refetched.data
|
} = refetched.data
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "fetch with history" do
|
||||||
|
setup do
|
||||||
|
object2 = %{
|
||||||
|
"id" => "https://mastodon.social/2",
|
||||||
|
"actor" => "https://mastodon.social/users/emelie",
|
||||||
|
"attributedTo" => "https://mastodon.social/users/emelie",
|
||||||
|
"type" => "Note",
|
||||||
|
"content" => "test 2",
|
||||||
|
"bcc" => [],
|
||||||
|
"bto" => [],
|
||||||
|
"cc" => ["https://mastodon.social/users/emelie/followers"],
|
||||||
|
"to" => [],
|
||||||
|
"summary" => "",
|
||||||
|
"formerRepresentations" => %{
|
||||||
|
"type" => "OrderedCollection",
|
||||||
|
"orderedItems" => [
|
||||||
|
%{
|
||||||
|
"type" => "Note",
|
||||||
|
"content" => "orig 2",
|
||||||
|
"actor" => "https://mastodon.social/users/emelie",
|
||||||
|
"attributedTo" => "https://mastodon.social/users/emelie",
|
||||||
|
"bcc" => [],
|
||||||
|
"bto" => [],
|
||||||
|
"cc" => ["https://mastodon.social/users/emelie/followers"],
|
||||||
|
"to" => [],
|
||||||
|
"summary" => ""
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"totalItems" => 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mock(fn
|
||||||
|
%{
|
||||||
|
method: :get,
|
||||||
|
url: "https://mastodon.social/2"
|
||||||
|
} ->
|
||||||
|
%Tesla.Env{
|
||||||
|
status: 200,
|
||||||
|
headers: [{"content-type", "application/activity+json"}],
|
||||||
|
body: Jason.encode!(object2)
|
||||||
|
}
|
||||||
|
|
||||||
|
%{
|
||||||
|
method: :get,
|
||||||
|
url: "https://mastodon.social/users/emelie/collections/featured"
|
||||||
|
} ->
|
||||||
|
%Tesla.Env{
|
||||||
|
status: 200,
|
||||||
|
headers: [{"content-type", "application/activity+json"}],
|
||||||
|
body:
|
||||||
|
Jason.encode!(%{
|
||||||
|
"id" => "https://mastodon.social/users/emelie/collections/featured",
|
||||||
|
"type" => "OrderedCollection",
|
||||||
|
"actor" => "https://mastodon.social/users/emelie",
|
||||||
|
"attributedTo" => "https://mastodon.social/users/emelie",
|
||||||
|
"orderedItems" => [],
|
||||||
|
"totalItems" => 0
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
env ->
|
||||||
|
apply(HttpRequestMock, :request, [env])
|
||||||
|
end)
|
||||||
|
|
||||||
|
%{object2: object2}
|
||||||
|
end
|
||||||
|
|
||||||
|
test "it gets history", %{object2: object2} do
|
||||||
|
{:ok, object} = Fetcher.fetch_object_from_id(object2["id"])
|
||||||
|
|
||||||
|
assert %{
|
||||||
|
"formerRepresentations" => %{
|
||||||
|
"type" => "OrderedCollection",
|
||||||
|
"orderedItems" => [%{}]
|
||||||
|
}
|
||||||
|
} = object.data
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue