Fix display names/usernames being switched

This commit is contained in:
Shadowfacts 2021-08-25 17:22:16 -04:00
parent 10a06fd634
commit afff7c4fb3
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
2 changed files with 19 additions and 5 deletions

View File

@ -3,7 +3,7 @@
<div class="p-author h-card">
<h2 class="status-author-nickname">
<a href="<%= local_actor_link(@author) %>">
<%= @author.data["preferredUsername"] %>
<%= display_name(@author) %>
</a>
</h2>
<h3 class="status-author-username">

View File

@ -7,13 +7,27 @@ defmodule ClacksWeb.FrontendView do
@spec display_username(actor :: Actor.t()) :: String.t()
def display_username(%Actor{local: true, data: %{"name" => name}}) do
"@" <> name
def display_username(%Actor{local: true, data: %{"preferredUsername" => username}}) do
"@" <> username
end
def display_username(%Actor{local: false, ap_id: ap_id, data: %{"name" => name}}) do
def display_username(%Actor{
local: false,
ap_id: ap_id,
data: %{"preferredUsername" => username}
}) do
%URI{host: host} = URI.parse(ap_id)
"@" <> name <> "@" <> host
"@" <> username <> "@" <> host
end
@spec display_name(actor :: Actor.t()) :: String.t()
def display_name(%Actor{data: %{"name" => name, "preferredUsername" => username}}) do
if is_binary(name) && String.length(name) > 0 do
name
else
username
end
end
def local_actor_link(%Actor{local: true, ap_id: ap_id}), do: ap_id