Remove caching because it does not affect performance and may be even worse in some...
[akkoma] / lib / pleroma / web / metadata / opengraph.ex
index 1e3af947d6755d27b04f0bdd4bd53f5ce779d102..b158569748d5559da9833e10201d59728a35f63f 100644 (file)
@@ -7,7 +7,7 @@ defmodule Pleroma.Web.Metadata.Providers.OpenGraph do
 
   @impl Provider
   def build_tags(%{activity: activity, user: user}) do
-    with truncated_content = scrub_html_and_truncate(activity.data["object"]["content"]) do
+    with truncated_content = scrub_html_and_truncate(activity) do
       attachments = build_attachments(activity)
 
       [
@@ -71,7 +71,16 @@ defmodule Pleroma.Web.Metadata.Providers.OpenGraph do
     end)
   end
 
-  defp scrub_html_and_truncate(content) do
+  defp scrub_html_and_truncate(%{data: %{"object" => %{"content" => content}}} = activity) 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(activity, __MODULE__)
+    |> Formatter.truncate()
+  end
+
+  defp scrub_html_and_truncate(content) when is_binary(content) do
     content
     # html content comes from DB already encoded, decode first and scrub after
     |> HtmlEntities.decode()