Insert text representation of hashtags into object["hashtags"]

Includes a new mix task: pleroma.database fill_old_hashtags
This commit is contained in:
Haelwenn (lanodan) Monnier 2020-07-31 16:46:35 +02:00
commit acb03d591b
No known key found for this signature in database
GPG key ID: D5B7A8E43C997DEE
22 changed files with 139 additions and 51 deletions

View file

@ -312,16 +312,15 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
def fix_emoji(object), do: object
def fix_tag(%{"tag" => tag} = object) when is_list(tag) do
tags =
hashtags =
tag
|> Enum.filter(fn data -> data["type"] == "Hashtag" and data["name"] end)
|> Enum.map(fn %{"name" => name} ->
name
|> String.slice(1..-1)
|> String.downcase()
|> Enum.map(fn
%{"name" => "#" <> hashtag} -> String.downcase(hashtag)
%{"name" => hashtag} -> String.downcase(hashtag)
end)
Map.put(object, "tag", tag ++ tags)
Map.put(object, "hashtags", hashtags)
end
def fix_tag(%{"tag" => %{} = tag} = object) do
@ -865,7 +864,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
def add_hashtags(object) do
tags =
(object["tag"] || [])
((object["hashtags"] || []) ++ (object["tag"] || []))
|> Enum.map(fn
# Expand internal representation tags into AS2 tags.
tag when is_binary(tag) ->
@ -936,7 +935,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
end
def set_sensitive(object) do
tags = object["tag"] || []
tags = object["hashtags"] || object["tag"] || []
Map.put(object, "sensitive", "nsfw" in tags)
end