Merge branch 'dev_vald_fe/data_tag' into 'develop'
added data-user and data-tag attributes Closes #410 See merge request pleroma/pleroma!504
This commit is contained in:
commit
6ab58fdfa1
@ -114,7 +114,7 @@ defmodule Pleroma.Formatter do
|
||||
|
||||
subs =
|
||||
subs ++
|
||||
Enum.map(mentions, fn {match, %User{ap_id: ap_id, info: info}, uuid} ->
|
||||
Enum.map(mentions, fn {match, %User{id: id, ap_id: ap_id, info: info}, uuid} ->
|
||||
ap_id =
|
||||
if is_binary(info.source_data["url"]) do
|
||||
info.source_data["url"]
|
||||
@ -125,7 +125,7 @@ defmodule Pleroma.Formatter do
|
||||
short_match = String.split(match, "@") |> tl() |> hd()
|
||||
|
||||
{uuid,
|
||||
"<span><a class='mention' href='#{ap_id}'>@<span>#{short_match}</span></a></span>"}
|
||||
"<span><a data-user='#{id}' class='mention' href='#{ap_id}'>@<span>#{short_match}</span></a></span>"}
|
||||
end)
|
||||
|
||||
{subs, uuid_text}
|
||||
@ -147,7 +147,11 @@ defmodule Pleroma.Formatter do
|
||||
subs =
|
||||
subs ++
|
||||
Enum.map(tags, fn {tag_text, tag, uuid} ->
|
||||
url = "<a href='#{Pleroma.Web.base_url()}/tag/#{tag}' rel='tag'>#{tag_text}</a>"
|
||||
url =
|
||||
"<a data-tag='#{tag}' href='#{Pleroma.Web.base_url()}/tag/#{tag}' rel='tag'>#{
|
||||
tag_text
|
||||
}</a>"
|
||||
|
||||
{uuid, url}
|
||||
end)
|
||||
|
||||
|
@ -45,7 +45,7 @@ defmodule Pleroma.HTML.Scrubber.TwitterText do
|
||||
Meta.strip_comments()
|
||||
|
||||
# links
|
||||
Meta.allow_tag_with_uri_attributes("a", ["href"], @valid_schemes)
|
||||
Meta.allow_tag_with_uri_attributes("a", ["href", "data-user", "data-tag"], @valid_schemes)
|
||||
Meta.allow_tag_with_these_attributes("a", ["name", "title"])
|
||||
|
||||
# paragraphs and linebreaks
|
||||
@ -86,7 +86,7 @@ defmodule Pleroma.HTML.Scrubber.Default do
|
||||
Meta.remove_cdata_sections_before_scrub()
|
||||
Meta.strip_comments()
|
||||
|
||||
Meta.allow_tag_with_uri_attributes("a", ["href"], @valid_schemes)
|
||||
Meta.allow_tag_with_uri_attributes("a", ["href", "data-user", "data-tag"], @valid_schemes)
|
||||
Meta.allow_tag_with_these_attributes("a", ["name", "title"])
|
||||
|
||||
Meta.allow_tag_with_these_attributes("abbr", ["title"])
|
||||
|
@ -15,7 +15,7 @@ defmodule Pleroma.FormatterTest do
|
||||
text = "I love #cofe and #2hu"
|
||||
|
||||
expected_text =
|
||||
"I love <a href='http://localhost:4001/tag/cofe' rel='tag'>#cofe</a> and <a href='http://localhost:4001/tag/2hu' rel='tag'>#2hu</a>"
|
||||
"I love <a data-tag='cofe' href='http://localhost:4001/tag/cofe' rel='tag'>#cofe</a> and <a data-tag='2hu' href='http://localhost:4001/tag/2hu' rel='tag'>#2hu</a>"
|
||||
|
||||
tags = Formatter.parse_tags(text)
|
||||
|
||||
@ -128,11 +128,11 @@ defmodule Pleroma.FormatterTest do
|
||||
Enum.each(subs, fn {uuid, _} -> assert String.contains?(text, uuid) end)
|
||||
|
||||
expected_text =
|
||||
"<span><a class='mention' href='#{gsimg.ap_id}'>@<span>gsimg</span></a></span> According to <span><a class='mention' href='#{
|
||||
"https://archeme/@archaeme"
|
||||
}'>@<span>archaeme</span></a></span>, that is @daggsy. Also hello <span><a class='mention' href='#{
|
||||
archaeme_remote.ap_id
|
||||
}'>@<span>archaeme</span></a></span>"
|
||||
"<span><a data-user='#{gsimg.id}' class='mention' href='#{gsimg.ap_id}'>@<span>gsimg</span></a></span> According to <span><a data-user='#{
|
||||
archaeme.id
|
||||
}' class='mention' href='#{"https://archeme/@archaeme"}'>@<span>archaeme</span></a></span>, that is @daggsy. Also hello <span><a data-user='#{
|
||||
archaeme_remote.id
|
||||
}' class='mention' href='#{archaeme_remote.ap_id}'>@<span>archaeme</span></a></span>"
|
||||
|
||||
assert expected_text == Formatter.finalize({subs, text})
|
||||
end
|
||||
@ -150,7 +150,7 @@ defmodule Pleroma.FormatterTest do
|
||||
Enum.each(subs, fn {uuid, _} -> assert String.contains?(text, uuid) end)
|
||||
|
||||
expected_text =
|
||||
"<span><a class='mention' href='#{mike.ap_id}'>@<span>mike</span></a></span> test"
|
||||
"<span><a data-user='#{mike.id}' class='mention' href='#{mike.ap_id}'>@<span>mike</span></a></span> test"
|
||||
|
||||
assert expected_text == Formatter.finalize({subs, text})
|
||||
end
|
||||
@ -166,7 +166,9 @@ defmodule Pleroma.FormatterTest do
|
||||
assert length(subs) == 1
|
||||
Enum.each(subs, fn {uuid, _} -> assert String.contains?(text, uuid) end)
|
||||
|
||||
expected_text = "<span><a class='mention' href='#{o.ap_id}'>@<span>o</span></a></span> hi"
|
||||
expected_text =
|
||||
"<span><a data-user='#{o.id}' class='mention' href='#{o.ap_id}'>@<span>o</span></a></span> hi"
|
||||
|
||||
assert expected_text == Formatter.finalize({subs, text})
|
||||
end
|
||||
|
||||
|
@ -590,7 +590,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
||||
|> get("/api/v1/notifications")
|
||||
|
||||
expected_response =
|
||||
"hi <span><a href=\"#{user.ap_id}\">@<span>#{user.nickname}</span></a></span>"
|
||||
"hi <span><a data-user=\"#{user.id}\" href=\"#{user.ap_id}\">@<span>#{user.nickname}</span></a></span>"
|
||||
|
||||
assert [%{"status" => %{"content" => response}} | _rest] = json_response(conn, 200)
|
||||
assert response == expected_response
|
||||
@ -611,7 +611,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
||||
|> get("/api/v1/notifications/#{notification.id}")
|
||||
|
||||
expected_response =
|
||||
"hi <span><a href=\"#{user.ap_id}\">@<span>#{user.nickname}</span></a></span>"
|
||||
"hi <span><a data-user=\"#{user.id}\" href=\"#{user.ap_id}\">@<span>#{user.nickname}</span></a></span>"
|
||||
|
||||
assert %{"status" => %{"content" => response}} = json_response(conn, 200)
|
||||
assert response == expected_response
|
||||
@ -1271,9 +1271,9 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
||||
assert user = json_response(conn, 200)
|
||||
|
||||
assert user["note"] ==
|
||||
"I drink <a href=\"http://localhost:4001/tag/cofe\">#cofe</a> with <span><a href=\"#{
|
||||
user2.ap_id
|
||||
}\">@<span>#{user2.nickname}</span></a></span>"
|
||||
"I drink <a data-tag=\"cofe\" href=\"http://localhost:4001/tag/cofe\">#cofe</a> with <span><a data-user=\"#{
|
||||
user2.id
|
||||
}\" href=\"#{user2.ap_id}\">@<span>#{user2.nickname}</span></a></span>"
|
||||
end
|
||||
|
||||
test "updates the user's locking status", %{conn: conn} do
|
||||
|
@ -969,7 +969,9 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|
||||
assert user.name == "new name"
|
||||
|
||||
assert user.bio ==
|
||||
"hi <span><a class='mention' href='#{user2.ap_id}'>@<span>#{user2.nickname}</span></a></span>"
|
||||
"hi <span><a data-user='#{user2.id}' class='mention' href='#{user2.ap_id}'>@<span>#{
|
||||
user2.nickname
|
||||
}</span></a></span>"
|
||||
|
||||
assert json_response(conn, 200) == UserView.render("user.json", %{user: user, for: user})
|
||||
end
|
||||
|
@ -10,7 +10,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
||||
|
||||
test "create a status" do
|
||||
user = insert(:user)
|
||||
_mentioned_user = insert(:user, %{nickname: "shp", ap_id: "shp"})
|
||||
mentioned_user = insert(:user, %{nickname: "shp", ap_id: "shp"})
|
||||
|
||||
object_data = %{
|
||||
"type" => "Image",
|
||||
@ -35,7 +35,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
||||
{:ok, activity = %Activity{}} = TwitterAPI.create_status(user, input)
|
||||
|
||||
expected_text =
|
||||
"Hello again, <span><a class='mention' href='shp'>@<span>shp</span></a></span>.<script></script><br>This is on another :moominmamma: line. <a href='http://localhost:4001/tag/2hu' rel='tag'>#2hu</a> <a href='http://localhost:4001/tag/epic' rel='tag'>#epic</a> <a href='http://localhost:4001/tag/phantasmagoric' rel='tag'>#phantasmagoric</a><br><a href=\"http://example.org/image.jpg\" class='attachment'>image.jpg</a>"
|
||||
"Hello again, <span><a data-user='#{mentioned_user.id}' class='mention' href='shp'>@<span>shp</span></a></span>.<script></script><br>This is on another :moominmamma: line. <a data-tag='2hu' href='http://localhost:4001/tag/2hu' rel='tag'>#2hu</a> <a data-tag='epic' href='http://localhost:4001/tag/epic' rel='tag'>#epic</a> <a data-tag='phantasmagoric' href='http://localhost:4001/tag/phantasmagoric' rel='tag'>#phantasmagoric</a><br><a href=\"http://example.org/image.jpg\" class='attachment'>image.jpg</a>"
|
||||
|
||||
assert get_in(activity.data, ["object", "content"]) == expected_text
|
||||
assert get_in(activity.data, ["object", "type"]) == "Note"
|
||||
@ -281,7 +281,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
||||
{:ok, user2} = TwitterAPI.register_user(data2)
|
||||
|
||||
expected_text =
|
||||
"<span><a class='mention' href='#{user1.ap_id}'>@<span>john</span></a></span> test"
|
||||
"<span><a data-user='#{user1.id}' class='mention' href='#{user1.ap_id}'>@<span>john</span></a></span> test"
|
||||
|
||||
assert user2.bio == expected_text
|
||||
end
|
||||
|
@ -47,7 +47,7 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do
|
||||
"repeated" => false,
|
||||
"statusnet_conversation_id" => convo_id,
|
||||
"statusnet_html" =>
|
||||
"Hey <span><a href=\"#{other_user.ap_id}\">@<span>shp</span></a></span>!",
|
||||
"Hey <span><a data-user=\"#{other_user.id}\" href=\"#{other_user.ap_id}\">@<span>shp</span></a></span>!",
|
||||
"tags" => [],
|
||||
"text" => "Hey @shp!",
|
||||
"uri" => activity.data["object"]["id"],
|
||||
|
Loading…
Reference in New Issue
Block a user