From b44995866ba49d2c9ea53082deadb6b72acf53e3 Mon Sep 17 00:00:00 2001 From: rinpatch Date: Wed, 16 Jan 2019 16:52:01 +0300 Subject: [PATCH] Replace map with reduce to remove nils --- lib/pleroma/web/metadata/opengraph.ex | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/pleroma/web/metadata/opengraph.ex b/lib/pleroma/web/metadata/opengraph.ex index b15856974..f6a1f3023 100644 --- a/lib/pleroma/web/metadata/opengraph.ex +++ b/lib/pleroma/web/metadata/opengraph.ex @@ -50,23 +50,25 @@ defmodule Pleroma.Web.Metadata.Providers.OpenGraph do end end - defp build_attachments(activity) do - Enum.reduce(activity.data["object"]["attachment"], [], fn attachment, acc -> + defp build_attachments(%{data: %{"object" => %{"attachment" => attachments}}} = _activity) do + Enum.reduce(attachments, [], fn attachment, acc -> rendered_tags = - Enum.map(attachment["url"], fn url -> + Enum.reduce(attachment["url"], [], fn url, acc -> media_type = Enum.find(["image", "audio", "video"], fn media_type -> String.starts_with?(url["mediaType"], media_type) end) 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 - nil + acc end end) - Enum.reject(rendered_tags, &is_nil/1) acc ++ rendered_tags end) end