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
alias Pleroma.Config
alias Pleroma.FollowingRelationship
+ alias Pleroma.Object
alias Pleroma.User
alias Pleroma.Web.ActivityPub.MRF
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)
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) ->
- %{
- "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
+ hashtags =
+ object
+ |> Object.hashtags()
+ |> Enum.map(fn tag ->
+ %{
+ "href" => Pleroma.Web.Endpoint.url() <> "/tags/#{tag}",
+ "name" => "##{tag}",
+ "type" => "Hashtag"
+ }
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
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
<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 %>
<link><%= @data["external_url"] %></link>
<% end %>
- <%= for hashtag <- @data["hashtags"] || [] do %>
+ <%= for hashtag <- Object.hashtags(@data) do %>
<category term="<%= hashtag %>"></category>
<% end %>
<% end %>
<% end %>
- <%= for hashtag <- @data["hashtags"] || [] do %>
+ <%= for hashtag <- Object.hashtags(@data) do %>
<category term="<%= hashtag %>"></category>
<% end %>