Prepare all types objects before serialising
Activities returned from inbox can include other types of objects like Article
This commit is contained in:
parent
19b6a82393
commit
1eb7318831
|
@ -641,7 +641,7 @@ def prepare_object(object) do
|
||||||
# internal -> Mastodon
|
# internal -> Mastodon
|
||||||
# """
|
# """
|
||||||
|
|
||||||
def prepare_outgoing(%{"type" => "Create", "object" => %{"type" => "Note"} = object} = data) do
|
def prepare_outgoing(%{"type" => "Create", "object" => object} = data) do
|
||||||
object =
|
object =
|
||||||
object
|
object
|
||||||
|> prepare_object
|
|> prepare_object
|
||||||
|
|
|
@ -57,6 +57,11 @@ def direct_note_factory do
|
||||||
%Pleroma.Object{data: Map.merge(data, %{"to" => [user2.ap_id]})}
|
%Pleroma.Object{data: Map.merge(data, %{"to" => [user2.ap_id]})}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def article_factory do
|
||||||
|
note_factory()
|
||||||
|
|> Map.put("type", "Article")
|
||||||
|
end
|
||||||
|
|
||||||
def tombstone_factory do
|
def tombstone_factory do
|
||||||
data = %{
|
data = %{
|
||||||
"type" => "Tombstone",
|
"type" => "Tombstone",
|
||||||
|
@ -110,6 +115,26 @@ def note_activity_factory do
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def article_activity_factory do
|
||||||
|
article = insert(:article)
|
||||||
|
|
||||||
|
data = %{
|
||||||
|
"id" => Pleroma.Web.ActivityPub.Utils.generate_activity_id(),
|
||||||
|
"type" => "Create",
|
||||||
|
"actor" => article.data["actor"],
|
||||||
|
"to" => article.data["to"],
|
||||||
|
"object" => article.data,
|
||||||
|
"published" => DateTime.utc_now() |> DateTime.to_iso8601(),
|
||||||
|
"context" => article.data["context"]
|
||||||
|
}
|
||||||
|
|
||||||
|
%Pleroma.Activity{
|
||||||
|
data: data,
|
||||||
|
actor: data["actor"],
|
||||||
|
recipients: data["to"]
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
def announce_activity_factory do
|
def announce_activity_factory do
|
||||||
note_activity = insert(:note_activity)
|
note_activity = insert(:note_activity)
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
|
|
|
@ -835,6 +835,21 @@ test "it strips internal fields" do
|
||||||
assert is_nil(modified["object"]["announcement_count"])
|
assert is_nil(modified["object"]["announcement_count"])
|
||||||
assert is_nil(modified["object"]["context_id"])
|
assert is_nil(modified["object"]["context_id"])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "it strips internal fields of article" do
|
||||||
|
activity = insert(:article_activity)
|
||||||
|
|
||||||
|
{:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
|
||||||
|
|
||||||
|
assert length(modified["object"]["tag"]) == 2
|
||||||
|
|
||||||
|
assert is_nil(modified["object"]["emoji"])
|
||||||
|
assert is_nil(modified["object"]["likes"])
|
||||||
|
assert is_nil(modified["object"]["like_count"])
|
||||||
|
assert is_nil(modified["object"]["announcements"])
|
||||||
|
assert is_nil(modified["object"]["announcement_count"])
|
||||||
|
assert is_nil(modified["object"]["context_id"])
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "user upgrade" do
|
describe "user upgrade" do
|
||||||
|
|
Loading…
Reference in a new issue