forked from AkkomaGang/akkoma
Shorten names in links.
This commit is contained in:
parent
fb78773112
commit
c6aa60c829
2 changed files with 3 additions and 2 deletions
|
@ -38,7 +38,8 @@ def add_user_links(text, mentions) do
|
||||||
end)
|
end)
|
||||||
|
|
||||||
Enum.reduce(mentions, step_one, fn ({match, %User{ap_id: ap_id}, uuid}, text) ->
|
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)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -263,7 +263,7 @@ test "it adds user links to an existing text" do
|
||||||
archaeme_remote = insert(:user, %{nickname: "archaeme@archae.me"})
|
archaeme_remote = insert(:user, %{nickname: "archaeme@archae.me"})
|
||||||
|
|
||||||
mentions = TwitterAPI.parse_mentions(text)
|
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
|
assert Utils.add_user_links(text, mentions) == expected_text
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue