logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma
commit: 806550c921d1137e47ec662ea83ee0a542fb55d5
parent: b3b7ab5d9a0528bdfa385bd61d7f97ae4c7de374
Author: lain <lain@soykaf.club>
Date:   Tue,  3 Apr 2018 18:32:46 +0200

Use user url in mention if we have it.

Diffstat:

Mlib/pleroma/formatter.ex4+++-
Mtest/formatter_test.exs10++++++++--
2 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/lib/pleroma/formatter.ex b/lib/pleroma/formatter.ex @@ -189,7 +189,9 @@ defmodule Pleroma.Formatter 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, "<span><a href='#{ap_id}'>@<span>#{short_match}</span></a></span>"} end) diff --git a/test/formatter_test.exs b/test/formatter_test.exs @@ -64,7 +64,13 @@ defmodule Pleroma.FormatterTest 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 @@ defmodule Pleroma.FormatterTest do expected_text = "<span><a href='#{gsimg.ap_id}'>@<span>gsimg</span></a></span> According to <span><a href='#{ - archaeme.ap_id + "https://archeme/@archaeme" }'>@<span>archaeme</span></a></span>, that is @daggsy. Also hello <span><a href='#{ archaeme_remote.ap_id }'>@<span>archaeme</span></a></span>"