1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4 defmodule Pleroma.Web.Metadata.Providers.TwitterCard do
5 alias Pleroma.Web.Metadata.Providers.Provider
10 def build_tags(%{activity: activity}) do
11 if Enum.any?(activity.data["object"]["tag"], fn tag -> tag == "nsfw" end) or
12 activity.data["object"]["attachment"] == [] do
15 case find_first_acceptable_media_type(activity) do
17 [{:meta, [property: "twitter:card", content: "summary_large_image"], []}]
20 [{:meta, [property: "twitter:card", content: "player"], []}]
23 [{:meta, [property: "twitter:card", content: "player"], []}]
33 [{:meta, [property: "twitter:card", content: "summary"], []}]
36 def find_first_acceptable_media_type(%{data: %{"object" => %{"attachment" => attachment}}}) do
37 Enum.find_value(attachment, fn attachment ->
38 Enum.find_value(attachment["url"], fn url ->
39 Enum.find(["image", "audio", "video"], fn media_type ->
40 String.starts_with?(url["mediaType"], media_type)