Merge branch 'oauth2' into 'develop'
[akkoma] / lib / pleroma / web / twitter_api / utils.ex
index 7f305c863a9ab6fbdee311fed07adfae66818387..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