- def find_first_acceptable_media_type(%{data: %{"object" => %{"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)
+ def image_tag(user) do
+ {:meta, [property: "twitter:image", content: Utils.attachment_url(User.avatar_url(user))], []}
+ end
+
+ defp build_attachments(id, %{data: %{"attachment" => attachments}}) do
+ Enum.reduce(attachments, [], fn attachment, acc ->
+ rendered_tags =
+ Enum.reduce(attachment["url"], [], fn url, acc ->
+ # TODO: Add additional properties to objects when we have the data available.
+ case Utils.fetch_media_type(@media_types, url["mediaType"]) do
+ "audio" ->
+ [
+ {:meta, [property: "twitter:card", content: "player"], []},
+ {:meta, [property: "twitter:player:width", content: "480"], []},
+ {:meta, [property: "twitter:player:height", content: "80"], []},
+ {:meta, [property: "twitter:player", content: player_url(id)], []}
+ | acc
+ ]
+
+ "image" ->
+ [
+ {:meta, [property: "twitter:card", content: "summary_large_image"], []},
+ {:meta,
+ [
+ property: "twitter:player",
+ content: Utils.attachment_url(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: player_url(id)], []},
+ {:meta, [property: "twitter:player:width", content: "480"], []},
+ {:meta, [property: "twitter:player:height", content: "480"], []}
+ | acc
+ ]
+
+ _ ->
+ acc
+ end