forked from AkkomaGang/akkoma
CommonAPI: Linkify chat messages.
This commit is contained in:
parent
2c9465cc51
commit
8bdf18d7c1
2 changed files with 29 additions and 1 deletions
|
@ -50,7 +50,12 @@ def post_chat_message(%User{} = user, %User{} = recipient, content, opts \\ [])
|
||||||
defp format_chat_content(nil), do: nil
|
defp format_chat_content(nil), do: nil
|
||||||
|
|
||||||
defp format_chat_content(content) do
|
defp format_chat_content(content) do
|
||||||
content |> Formatter.html_escape("text/plain")
|
{text, _, _} =
|
||||||
|
content
|
||||||
|
|> Formatter.html_escape("text/plain")
|
||||||
|
|> Formatter.linkify()
|
||||||
|
|
||||||
|
text
|
||||||
end
|
end
|
||||||
|
|
||||||
defp validate_chat_content_length(_, true), do: :ok
|
defp validate_chat_content_length(_, true), do: :ok
|
||||||
|
|
|
@ -50,6 +50,29 @@ test "it posts a chat message without content but with an attachment" do
|
||||||
assert activity
|
assert activity
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "it linkifies" do
|
||||||
|
author = insert(:user)
|
||||||
|
recipient = insert(:user)
|
||||||
|
|
||||||
|
other_user = insert(:user)
|
||||||
|
|
||||||
|
{:ok, activity} =
|
||||||
|
CommonAPI.post_chat_message(
|
||||||
|
author,
|
||||||
|
recipient,
|
||||||
|
"https://example.org is the site of @#{other_user.nickname} #2hu"
|
||||||
|
)
|
||||||
|
|
||||||
|
assert other_user.ap_id not in activity.recipients
|
||||||
|
|
||||||
|
object = Object.normalize(activity, false)
|
||||||
|
|
||||||
|
assert object.data["content"] ==
|
||||||
|
"<a href=\"https://example.org\" rel=\"ugc\">https://example.org</a> is the site of <span class=\"h-card\"><a class=\"u-url mention\" data-user=\"#{
|
||||||
|
other_user.id
|
||||||
|
}\" href=\"#{other_user.ap_id}\" rel=\"ugc\">@<span>#{other_user.nickname}</span></a></span> <a class=\"hashtag\" data-tag=\"2hu\" href=\"http://localhost:4001/tag/2hu\">#2hu</a>"
|
||||||
|
end
|
||||||
|
|
||||||
test "it posts a chat message" do
|
test "it posts a chat message" do
|
||||||
author = insert(:user)
|
author = insert(:user)
|
||||||
recipient = insert(:user)
|
recipient = insert(:user)
|
||||||
|
|
Loading…
Reference in a new issue