aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/pleroma/web/activity_pub/utils.ex25
-rw-r--r--lib/pleroma/web/metadata/utils.ex4
-rw-r--r--lib/pleroma/web/push/push.ex40
-rw-r--r--lib/pleroma/web/rich_media/helpers.ex14
4 files changed, 69 insertions, 14 deletions
diff --git a/lib/pleroma/web/activity_pub/utils.ex b/lib/pleroma/web/activity_pub/utils.ex
index 88f4779c8..9e50789db 100644
--- a/lib/pleroma/web/activity_pub/utils.ex
+++ b/lib/pleroma/web/activity_pub/utils.ex
@@ -7,6 +7,7 @@ defmodule Pleroma.Web.ActivityPub.Utils do
alias Pleroma.Web
alias Pleroma.Object
alias Pleroma.Activity
+ alias Pleroma.Web.ActivityPub.Visibility
alias Pleroma.User
alias Pleroma.Notification
alias Pleroma.Web.Router.Helpers
@@ -274,13 +275,31 @@ defmodule Pleroma.Web.ActivityPub.Utils do
Repo.all(query)
end
- def make_like_data(%User{ap_id: ap_id} = actor, %{data: %{"id" => id}} = object, activity_id) do
+ def make_like_data(
+ %User{ap_id: ap_id} = actor,
+ %{data: %{"actor" => object_actor_id, "id" => id}} = object,
+ activity_id
+ ) do
+ object_actor = User.get_cached_by_ap_id(object_actor_id)
+
+ to =
+ if Visibility.is_public?(object) do
+ [actor.follower_address, object.data["actor"]]
+ else
+ [object.data["actor"]]
+ end
+
+ cc =
+ (object.data["to"] ++ (object.data["cc"] || []))
+ |> List.delete(actor.ap_id)
+ |> List.delete(object_actor.follower_address)
+
data = %{
"type" => "Like",
"actor" => ap_id,
"object" => id,
- "to" => [actor.follower_address, object.data["actor"]],
- "cc" => ["https://www.w3.org/ns/activitystreams#Public"],
+ "to" => to,
+ "cc" => cc,
"context" => object.data["context"]
}
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
diff --git a/lib/pleroma/web/rich_media/helpers.ex b/lib/pleroma/web/rich_media/helpers.ex
index abb1cf7f2..8317a1162 100644
--- a/lib/pleroma/web/rich_media/helpers.ex
+++ b/lib/pleroma/web/rich_media/helpers.ex
@@ -8,10 +8,24 @@ defmodule Pleroma.Web.RichMedia.Helpers do
alias Pleroma.HTML
alias Pleroma.Web.RichMedia.Parser
+ defp validate_page_url(page_url) when is_binary(page_url) do
+ if AutoLinker.Parser.is_url?(page_url, true) do
+ URI.parse(page_url) |> validate_page_url
+ else
+ :error
+ end
+ end
+
+ defp validate_page_url(%URI{authority: nil}), do: :error
+ defp validate_page_url(%URI{scheme: nil}), do: :error
+ defp validate_page_url(%URI{}), do: :ok
+ defp validate_page_url(_), do: :error
+
def fetch_data_for_activity(%Activity{} = activity) do
with true <- Pleroma.Config.get([:rich_media, :enabled]),
%Object{} = object <- Object.normalize(activity.data["object"]),
{:ok, page_url} <- HTML.extract_first_external_url(object, object.data["content"]),
+ :ok <- validate_page_url(page_url),
{:ok, rich_media} <- Parser.parse(page_url) do
%{page_url: page_url, rich_media: rich_media}
else