diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pleroma/web/metadata/utils.ex | 4 | ||||
-rw-r--r-- | lib/pleroma/web/push/push.ex | 43 |
2 files changed, 36 insertions, 11 deletions
diff --git a/lib/pleroma/web/metadata/utils.ex b/lib/pleroma/web/metadata/utils.ex index a166800d4..5fc9c9e7b 100644 --- a/lib/pleroma/web/metadata/utils.ex +++ b/lib/pleroma/web/metadata/utils.ex @@ -17,14 +17,14 @@ defmodule Pleroma.Web.Metadata.Utils do |> Formatter.truncate() end - def scrub_html_and_truncate(content) when is_binary(content) do + def scrub_html_and_truncate(content, max_length \\ 200) when is_binary(content) do content # html content comes from DB already encoded, decode first and scrub after |> HtmlEntities.decode() |> String.replace(~r/<br\s?\/?>/, " ") |> HTML.strip_tags() |> Formatter.demojify() - |> Formatter.truncate() + |> Formatter.truncate(max_length) end def attachment_url(url) do diff --git a/lib/pleroma/web/push/push.ex b/lib/pleroma/web/push/push.ex index ddd4fe037..4979e0c0c 100644 --- a/lib/pleroma/web/push/push.ex +++ b/lib/pleroma/web/push/push.ex @@ -7,7 +7,10 @@ defmodule Pleroma.Web.Push do alias Pleroma.Repo alias Pleroma.User + alias Pleroma.Activity + alias Pleroma.Object alias Pleroma.Web.Push.Subscription + alias Pleroma.Web.Metadata.Utils require Logger import Ecto.Query @@ -119,6 +122,37 @@ defmodule Pleroma.Web.Push do {:noreply, state} end + # Pleroma.Repo.all(Pleroma.Object) + # Pleroma.Repo.all(Pleroma.Activity) + + def format_body( + %{activity: %{data: %{"type" => "Create", "object" => %{"content" => content}}}}, + actor + ) do + "@#{actor.nickname}: #{Utils.scrub_html_and_truncate(content, 80)}" + end + + def format_body( + %{activity: %{data: %{"type" => "Announce", "object" => activity_id}}}, + actor + ) do + %Activity{data: %{"object" => %{"id" => object_id}}} = Activity.get_by_ap_id(activity_id) + %Object{data: %{"content" => content}} = Object.get_by_ap_id(object_id) + + "@#{actor.nickname} repeated: #{Utils.scrub_html_and_truncate(content, 80)}" + end + + def format_body( + %{activity: %{data: %{"type" => type}}}, + actor + ) + when type in ["Follow", "Like"] do + case type do + "Follow" -> "@#{actor.nickname} has followed you" + "Like" -> "@#{actor.nickname} has favorited your post" + end + end + defp format_title(%{activity: %{data: %{"type" => type}}}) do case type do "Create" -> "New Mention" @@ -127,13 +161,4 @@ defmodule Pleroma.Web.Push do "Like" -> "New Favorite" end end - - defp format_body(%{activity: %{data: %{"type" => type}}}, actor) do - case type do - "Create" -> "@#{actor.nickname} has mentioned you" - "Follow" -> "@#{actor.nickname} has followed you" - "Announce" -> "@#{actor.nickname} has repeated your post" - "Like" -> "@#{actor.nickname} has favorited your post" - end - end end |