From 806550c921d1137e47ec662ea83ee0a542fb55d5 Mon Sep 17 00:00:00 2001 From: lain Date: Tue, 3 Apr 2018 18:32:46 +0200 Subject: [PATCH] Use user url in mention if we have it. --- lib/pleroma/formatter.ex | 4 +++- test/formatter_test.exs | 10 ++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/pleroma/formatter.ex b/lib/pleroma/formatter.ex index 9396b1826..3634a8f5b 100644 --- a/lib/pleroma/formatter.ex +++ b/lib/pleroma/formatter.ex @@ -189,7 +189,9 @@ def add_user_links({subs, text}, mentions) do subs = subs ++ - Enum.map(mentions, fn {match, %User{ap_id: ap_id}, uuid} -> + Enum.map(mentions, fn {match, %User{ap_id: ap_id, info: info}, uuid} -> + ap_id = info["source_data"]["url"] || ap_id + short_match = String.split(match, "@") |> tl() |> hd() {uuid, "@#{short_match}"} end) diff --git a/test/formatter_test.exs b/test/formatter_test.exs index b7246252f..d9cef8abc 100644 --- a/test/formatter_test.exs +++ b/test/formatter_test.exs @@ -64,7 +64,13 @@ test "turning urls into links" do test "gives a replacement for user links" do text = "@gsimg According to @archaeme, that is @daggsy. Also hello @archaeme@archae.me" gsimg = insert(:user, %{nickname: "gsimg"}) - archaeme = insert(:user, %{nickname: "archaeme"}) + + archaeme = + insert(:user, %{ + nickname: "archaeme", + info: %{"source_data" => %{"url" => "https://archeme/@archaeme"}} + }) + archaeme_remote = insert(:user, %{nickname: "archaeme@archae.me"}) mentions = Pleroma.Formatter.parse_mentions(text) @@ -76,7 +82,7 @@ test "gives a replacement for user links" do expected_text = "@gsimg According to @archaeme, that is @daggsy. Also hello @archaeme"