Pleroma.Object/1: take %Object{} as argument instead

This commit is contained in:
Haelwenn (lanodan) Monnier 2020-12-28 10:33:28 +01:00
parent 87b13c5430
commit 18b536c176
No known key found for this signature in database
GPG key ID: D5B7A8E43C997DEE
9 changed files with 12 additions and 17 deletions

View file

@ -48,18 +48,12 @@ defmodule Pleroma.Activity.Ir.Topics do
tags tags
end end
defp hashtags_to_topics(%{data: %{"hashtags" => tags}}) do defp hashtags_to_topics(object) do
Enum.map(tags, fn tag -> "hashtag:" <> tag end) object
end |> Object.hashtags()
defp hashtags_to_topics(%{data: %{"tag" => tags}}) do
tags
|> Enum.filter(&is_bitstring(&1))
|> Enum.map(fn tag -> "hashtag:" <> tag end) |> Enum.map(fn tag -> "hashtag:" <> tag end)
end end
defp hashtags_to_topics(_), do: []
defp remote_topics(%{local: true}), do: [] defp remote_topics(%{local: true}), do: []
defp remote_topics(%{actor: actor}) when is_binary(actor), defp remote_topics(%{actor: actor}) when is_binary(actor),

View file

@ -345,7 +345,7 @@ defmodule Pleroma.Object do
def self_replies(object, opts \\ []), def self_replies(object, opts \\ []),
do: replies(object, Keyword.put(opts, :self_only, true)) do: replies(object, Keyword.put(opts, :self_only, true))
def hashtags(%{"hashtags" => hashtags}), do: hashtags || [] def hashtags(%Object{data: %{"hashtags" => hashtags}}), do: hashtags || []
def hashtags(%{"tag" => tags}), do: Enum.filter(tags, &is_bitstring(&1)) def hashtags(%Object{data: %{"tag" => tags}}), do: Enum.filter(tags, &is_bitstring(&1))
def hashtags(_), do: [] def hashtags(_), do: []
end end

View file

@ -77,7 +77,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicy do
if MRF.subdomain_match?(media_nsfw, actor_host) do if MRF.subdomain_match?(media_nsfw, actor_host) do
child_object = child_object =
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("sensitive", true)
Map.put(object, "object", child_object) Map.put(object, "object", child_object)

View file

@ -864,7 +864,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
def add_hashtags(object) do def add_hashtags(object) do
hashtags = hashtags =
object %Object{data: object}
|> Object.hashtags() |> Object.hashtags()
|> Enum.map(fn tag -> |> Enum.map(fn tag ->
%{ %{

View file

@ -32,6 +32,7 @@ defmodule Pleroma.Web.Feed.FeedView do
%{ %{
activity: activity, activity: activity,
object: object,
data: Map.get(object, :data), data: Map.get(object, :data),
actor: actor actor: actor
} }

View file

@ -347,7 +347,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
media_attachments: attachments, media_attachments: attachments,
poll: render(PollView, "show.json", object: object, for: opts[:for]), poll: render(PollView, "show.json", object: object, for: opts[:for]),
mentions: mentions, mentions: mentions,
tags: build_tags(Object.hashtags(object.data)), tags: build_tags(Object.hashtags(object)),
application: %{ application: %{
name: "Web", name: "Web",
website: nil website: nil

View file

@ -22,7 +22,7 @@
<link type="text/html" href='<%= @data["external_url"] %>' rel="alternate"/> <link type="text/html" href='<%= @data["external_url"] %>' rel="alternate"/>
<% end %> <% end %>
<%= for hashtag <- Object.hashtags(@data) do %> <%= for hashtag <- Object.hashtags(@object) do %>
<category term="<%= hashtag %>"></category> <category term="<%= hashtag %>"></category>
<% end %> <% end %>

View file

@ -21,7 +21,7 @@
<link><%= @data["external_url"] %></link> <link><%= @data["external_url"] %></link>
<% end %> <% end %>
<%= for hashtag <- Object.hashtags(@data) do %> <%= for hashtag <- Object.hashtags(@object) do %>
<category term="<%= hashtag %>"></category> <category term="<%= hashtag %>"></category>
<% end %> <% end %>

View file

@ -41,7 +41,7 @@
<% end %> <% end %>
<% end %> <% end %>
<%= for hashtag <- Object.hashtags(@data) do %> <%= for hashtag <- Object.hashtags(@object) do %>
<category term="<%= hashtag %>"></category> <category term="<%= hashtag %>"></category>
<% end %> <% end %>