Move finmojis to representation.
[akkoma] / lib / pleroma / web / twitter_api / utils.ex
index 82e3620f2a38e6d31e1de6785923335617399037..5cbe0cf9c96acb297a119b12bf9d95f2e25595be 100644 (file)
@@ -11,7 +11,7 @@ defmodule Pleroma.Web.TwitterAPI.Utils do
   def add_attachments(text, attachments) do
     attachment_text = Enum.map(attachments, fn
       (%{"url" => [%{"href" => href} | _]}) ->
-        "<a href='#{href}' class='attachment'>#{Path.basename(href)}</a>"
+        "<a href=\"#{URI.encode(href)}\" class='attachment'>#{Path.basename(href)}</a>"
       _ -> ""
     end)
     Enum.join([text | attachment_text], "<br>\n")
@@ -38,7 +38,8 @@ defmodule Pleroma.Web.TwitterAPI.Utils do
     end)
 
     Enum.reduce(mentions, step_one, fn ({match, %User{ap_id: ap_id}, uuid}, text) ->
-      String.replace(text, uuid, "<a href='#{ap_id}'>#{match}</a>")
+      short_match = String.split(match, "@") |> tl() |> hd()
+      String.replace(text, uuid, "<a href='#{ap_id}'>@#{short_match}</a>")
     end)
   end
 
@@ -51,6 +52,7 @@ defmodule Pleroma.Web.TwitterAPI.Utils do
   def make_context(%Activity{data: %{"context" => context}}), do: context
   def make_context(_), do: Utils.generate_context_id
 
+  # TODO: Move this to a more fitting space
   def make_note_data(actor, to, context, content_html, attachments, inReplyTo, tags) do
       object = %{
         "type" => "Note",