diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pleroma/web/metadata/utils.ex | 17 | ||||
-rw-r--r-- | lib/pleroma/web/push/impl.ex | 21 |
2 files changed, 17 insertions, 21 deletions
diff --git a/lib/pleroma/web/metadata/utils.ex b/lib/pleroma/web/metadata/utils.ex index 4c763a877..dd80c3277 100644 --- a/lib/pleroma/web/metadata/utils.ex +++ b/lib/pleroma/web/metadata/utils.ex @@ -13,12 +13,6 @@ defmodule Pleroma.Web.Metadata.Utils do def filter_html_and_truncate(content, max_length \\ nil), do: do_filter_html_and_truncate(content, max_length) - def scrub_html_and_truncate(%{data: %{"content" => content}} = _object), - do: do_scrub_html_and_truncate(content) - - def scrub_html_and_truncate(content, max_length \\ nil), - do: do_scrub_html_and_truncate(content, max_length) - def user_name_string(user) do "#{user.name} " <> if user.local do @@ -45,15 +39,4 @@ defmodule Pleroma.Web.Metadata.Utils do |> String.replace(~r/<br\s?\/?>/, " ") |> Formatter.truncate(max_length) end - - defp do_scrub_html_and_truncate(content, max_length \\ 200) when is_binary(content) do - # html content comes from DB already encoded - content - |> HtmlEntities.decode() - |> Emoji.Formatter.demojify() - |> String.replace(~r/<br\s?\/?>/, " ") - |> HTML.strip_tags() - |> HtmlEntities.decode() - |> Formatter.truncate(max_length) - end end diff --git a/lib/pleroma/web/push/impl.ex b/lib/pleroma/web/push/impl.ex index 83cbdc870..6d83df8ab 100644 --- a/lib/pleroma/web/push/impl.ex +++ b/lib/pleroma/web/push/impl.ex @@ -6,11 +6,13 @@ defmodule Pleroma.Web.Push.Impl do @moduledoc "The module represents implementation push web notification" alias Pleroma.Activity + alias Pleroma.Emoji + alias Pleroma.Formatter + alias Pleroma.HTML alias Pleroma.Notification alias Pleroma.Object alias Pleroma.Repo alias Pleroma.User - alias Pleroma.Web.Metadata.Utils alias Pleroma.Web.Push.Subscription require Logger @@ -127,7 +129,7 @@ defmodule Pleroma.Web.Push.Impl do def format_body(_activity, actor, %{data: %{"type" => "ChatMessage", "content" => content}}, _) do case content do nil -> "@#{actor.nickname}: (Attachment)" - content -> "@#{actor.nickname}: #{Utils.scrub_html_and_truncate(content, 80)}" + content -> "@#{actor.nickname}: #{filter_html_and_truncate(content, 80)}" end end @@ -137,7 +139,7 @@ defmodule Pleroma.Web.Push.Impl do %{data: %{"content" => content}}, _mastodon_type ) do - "@#{actor.nickname}: #{Utils.scrub_html_and_truncate(content, 80)}" + "@#{actor.nickname}: #{filter_html_and_truncate(content, 80)}" end def format_body( @@ -146,7 +148,7 @@ defmodule Pleroma.Web.Push.Impl do %{data: %{"content" => content}}, _mastodon_type ) do - "@#{actor.nickname} repeated: #{Utils.scrub_html_and_truncate(content, 80)}" + "@#{actor.nickname} repeated: #{filter_html_and_truncate(content, 80)}" end def format_body( @@ -192,4 +194,15 @@ defmodule Pleroma.Web.Push.Impl do type -> "New #{String.capitalize(type || "event")}" end end + + defp filter_html_and_truncate(content, max_length) when is_binary(content) do + # html content comes from DB already encoded + content + |> HtmlEntities.decode() + |> Emoji.Formatter.demojify() + |> HTML.filter_tags(Pleroma.HTML.Scrubber.BreaksOnly) + |> HtmlEntities.decode() + |> String.replace(~r/<br\s?\/?>/, "\r\n") + |> Formatter.truncate(max_length) + end end |