CommonAPI: Newlines -> br for chat messages.
authorlain <lain@soykaf.club>
Mon, 1 Jun 2020 13:14:22 +0000 (15:14 +0200)
committerlain <lain@soykaf.club>
Mon, 1 Jun 2020 13:14:22 +0000 (15:14 +0200)
lib/pleroma/web/common_api/common_api.ex
test/web/common_api/common_api_test.exs

index 173353aa5ac363a646a5d56005cb485d4875cd36..e0987b1a7d36a2340f839980ad6d12aa43d59648 100644 (file)
@@ -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
index 41c6909de4b625eb90524c80a859aab0027a62c9..611a9ae66cf5afb6fe7c5cc46380718db7625666 100644 (file)
@@ -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)