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
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),

View file

@ -345,7 +345,7 @@ defmodule Pleroma.Object 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

View file

@ -77,7 +77,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicy do
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)

View file

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

View file

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

View file

@ -347,7 +347,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
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

View file

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

View file

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

View file

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