1 defmodule Pleroma.Web.Metadata.Providers.TwitterCard do
2 def build_tags(%{activity: activity}) do
3 if Enum.any?(activity.data["object"]["tag"], fn tag -> tag == "nsfw" end) or
4 activity.data["object"]["attachment"] == [] do
7 case find_first_acceptable_media_type(activity) do
9 [{:meta, [property: "twitter:card", content: "summary_large_image"], []}]
12 [{:meta, [property: "twitter:card", content: "player"], []}]
15 [{:meta, [property: "twitter:card", content: "player"], []}]
24 [{:meta, [property: "twitter:card", content: "summary"], []}]
27 def find_first_acceptable_media_type(%{data: %{"object" => %{"attachment" => attachment}}}) do
28 Enum.find_value(attachment, fn attachment ->
29 Enum.find_value(attachment["url"], fn url ->
30 Enum.find(["image", "audio", "video"], fn media_type ->
31 String.starts_with?(url["mediaType"], media_type)