Replace map with reduce to remove nils
This commit is contained in:
parent
ff01fd3c4f
commit
b44995866b
|
@ -50,23 +50,25 @@ def build_tags(%{user: user}) do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
defp build_attachments(activity) do
|
defp build_attachments(%{data: %{"object" => %{"attachment" => attachments}}} = _activity) do
|
||||||
Enum.reduce(activity.data["object"]["attachment"], [], fn attachment, acc ->
|
Enum.reduce(attachments, [], fn attachment, acc ->
|
||||||
rendered_tags =
|
rendered_tags =
|
||||||
Enum.map(attachment["url"], fn url ->
|
Enum.reduce(attachment["url"], [], fn url, acc ->
|
||||||
media_type =
|
media_type =
|
||||||
Enum.find(["image", "audio", "video"], fn media_type ->
|
Enum.find(["image", "audio", "video"], fn media_type ->
|
||||||
String.starts_with?(url["mediaType"], media_type)
|
String.starts_with?(url["mediaType"], media_type)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
if media_type do
|
if media_type do
|
||||||
|
[
|
||||||
{:meta, [property: "og:" <> media_type, content: attachment_url(url["href"])], []}
|
{:meta, [property: "og:" <> media_type, content: attachment_url(url["href"])], []}
|
||||||
|
| acc
|
||||||
|
]
|
||||||
else
|
else
|
||||||
nil
|
acc
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
Enum.reject(rendered_tags, &is_nil/1)
|
|
||||||
acc ++ rendered_tags
|
acc ++ rendered_tags
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue