Add status text to notifications (mentions and reposts)
This commit is contained in:
parent
dd5865535e
commit
cc7b35e097
7 changed files with 101 additions and 27 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue