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

@ -78,7 +78,7 @@ defmodule Pleroma.Activity.Ir.TopicsTest do
end
test "converts tags to hash tags", %{activity: %{object: %{data: data} = object} = activity} do
tagged_data = Map.put(data, "tag", ["foo", "bar"])
tagged_data = Map.put(data, "hashtags", ["foo", "bar"])
activity = %{activity | object: %{object | data: tagged_data}}
topics = Topics.get_activity_topics(activity)

View file

@ -78,7 +78,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
assert SimplePolicy.filter(media_message) ==
{:ok,
media_message
|> put_in(["object", "tag"], ["foo", "nsfw"])
|> put_in(["object", "hashtags"], ["foo", "nsfw"])
|> put_in(["object", "sensitive"], true)}
assert SimplePolicy.filter(local_message) == {:ok, local_message}
@ -92,7 +92,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
assert SimplePolicy.filter(media_message) ==
{:ok,
media_message
|> put_in(["object", "tag"], ["foo", "nsfw"])
|> put_in(["object", "hashtags"], ["foo", "nsfw"])
|> put_in(["object", "sensitive"], true)}
assert SimplePolicy.filter(local_message) == {:ok, local_message}
@ -105,7 +105,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
"type" => "Create",
"object" => %{
"attachment" => [%{}],
"tag" => ["foo"],
"hashtags" => ["foo"],
"sensitive" => false
}
}

View file

@ -39,7 +39,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.NoteHandlingTest do
{:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
object = Object.normalize(data["object"])
assert "test" in object.data["tag"]
assert ["test"] == object.data["hashtags"]
end
test "it cleans up incoming notices which are not really DMs" do
@ -220,7 +220,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.NoteHandlingTest do
{:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
object = Object.normalize(data["object"])
assert Enum.at(object.data["tag"], 2) == "moo"
assert object.data["hashtags"] == ["moo"]
end
test "it works for incoming notices with contentMap" do

View file

@ -204,30 +204,37 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
{:ok, activity} = CommonAPI.post(user, %{status: "#2hu :firefox:"})
{:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
{:ok, %{"object" => modified_object}} = Transmogrifier.prepare_outgoing(activity.data)
assert length(modified["object"]["tag"]) == 2
assert [
%{"name" => "#2hu", "type" => "Hashtag"},
%{"name" => ":firefox:", "type" => "Emoji"}
] = modified_object["tag"]
assert is_nil(modified["object"]["emoji"])
assert is_nil(modified["object"]["like_count"])
assert is_nil(modified["object"]["announcements"])
assert is_nil(modified["object"]["announcement_count"])
assert is_nil(modified["object"]["context_id"])
refute Map.has_key?(modified_object, "hashtags")
refute Map.has_key?(modified_object, "emoji")
refute Map.has_key?(modified_object, "like_count")
refute Map.has_key?(modified_object, "announcements")
refute Map.has_key?(modified_object, "announcement_count")
refute Map.has_key?(modified_object, "context_id")
end
test "it strips internal fields of article" do
activity = insert(:article_activity)
{:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
{:ok, %{"object" => modified_object}} = Transmogrifier.prepare_outgoing(activity.data)
assert length(modified["object"]["tag"]) == 2
assert [
%{"name" => "#2hu", "type" => "Hashtag"},
%{"name" => ":2hu:", "type" => "Emoji"}
] = modified_object["tag"]
assert is_nil(modified["object"]["emoji"])
assert is_nil(modified["object"]["like_count"])
assert is_nil(modified["object"]["announcements"])
assert is_nil(modified["object"]["announcement_count"])
assert is_nil(modified["object"]["context_id"])
assert is_nil(modified["object"]["likes"])
refute Map.has_key?(modified_object, "hashtags")
refute Map.has_key?(modified_object, "emoji")
refute Map.has_key?(modified_object, "like_count")
refute Map.has_key?(modified_object, "announcements")
refute Map.has_key?(modified_object, "announcement_count")
refute Map.has_key?(modified_object, "context_id")
end
test "the directMessage flag is present" do

View file

@ -591,7 +591,8 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
"context" => "2hu",
"sensitive" => false,
"summary" => "test summary",
"tag" => ["jimm"],
"hashtags" => ["jimm"],
"tag" => [],
"to" => [user2.ap_id],
"type" => "Note",
"custom_tag" => "test"

View file

@ -493,7 +493,8 @@ defmodule Pleroma.Web.CommonAPITest do
object = Object.normalize(activity)
assert object.data["tag"] == ["2hu"]
assert object.data["tag"] == []
assert object.data["hashtags"] == ["2hu"]
end
test "it adds emoji in the object" do

View file

@ -262,8 +262,8 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
mentions: [],
tags: [
%{
name: "#{object_data["tag"]}",
url: "/tag/#{object_data["tag"]}"
name: "2hu",
url: "/tag/2hu"
}
],
application: %{