Merge branch 'oauth2' into 'develop'
[akkoma] / lib / pleroma / web / twitter_api / utils.ex
index f02c8ad6da2b83977c3e0e8ed4808872f518f28a..0555880310f851e21d8a278ddb1d6dd8310e41bc 100644 (file)
@@ -9,19 +9,28 @@ defmodule Pleroma.Web.TwitterAPI.Utils do
     end)
   end
 
+  defp shortname(name) do
+    if String.length(name) < 30 do
+      name
+    else
+      String.slice(name, 0..30) <> "…"
+    end
+  end
+
   def add_attachments(text, attachments) do
     attachment_text = Enum.map(attachments, fn
       (%{"url" => [%{"href" => href} | _]}) ->
-        "<a href=\"#{URI.encode(href)}\" class='attachment'>#{Path.basename(href)}</a>"
+        name = URI.decode(Path.basename(href))
+        "<a href=\"#{href}\" class='attachment'>#{shortname(name)}</a>"
       _ -> ""
     end)
-    Enum.join([text | attachment_text], "<br />\n")
+    Enum.join([text | attachment_text], "<br>\n")
   end
 
   def format_input(text, mentions) do
     HtmlSanitizeEx.strip_tags(text)
     |> Formatter.linkify
-    |> String.replace("\n", "<br />\n")
+    |> String.replace("\n", "<br>\n")
     |> add_user_links(mentions)
   end
 
@@ -44,13 +53,10 @@ defmodule Pleroma.Web.TwitterAPI.Utils do
     end)
   end
 
-  def wrap_in_p(text), do: "<p>#{text}</p>"
-
   def make_content_html(status, mentions, attachments) do
     status
     |> format_input(mentions)
     |> add_attachments(attachments)
-    |> wrap_in_p
   end
 
   def make_context(%Activity{data: %{"context" => context}}), do: context