Shorten names in links.
authorRoger Braun <roger@rogerbraun.net>
Tue, 30 May 2017 12:26:31 +0000 (14:26 +0200)
committerRoger Braun <roger@rogerbraun.net>
Tue, 30 May 2017 12:26:31 +0000 (14:26 +0200)
lib/pleroma/web/twitter_api/utils.ex
test/web/twitter_api/twitter_api_test.exs

index 82e3620f2a38e6d31e1de6785923335617399037..91dfa191ffbf3f65fee18c88413e65e07b813a3f 100644 (file)
@@ -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
 
index 4df1aba9eb1f88b37466745dcc36a5bec631049c..df1022d6bfaa2e27a51f80e893e46f3589923610 100644 (file)
@@ -263,7 +263,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
     archaeme_remote = insert(:user, %{nickname: "archaeme@archae.me"})
 
     mentions = TwitterAPI.parse_mentions(text)
-    expected_text = "<a href='#{gsimg.ap_id}'>@gsimg</a> According to <a href='#{archaeme.ap_id}'>@archaeme</a>, that is @daggsy. Also hello <a href='#{archaeme_remote.ap_id}'>@archaeme@archae.me</a>"
+    expected_text = "<a href='#{gsimg.ap_id}'>@gsimg</a> According to <a href='#{archaeme.ap_id}'>@archaeme</a>, that is @daggsy. Also hello <a href='#{archaeme_remote.ap_id}'>@archaeme</a>"
 
     assert Utils.add_user_links(text, mentions) == expected_text
   end