diff options
author | kaniini <nenolod@gmail.com> | 2019-03-04 18:29:13 +0000 |
---|---|---|
committer | kaniini <nenolod@gmail.com> | 2019-03-04 18:29:13 +0000 |
commit | d45dbdce5a478a004711baad963d7134988402ed (patch) | |
tree | 6dfcc121950f9513ae82bfc147c6dbc1b3b069a6 /lib | |
parent | ca5d894e6811e0020facabdaa12d2fd263b497c5 (diff) | |
parent | 0245ce842fad4dd53f3c6f6e4a146fc857e8eb1d (diff) | |
download | pleroma-d45dbdce5a478a004711baad963d7134988402ed.tar.gz |
Merge branch 'feature/add-status-text-to-notifications' into 'develop'
Add status text to notifications (mentions and reposts)
Closes #696
See merge request pleroma/pleroma!897
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pleroma/web/metadata/utils.ex | 4 | ||||
-rw-r--r-- | lib/pleroma/web/push/push.ex | 40 |
2 files changed, 33 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..92f8f9ab4 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,34 @@ defmodule Pleroma.Web.Push do {:noreply, state} end + 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 +158,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 |