formatter: Use user.uri instead of user.source_data.uri

This commit is contained in:
Haelwenn (lanodan) Monnier 2020-04-01 07:15:38 +02:00
parent b6bed1a284
commit 369c03834c
No known key found for this signature in database
GPG key ID: D5B7A8E43C997DEE
2 changed files with 3 additions and 6 deletions

View file

@ -31,7 +31,7 @@ def escape_mention_handler("@" <> nickname = mention, buffer, _, _) do
def mention_handler("@" <> nickname, buffer, opts, acc) do def mention_handler("@" <> nickname, buffer, opts, acc) do
case User.get_cached_by_nickname(nickname) do case User.get_cached_by_nickname(nickname) do
%User{id: id} = user -> %User{id: id} = user ->
ap_id = get_ap_id(user) user_url = user.uri || user.ap_id
nickname_text = get_nickname_text(nickname, opts) nickname_text = get_nickname_text(nickname, opts)
link = link =
@ -42,7 +42,7 @@ def mention_handler("@" <> nickname, buffer, opts, acc) do
["@", Phoenix.HTML.Tag.content_tag(:span, nickname_text)], ["@", Phoenix.HTML.Tag.content_tag(:span, nickname_text)],
"data-user": id, "data-user": id,
class: "u-url mention", class: "u-url mention",
href: ap_id, href: user_url,
rel: "ugc" rel: "ugc"
), ),
class: "h-card" class: "h-card"
@ -146,9 +146,6 @@ def truncate(text, max_length \\ 200, omission \\ "...") do
end end
end end
defp get_ap_id(%User{source_data: %{"url" => url}}) when is_binary(url), do: url
defp get_ap_id(%User{ap_id: ap_id}), do: ap_id
defp get_nickname_text(nickname, %{mentions_format: :full}), do: User.full_nickname(nickname) defp get_nickname_text(nickname, %{mentions_format: :full}), do: User.full_nickname(nickname)
defp get_nickname_text(nickname, _), do: User.local_nickname(nickname) defp get_nickname_text(nickname, _), do: User.local_nickname(nickname)
end end

View file

@ -140,7 +140,7 @@ test "gives a replacement for user links, using local nicknames in user links te
archaeme = archaeme =
insert(:user, insert(:user,
nickname: "archa_eme_", nickname: "archa_eme_",
source_data: %{"url" => "https://archeme/@archa_eme_"} uri: "https://archeme/@archa_eme_"
) )
archaeme_remote = insert(:user, %{nickname: "archaeme@archae.me"}) archaeme_remote = insert(:user, %{nickname: "archaeme@archae.me"})