+ defp build_attachments(%{data: %{"attachment" => attachments}}) do
+ Enum.reduce(attachments, [], fn attachment, acc ->
+ rendered_tags =
+ 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)
+
+ # TODO: Add additional properties to objects when we have the data available.
+ # Also, Whatsapp only wants JPEG or PNGs. It seems that if we add a second og:image
+ # object when a Video or GIF is attached it will display that in the Whatsapp Rich Preview.
+ case media_type do
+ "audio" ->
+ [
+ {:meta, [property: "og:" <> media_type, content: attachment_url(url["href"])], []}
+ | acc
+ ]
+
+ "image" ->
+ [
+ {:meta, [property: "og:" <> media_type, content: attachment_url(url["href"])],
+ []},
+ {:meta, [property: "og:image:width", content: 150], []},
+ {:meta, [property: "og:image:height", content: 150], []}
+ | acc
+ ]
+
+ "video" ->
+ [
+ {:meta, [property: "og:" <> media_type, content: attachment_url(url["href"])], []}
+ | acc
+ ]
+
+ _ ->
+ acc
+ end
+ end)
+
+ acc ++ rendered_tags
+ end)
+ end
+
+ defp scrub_html_and_truncate(%{data: %{"content" => content}} = object) do
+ content
+ # html content comes from DB already encoded, decode first and scrub after
+ |> HtmlEntities.decode()
+ |> String.replace(~r/<br\s?\/?>/, " ")
+ |> HTML.get_cached_stripped_html_for_object(object, __MODULE__)
+ |> Formatter.demojify()
+ |> Formatter.truncate()
+ end
+
+ defp scrub_html_and_truncate(content) when is_binary(content) do