Merge branch 'features/ingestion-no-nil' into 'develop'
ObjectValidator.stringify_keys: filter out nil values See merge request pleroma/pleroma!3506
This commit is contained in:
commit
bc62a35282
|
@ -213,6 +213,7 @@ def stringify_keys(%{__struct__: _} = object) do
|
||||||
|
|
||||||
def stringify_keys(object) when is_map(object) do
|
def stringify_keys(object) when is_map(object) do
|
||||||
object
|
object
|
||||||
|
|> Enum.filter(fn {_, v} -> v != nil end)
|
||||||
|> Map.new(fn {key, val} -> {to_string(key), stringify_keys(val)} end)
|
|> Map.new(fn {key, val} -> {to_string(key), stringify_keys(val)} end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -124,8 +124,8 @@ def build_content(notification, actor, object, mastodon_type) do
|
||||||
|
|
||||||
def format_body(activity, actor, object, mastodon_type \\ nil)
|
def format_body(activity, actor, object, mastodon_type \\ nil)
|
||||||
|
|
||||||
def format_body(_activity, actor, %{data: %{"type" => "ChatMessage", "content" => content}}, _) do
|
def format_body(_activity, actor, %{data: %{"type" => "ChatMessage"} = data}, _) do
|
||||||
case content do
|
case data["content"] do
|
||||||
nil -> "@#{actor.nickname}: (Attachment)"
|
nil -> "@#{actor.nickname}: (Attachment)"
|
||||||
content -> "@#{actor.nickname}: #{Utils.scrub_html_and_truncate(content, 80)}"
|
content -> "@#{actor.nickname}: #{Utils.scrub_html_and_truncate(content, 80)}"
|
||||||
end
|
end
|
||||||
|
|
|
@ -68,7 +68,7 @@ test "let's through some basic html", %{user: user, recipient: recipient} do
|
||||||
test "validates for a basic object we build", %{valid_chat_message: valid_chat_message} do
|
test "validates for a basic object we build", %{valid_chat_message: valid_chat_message} do
|
||||||
assert {:ok, object, _meta} = ObjectValidator.validate(valid_chat_message, [])
|
assert {:ok, object, _meta} = ObjectValidator.validate(valid_chat_message, [])
|
||||||
|
|
||||||
assert Map.put(valid_chat_message, "attachment", nil) == object
|
assert valid_chat_message == object
|
||||||
assert match?(%{"firefox" => _}, object["emoji"])
|
assert match?(%{"firefox" => _}, object["emoji"])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -73,16 +73,12 @@ test "Funkwhale Audio object" do
|
||||||
%{
|
%{
|
||||||
"mediaType" => "audio/ogg",
|
"mediaType" => "audio/ogg",
|
||||||
"type" => "Link",
|
"type" => "Link",
|
||||||
"name" => nil,
|
|
||||||
"blurhash" => nil,
|
|
||||||
"url" => [
|
"url" => [
|
||||||
%{
|
%{
|
||||||
"href" =>
|
"href" =>
|
||||||
"https://channels.tests.funkwhale.audio/api/v1/listen/3901e5d8-0445-49d5-9711-e096cf32e515/?upload=42342395-0208-4fee-a38d-259a6dae0871&download=false",
|
"https://channels.tests.funkwhale.audio/api/v1/listen/3901e5d8-0445-49d5-9711-e096cf32e515/?upload=42342395-0208-4fee-a38d-259a6dae0871&download=false",
|
||||||
"mediaType" => "audio/ogg",
|
"mediaType" => "audio/ogg",
|
||||||
"type" => "Link",
|
"type" => "Link"
|
||||||
"width" => nil,
|
|
||||||
"height" => nil
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,16 +53,12 @@ test "it remaps video URLs as attachments if necessary" do
|
||||||
%{
|
%{
|
||||||
"type" => "Link",
|
"type" => "Link",
|
||||||
"mediaType" => "video/mp4",
|
"mediaType" => "video/mp4",
|
||||||
"name" => nil,
|
|
||||||
"blurhash" => nil,
|
|
||||||
"url" => [
|
"url" => [
|
||||||
%{
|
%{
|
||||||
"href" =>
|
"href" =>
|
||||||
"https://peertube.moe/static/webseed/df5f464b-be8d-46fb-ad81-2d4c2d1630e3-480.mp4",
|
"https://peertube.moe/static/webseed/df5f464b-be8d-46fb-ad81-2d4c2d1630e3-480.mp4",
|
||||||
"mediaType" => "video/mp4",
|
"mediaType" => "video/mp4",
|
||||||
"type" => "Link",
|
"type" => "Link"
|
||||||
"width" => nil,
|
|
||||||
"height" => nil
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -78,16 +74,12 @@ test "it remaps video URLs as attachments if necessary" do
|
||||||
%{
|
%{
|
||||||
"type" => "Link",
|
"type" => "Link",
|
||||||
"mediaType" => "video/mp4",
|
"mediaType" => "video/mp4",
|
||||||
"name" => nil,
|
|
||||||
"blurhash" => nil,
|
|
||||||
"url" => [
|
"url" => [
|
||||||
%{
|
%{
|
||||||
"href" =>
|
"href" =>
|
||||||
"https://framatube.org/static/webseed/6050732a-8a7a-43d4-a6cd-809525a1d206-1080.mp4",
|
"https://framatube.org/static/webseed/6050732a-8a7a-43d4-a6cd-809525a1d206-1080.mp4",
|
||||||
"mediaType" => "video/mp4",
|
"mediaType" => "video/mp4",
|
||||||
"type" => "Link",
|
"type" => "Link"
|
||||||
"width" => nil,
|
|
||||||
"height" => nil
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -110,16 +102,12 @@ test "it works for peertube videos with only their mpegURL map" do
|
||||||
%{
|
%{
|
||||||
"type" => "Link",
|
"type" => "Link",
|
||||||
"mediaType" => "video/mp4",
|
"mediaType" => "video/mp4",
|
||||||
"name" => nil,
|
|
||||||
"blurhash" => nil,
|
|
||||||
"url" => [
|
"url" => [
|
||||||
%{
|
%{
|
||||||
"href" =>
|
"href" =>
|
||||||
"https://peertube.stream/static/streaming-playlists/hls/abece3c3-b9c6-47f4-8040-f3eed8c602e6/abece3c3-b9c6-47f4-8040-f3eed8c602e6-1080-fragmented.mp4",
|
"https://peertube.stream/static/streaming-playlists/hls/abece3c3-b9c6-47f4-8040-f3eed8c602e6/abece3c3-b9c6-47f4-8040-f3eed8c602e6-1080-fragmented.mp4",
|
||||||
"mediaType" => "video/mp4",
|
"mediaType" => "video/mp4",
|
||||||
"type" => "Link",
|
"type" => "Link"
|
||||||
"width" => nil,
|
|
||||||
"height" => nil
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue