- def find_first_acceptable_media_type(%{data: %{"attachment" => attachment}}) do
- Enum.find_value(attachment, fn attachment ->
- Enum.find_value(attachment["url"], fn url ->
- Enum.find(["image", "audio", "video"], fn media_type ->
- String.starts_with?(url["mediaType"], media_type)
+ defp build_attachments(%{data: %{"attachment" => attachments}}) do
+ Enum.reduce(attachments, [], fn attachment, acc ->
+ rendered_tags =
+ Enum.reduce(attachment["url"], [], fn url, acc ->
+ content_type = url["mediaType"]
+
+ media_type =
+ Enum.find(["image", "audio", "video"], fn media_type ->
+ String.starts_with?(url["mediaType"], media_type)
+ end)
+
+ # TODO: Add additional properties to objects when we have the data available.
+ case media_type do
+ "audio" ->
+ [
+ {:meta, [property: "twitter:card", content: "player"], []},
+ {:meta, [property: "twitter:player", content: Utils.attachment_url(url["href"])],
+ []}
+ | acc
+ ]
+
+ "image" ->
+ [
+ {:meta, [property: "twitter:card", content: "summary_large_image"], []},
+ {:meta,
+ [
+ property: "twitter:player",
+ content:
+ Utils.attachment_url(
+ Pleroma.Uploaders.Uploader.preview_url(content_type, url["href"])
+ )
+ ], []}
+ | acc
+ ]
+
+ # TODO: Need the true width and height values here or Twitter renders an iFrame with a bad aspect ratio
+ "video" ->
+ [
+ {:meta, [property: "twitter:card", content: "player"], []},
+ {:meta, [property: "twitter:player", content: Utils.attachment_url(url["href"])],
+ []},
+ {:meta, [property: "twitter:player:width", content: "1280"], []},
+ {:meta, [property: "twitter:player:height", content: "720"], []}
+ | acc
+ ]
+
+ _ ->
+ acc
+ end