Create Object.hashtags/1 wrapper
This commit is contained in:
parent
acb03d591b
commit
87b13c5430
|
@ -344,4 +344,8 @@ 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(_), do: []
|
||||
end
|
||||
|
|
|
@ -8,6 +8,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicy do
|
|||
|
||||
alias Pleroma.Config
|
||||
alias Pleroma.FollowingRelationship
|
||||
alias Pleroma.Object
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.ActivityPub.MRF
|
||||
|
||||
|
@ -76,7 +77,7 @@ defp check_media_nsfw(
|
|||
if MRF.subdomain_match?(media_nsfw, actor_host) do
|
||||
child_object =
|
||||
child_object
|
||||
|> Map.put("hashtags", (child_object["hashtags"] || []) ++ ["nsfw"])
|
||||
|> Map.put("hashtags", Object.hashtags(child_object) ++ ["nsfw"])
|
||||
|> Map.put("sensitive", true)
|
||||
|
||||
Map.put(object, "object", child_object)
|
||||
|
|
|
@ -863,23 +863,18 @@ def maybe_fix_object_url(%{"object" => object} = data) when is_binary(object) do
|
|||
def maybe_fix_object_url(data), do: data
|
||||
|
||||
def add_hashtags(object) do
|
||||
tags =
|
||||
((object["hashtags"] || []) ++ (object["tag"] || []))
|
||||
|> Enum.map(fn
|
||||
# Expand internal representation tags into AS2 tags.
|
||||
tag when is_binary(tag) ->
|
||||
hashtags =
|
||||
object
|
||||
|> Object.hashtags()
|
||||
|> Enum.map(fn tag ->
|
||||
%{
|
||||
"href" => Pleroma.Web.Endpoint.url() <> "/tags/#{tag}",
|
||||
"name" => "##{tag}",
|
||||
"type" => "Hashtag"
|
||||
}
|
||||
|
||||
# Do not process tags which are already AS2 tag objects.
|
||||
tag when is_map(tag) ->
|
||||
tag
|
||||
end)
|
||||
|
||||
Map.put(object, "tag", tags)
|
||||
Map.put(object, "tag", hashtags ++ (object["tag"] || []))
|
||||
end
|
||||
|
||||
# TODO These should be added on our side on insertion, it doesn't make much
|
||||
|
|
|
@ -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.data["hashtags"] || tags),
|
||||
tags: build_tags(Object.hashtags(object.data)),
|
||||
application: %{
|
||||
name: "Web",
|
||||
website: nil
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
<link type="text/html" href='<%= @data["external_url"] %>' rel="alternate"/>
|
||||
<% end %>
|
||||
|
||||
<%= for hashtag <- @data["hashtags"] || [] do %>
|
||||
<%= for hashtag <- Object.hashtags(@data) do %>
|
||||
<category term="<%= hashtag %>"></category>
|
||||
<% end %>
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
<link><%= @data["external_url"] %></link>
|
||||
<% end %>
|
||||
|
||||
<%= for hashtag <- @data["hashtags"] || [] do %>
|
||||
<%= for hashtag <- Object.hashtags(@data) do %>
|
||||
<category term="<%= hashtag %>"></category>
|
||||
<% end %>
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@
|
|||
<% end %>
|
||||
<% end %>
|
||||
|
||||
<%= for hashtag <- @data["hashtags"] || [] do %>
|
||||
<%= for hashtag <- Object.hashtags(@data) do %>
|
||||
<category term="<%= hashtag %>"></category>
|
||||
<% end %>
|
||||
|
||||
|
|
Loading…
Reference in a new issue