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