Merge branch 'feature/unrepeats' of git.pleroma.social:normandy/pleroma into feature...
[akkoma] / lib / pleroma / gopher / server.ex
index 17741a7a797abb37b63a5300be5ed126af4f0301..82e241f21904025ea6c40f51286a5ffad0d0532c 100644 (file)
@@ -50,7 +50,13 @@ defmodule Pleroma.Gopher.Server.ProtocolHandler do
   end
 
   def info(text) do
-    "#{text}\tfake\(NULL)\t0\r\n"
+    text = String.replace(text, ~r/[\t\n]/, "")
+
+    String.split(text, "\r")
+    |> Enum.map(fn text ->
+      "i#{text}\tfake\(NULL)\t0\r\n"
+    end)
+    |> Enum.join("")
   end
 
   def link(name, selector, type \\ 1) do
@@ -77,7 +83,12 @@ defmodule Pleroma.Gopher.Server.ProtocolHandler do
 
       link("Post ##{activity.id} by #{user.nickname}", "/notices/#{activity.id}") <>
         info("#{like_count} likes, #{announcement_count} repeats") <>
-        "\r\n" <> info(HtmlSanitizeEx.strip_tags(activity.data["object"]["content"]))
+        "\r\n" <>
+        info(
+          HtmlSanitizeEx.strip_tags(
+            String.replace(activity.data["object"]["content"], "<br>", "\r")
+          )
+        )
     end)
     |> Enum.join("\r\n")
   end