aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlain <lain@soykaf.club>2020-06-01 15:14:22 +0200
committerlain <lain@soykaf.club>2020-06-01 15:14:22 +0200
commitaf9090238e1f71e6b081fbd09c09a5975d2ed99e (patch)
tree8930568a6cea53e180e2e8d9a79808d1815a22a6
parent8ff342582839259f3b8e039c6b3da3c0cf798a1f (diff)
downloadpleroma-af9090238e1f71e6b081fbd09c09a5975d2ed99e.tar.gz
CommonAPI: Newlines -> br for chat messages.
-rw-r--r--lib/pleroma/web/common_api/common_api.ex3
-rw-r--r--test/web/common_api/common_api_test.exs20
2 files changed, 23 insertions, 0 deletions
diff --git a/lib/pleroma/web/common_api/common_api.ex b/lib/pleroma/web/common_api/common_api.ex
index 173353aa5..e0987b1a7 100644
--- a/lib/pleroma/web/common_api/common_api.ex
+++ b/lib/pleroma/web/common_api/common_api.ex
@@ -54,6 +54,9 @@ defmodule Pleroma.Web.CommonAPI do
content
|> Formatter.html_escape("text/plain")
|> Formatter.linkify()
+ |> (fn {text, mentions, tags} ->
+ {String.replace(text, ~r/\r?\n/, "<br>"), mentions, tags}
+ end).()
text
end
diff --git a/test/web/common_api/common_api_test.exs b/test/web/common_api/common_api_test.exs
index 41c6909de..611a9ae66 100644
--- a/test/web/common_api/common_api_test.exs
+++ b/test/web/common_api/common_api_test.exs
@@ -50,6 +50,26 @@ defmodule Pleroma.Web.CommonAPITest do
assert activity
end
+ test "it adds html newlines" do
+ author = insert(:user)
+ recipient = insert(:user)
+
+ other_user = insert(:user)
+
+ {:ok, activity} =
+ CommonAPI.post_chat_message(
+ author,
+ recipient,
+ "uguu\nuguuu"
+ )
+
+ assert other_user.ap_id not in activity.recipients
+
+ object = Object.normalize(activity, false)
+
+ assert object.data["content"] == "uguu<br/>uguuu"
+ end
+
test "it linkifies" do
author = insert(:user)
recipient = insert(:user)