From 18b536c176d3b51f3a91f42ba5a001711ab85490 Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Mon, 28 Dec 2020 10:33:28 +0100 Subject: [PATCH] Pleroma.Object/1: take %Object{} as argument instead --- lib/pleroma/activity/ir/topics.ex | 12 +++--------- lib/pleroma/object.ex | 4 ++-- lib/pleroma/web/activity_pub/mrf/simple_policy.ex | 2 +- lib/pleroma/web/activity_pub/transmogrifier.ex | 2 +- lib/pleroma/web/feed/feed_view.ex | 1 + lib/pleroma/web/mastodon_api/views/status_view.ex | 2 +- .../web/templates/feed/feed/_activity.atom.eex | 2 +- .../web/templates/feed/feed/_activity.rss.eex | 2 +- .../web/templates/feed/feed/_tag_activity.atom.eex | 2 +- 9 files changed, 12 insertions(+), 17 deletions(-) diff --git a/lib/pleroma/activity/ir/topics.ex b/lib/pleroma/activity/ir/topics.ex index 2cdecf1e4..b7553c728 100644 --- a/lib/pleroma/activity/ir/topics.ex +++ b/lib/pleroma/activity/ir/topics.ex @@ -48,18 +48,12 @@ defp item_creation_tags(tags, _, _) do tags end - defp hashtags_to_topics(%{data: %{"hashtags" => tags}}) do - Enum.map(tags, fn tag -> "hashtag:" <> tag end) - end - - defp hashtags_to_topics(%{data: %{"tag" => tags}}) do - tags - |> Enum.filter(&is_bitstring(&1)) + defp hashtags_to_topics(object) do + object + |> Object.hashtags() |> Enum.map(fn tag -> "hashtag:" <> tag end) end - defp hashtags_to_topics(_), do: [] - defp remote_topics(%{local: true}), do: [] defp remote_topics(%{actor: actor}) when is_binary(actor), diff --git a/lib/pleroma/object.ex b/lib/pleroma/object.ex index 00d561d1b..9cbc1c6a6 100644 --- a/lib/pleroma/object.ex +++ b/lib/pleroma/object.ex @@ -345,7 +345,7 @@ def replies(object, opts \\ []) do def self_replies(object, opts \\ []), do: replies(object, Keyword.put(opts, :self_only, true)) - def hashtags(%{"hashtags" => hashtags}), do: hashtags || [] - def hashtags(%{"tag" => tags}), do: Enum.filter(tags, &is_bitstring(&1)) + def hashtags(%Object{data: %{"hashtags" => hashtags}}), do: hashtags || [] + def hashtags(%Object{data: %{"tag" => tags}}), do: Enum.filter(tags, &is_bitstring(&1)) def hashtags(_), do: [] end diff --git a/lib/pleroma/web/activity_pub/mrf/simple_policy.ex b/lib/pleroma/web/activity_pub/mrf/simple_policy.ex index 8e0514dc8..94933ce99 100644 --- a/lib/pleroma/web/activity_pub/mrf/simple_policy.ex +++ b/lib/pleroma/web/activity_pub/mrf/simple_policy.ex @@ -77,7 +77,7 @@ defp check_media_nsfw( if MRF.subdomain_match?(media_nsfw, actor_host) do child_object = child_object - |> Map.put("hashtags", Object.hashtags(child_object) ++ ["nsfw"]) + |> Map.put("hashtags", Object.hashtags(%Object{data: child_object}) ++ ["nsfw"]) |> Map.put("sensitive", true) Map.put(object, "object", child_object) diff --git a/lib/pleroma/web/activity_pub/transmogrifier.ex b/lib/pleroma/web/activity_pub/transmogrifier.ex index 36ef6a454..109f03641 100644 --- a/lib/pleroma/web/activity_pub/transmogrifier.ex +++ b/lib/pleroma/web/activity_pub/transmogrifier.ex @@ -864,7 +864,7 @@ def maybe_fix_object_url(data), do: data def add_hashtags(object) do hashtags = - object + %Object{data: object} |> Object.hashtags() |> Enum.map(fn tag -> %{ diff --git a/lib/pleroma/web/feed/feed_view.ex b/lib/pleroma/web/feed/feed_view.ex index 30e0a2a55..1155c6a39 100644 --- a/lib/pleroma/web/feed/feed_view.ex +++ b/lib/pleroma/web/feed/feed_view.ex @@ -32,6 +32,7 @@ def prepare_activity(activity, opts \\ []) do %{ activity: activity, + object: object, data: Map.get(object, :data), actor: actor } diff --git a/lib/pleroma/web/mastodon_api/views/status_view.ex b/lib/pleroma/web/mastodon_api/views/status_view.ex index b39f05d13..3ba453d1f 100644 --- a/lib/pleroma/web/mastodon_api/views/status_view.ex +++ b/lib/pleroma/web/mastodon_api/views/status_view.ex @@ -347,7 +347,7 @@ def render("show.json", %{activity: %{data: %{"object" => _object}} = activity} media_attachments: attachments, poll: render(PollView, "show.json", object: object, for: opts[:for]), mentions: mentions, - tags: build_tags(Object.hashtags(object.data)), + tags: build_tags(Object.hashtags(object)), application: %{ name: "Web", website: nil diff --git a/lib/pleroma/web/templates/feed/feed/_activity.atom.eex b/lib/pleroma/web/templates/feed/feed/_activity.atom.eex index cb18abb5d..4a1a3e993 100644 --- a/lib/pleroma/web/templates/feed/feed/_activity.atom.eex +++ b/lib/pleroma/web/templates/feed/feed/_activity.atom.eex @@ -22,7 +22,7 @@ <% end %> - <%= for hashtag <- Object.hashtags(@data) do %> + <%= for hashtag <- Object.hashtags(@object) do %> <% end %> diff --git a/lib/pleroma/web/templates/feed/feed/_activity.rss.eex b/lib/pleroma/web/templates/feed/feed/_activity.rss.eex index 6ef24d0ef..9ebaa3300 100644 --- a/lib/pleroma/web/templates/feed/feed/_activity.rss.eex +++ b/lib/pleroma/web/templates/feed/feed/_activity.rss.eex @@ -21,7 +21,7 @@ <%= @data["external_url"] %> <% end %> - <%= for hashtag <- Object.hashtags(@data) do %> + <%= for hashtag <- Object.hashtags(@object) do %> <% end %> diff --git a/lib/pleroma/web/templates/feed/feed/_tag_activity.atom.eex b/lib/pleroma/web/templates/feed/feed/_tag_activity.atom.eex index 098e28205..8d78520cf 100644 --- a/lib/pleroma/web/templates/feed/feed/_tag_activity.atom.eex +++ b/lib/pleroma/web/templates/feed/feed/_tag_activity.atom.eex @@ -41,7 +41,7 @@ <% end %> <% end %> - <%= for hashtag <- Object.hashtags(@data) do %> + <%= for hashtag <- Object.hashtags(@object) do %> <% end %>