switches username and preferred_username

This commit is contained in:
Christian Beutel
2025-06-24 17:55:59 +02:00
parent cb4f4f8125
commit 8bf8642703
39 changed files with 175 additions and 70 deletions

View File

@@ -34,8 +34,8 @@
try {
const actors: Actor[] = await searchActors(q, includeSelf);
searchItems = actors.map((a) => ({
text: a.preferred_username!,
description: `@${a.username}${a.isLocal ? "" : "@" + a.domain}`,
text: "a.username!",
description: `@${a.preferred_username}${a.isLocal ? "" : "@" + a.domain}`,
value: a,
icon: "user",
}));
@@ -50,7 +50,7 @@
}
function onClick(item: SearchItem) {
value = item.value.username ?? value;
value = item.value.preferred_username ?? value;
onclick?.(item);
searchItems = [];
@@ -70,7 +70,7 @@
<img
class="rounded-full w-8 aspect-square mr-2"
src={item.value.icon ||
`https://api.dicebear.com/7.x/initials/svg?seed=${item.value.username}&backgroundType=gradientLinear`}
`https://api.dicebear.com/7.x/initials/svg?seed=${item.value.preferred_username}&backgroundType=gradientLinear`}
alt="avatar"
/>
{/snippet}

View File

@@ -105,12 +105,12 @@
true,
);
return actors.map((a) => ({
text: a.preferred_username!,
description: `@${a.username}${a.isLocal ? "" : "@" + a.domain}`,
text: a.username!,
description: `@${a.preferred_username}${a.isLocal ? "" : "@" + a.domain}`,
value: a,
icon:
a.icon ||
`https://api.dicebear.com/7.x/initials/svg?seed=${a.username}&backgroundType=gradientLinear`,
`https://api.dicebear.com/7.x/initials/svg?seed=${a.preferred_username}&backgroundType=gradientLinear`,
}));
} catch (e) {
console.error(e);

View File

@@ -27,7 +27,7 @@
let avatarSrc = $derived(
comment.expand?.author.icon
? comment.expand?.author.icon
: `https://api.dicebear.com/7.x/initials/svg?seed=${comment.expand?.author.username ?? ""}&backgroundType=gradientLinear`,
: `https://api.dicebear.com/7.x/initials/svg?seed=${comment.expand?.author.preferred_username ?? ""}&backgroundType=gradientLinear`,
);
let timeSince = $derived(formatTimeSince(new Date(comment.created ?? "")));

View File

@@ -66,7 +66,7 @@
<img
class="rounded-full w-5 aspect-square mx-1 inline"
src={list.expand.author.icon ||
`https://api.dicebear.com/7.x/initials/svg?seed=${list.expand.author.username}&backgroundType=gradientLinear`}
`https://api.dicebear.com/7.x/initials/svg?seed=${list.expand.author.preferred_username}&backgroundType=gradientLinear`}
alt="avatar"
/>
{handleFromRecordWithIRI(list)}

View File

@@ -143,7 +143,7 @@
<img
class="rounded-full w-8 aspect-square mx-1 inline"
src={list.expand.author.icon ||
`https://api.dicebear.com/7.x/initials/svg?seed=${list.expand.author.username}&backgroundType=gradientLinear`}
`https://api.dicebear.com/7.x/initials/svg?seed=${list.expand.author.preferred_username}&backgroundType=gradientLinear`}
alt="avatar"
/>
<a class="underline" href="/profile/{handleFromRecordWithIRI(list)}"

View File

@@ -157,11 +157,11 @@
<img
class="rounded-full w-8 aspect-square mr-2"
src={share.expand.actor.icon ||
`https://api.dicebear.com/7.x/initials/svg?seed=${share.expand.actor.username}&backgroundType=gradientLinear`}
`https://api.dicebear.com/7.x/initials/svg?seed=${share.expand.actor.preferred_username}&backgroundType=gradientLinear`}
alt="avatar"
/>
<p>
{`@${share.expand.actor.username}${share.expand.actor.isLocal ? "" : "@" + share.expand.actor.domain}`}
{`@${share.expand.actor.preferred_username}${share.expand.actor.isLocal ? "" : "@" + share.expand.actor.domain}`}
</p>
<span
class="basis-full text-sm text-center text-gray-500"

View File

@@ -18,7 +18,7 @@
const avatarSrc = notification.expand?.author.icon
? notification.expand.author.icon
: `https://api.dicebear.com/7.x/initials/svg?seed=${notification.expand?.author.username ?? ""}&backgroundType=gradientLinear`;
: `https://api.dicebear.com/7.x/initials/svg?seed=${notification.expand?.author.preferred_username ?? ""}&backgroundType=gradientLinear`;
const timeSince = formatTimeSince(new Date(notification.created ?? ""));

View File

@@ -24,7 +24,7 @@
<img
class="rounded-full w-10 aspect-square overflow-hidden"
src={actor.icon ||
`https://api.dicebear.com/7.x/initials/svg?seed=${actor.username}&backgroundType=gradientLinear`}
`https://api.dicebear.com/7.x/initials/svg?seed=${actor.preferred_username}&backgroundType=gradientLinear`}
alt="avatar"
/>
<div>

View File

@@ -53,7 +53,7 @@
<img
class="rounded-full w-8 aspect-square mr-2"
src={share.expand.actor.icon ||
`https://api.dicebear.com/7.x/initials/svg?seed=${share.expand.actor.username}&backgroundType=gradientLinear`}
`https://api.dicebear.com/7.x/initials/svg?seed=${share.expand.actor.preferred_username}&backgroundType=gradientLinear`}
alt="avatar"
/>
<p class="font-semibold text-base">
@@ -82,7 +82,7 @@
<img
class="rounded-full w-8 aspect-square mr-2"
src={subject.expand.author.icon ||
`https://api.dicebear.com/7.x/initials/svg?seed=${subject.expand.author.username}&backgroundType=gradientLinear`}
`https://api.dicebear.com/7.x/initials/svg?seed=${subject.expand.author.preferred_username}&backgroundType=gradientLinear`}
alt="avatar"
/>
<p class="font-semibold">

View File

@@ -103,7 +103,7 @@
<img
class="rounded-full w-5 aspect-square mx-1 inline"
src={log.expand.author.icon ||
`https://api.dicebear.com/7.x/initials/svg?seed=${log.expand.author.username}&backgroundType=gradientLinear`}
`https://api.dicebear.com/7.x/initials/svg?seed=${log.expand.author.preferred_username}&backgroundType=gradientLinear`}
alt="avatar"
/>
{handleFromRecordWithIRI(log)}

View File

@@ -189,13 +189,13 @@
<td>
<p
class="tooltip flex justify-center"
data-title="{log.expand.author.username}{log.expand.author
data-title="@{log.expand.author.preferred_username}{log.expand.author
.isLocal
? ''
: '@' + log.expand.author.domain}"
>
<a
href="/profile/@{log.expand.author.username?.toLowerCase()}{log
href="/profile/@{log.expand.author.preferred_username?.toLowerCase()}{log
.expand.author.isLocal
? ''
: '@' + log.expand.author.domain}"
@@ -203,7 +203,7 @@
<img
class="rounded-full w-7 aspect-square"
src={log.expand.author.icon ||
`https://api.dicebear.com/7.x/initials/svg?seed=${log.expand.author.username}&backgroundType=gradientLinear`}
`https://api.dicebear.com/7.x/initials/svg?seed=${log.expand.author.preferred_username}&backgroundType=gradientLinear`}
alt="avatar"
/>
</a>

View File

@@ -130,10 +130,10 @@
<img
class="rounded-full w-5 aspect-square mx-1 inline"
src={trail.expand.author.icon ||
`https://api.dicebear.com/7.x/initials/svg?seed=${trail.expand.author.username}&backgroundType=gradientLinear`}
`https://api.dicebear.com/7.x/initials/svg?seed=${trail.expand.author.preferred_username}&backgroundType=gradientLinear`}
alt="avatar"
/>
{trail.expand.author.username}{trail.expand.author.isLocal
{trail.expand.author.preferred_username}{trail.expand.author.isLocal
? ""
: "@" + trail.expand.author.domain}
</p>

View File

@@ -377,7 +377,7 @@
<img
class="rounded-full w-8 aspect-square mx-1 inline"
src={trail.expand.author.icon ||
`https://api.dicebear.com/7.x/initials/svg?seed=${trail.expand.author.username}&backgroundType=gradientLinear`}
`https://api.dicebear.com/7.x/initials/svg?seed=${trail.expand.author.preferred_username}&backgroundType=gradientLinear`}
alt="avatar"
/>
<a class="underline" href="/profile/{handle}"

View File

@@ -99,7 +99,7 @@
<img
class="rounded-full w-5 aspect-square mx-1 inline"
src={trail.expand.author.icon ||
`https://api.dicebear.com/7.x/initials/svg?seed=${trail.expand.author.username}&backgroundType=gradientLinear`}
`https://api.dicebear.com/7.x/initials/svg?seed=${trail.expand.author.preferred_username}&backgroundType=gradientLinear`}
alt="avatar"
/>
{handleFromRecordWithIRI(trail)}

View File

@@ -88,10 +88,10 @@
{#if trail.expand && trail.expand.author}
<div class="author-icon">
<img
title={`${trail.public ? $_("public") + " " : ""}${$_("by")} ${trail.expand.author.username}${trail.expand.author.isLocal ? "" : "@" + trail.expand.author.domain}`}
title={`${trail.public ? $_("public") + " " : ""}${$_("by")} @${trail.expand.author.preferred_username}${trail.expand.author.isLocal ? "" : "@" + trail.expand.author.domain}`}
class="rounded-full w-5 aspect-square mx-1 inline"
src={trail.expand.author.icon ||
`https://api.dicebear.com/7.x/initials/svg?seed=${trail.expand.author.username}&backgroundType=gradientLinear`}
`https://api.dicebear.com/7.x/initials/svg?seed=${trail.expand.author.preferred_username}&backgroundType=gradientLinear`}
alt="avatar"
/>
</div>

View File

@@ -275,7 +275,7 @@ export async function searchResultToLists(hits: Hits<ListSearchResult>): Promise
author: {
icon: h.author_avatar,
id: h.author,
username: h.author_name,
preferred_username: h.author_name,
} as any,
list_share_via_list: h.shares?.map(s => ({
permission: "view",

View File

@@ -477,7 +477,7 @@ export async function searchResultToTrailList(hits: Hits<TrailSearchResult>): Pr
isLocal: (h.domain?.length ?? 0) == 0,
id: h.author,
icon: h.author_avatar,
username: h.author_name,
preferred_username: h.author_name,
domain: h.domain,
} as any,
trail_share_via_trail: h.shares?.map(s => ({

View File

@@ -18,9 +18,9 @@ export function handleFromRecordWithIRI(record: any) {
}
if (!record.iri) {
return `@${record.expand.author.username}`
return `@${record.expand.author.preferred_username}`
}
const url = new URL(record.iri ?? "")
return `@${record.expand.author.username}@${url.hostname}`
return `@${record.expand.author.preferred_username}@${url.hostname}`
}

View File

@@ -34,11 +34,11 @@
const actors = await searchActors(q);
searchDropdownItems = actors.map((a) => ({
text: a.username,
description: `@${a.username}${a.isLocal ? "" : "@" + a.domain}`,
description: `@${a.preferred_username}${a.isLocal ? "" : "@" + a.domain}`,
value: a,
icon:
a.icon ||
`https://api.dicebear.com/7.x/initials/svg?seed=${a.username}&backgroundType=gradientLinear`,
`https://api.dicebear.com/7.x/initials/svg?seed=${a.preferred_username}&backgroundType=gradientLinear`,
}));
} else {
const r = await searchMulti({
@@ -89,9 +89,9 @@
goto(`/trail/view/${item.value}`);
} else if (item.icon == "layer-group") {
goto(`/lists/${item.value}`);
} else if (item.value.username) {
} else if (item.value.preferred_username) {
goto(
`/profile/@${item.value.username}${item.value.isLocal ? "" : "@" + item.value.domain}`,
`/profile/@${item.value.preferred_username}${item.value.isLocal ? "" : "@" + item.value.domain}`,
);
} else {
goto(`/map/?lat=${item.value.lat}&lon=${item.value.lon}`);

View File

@@ -36,7 +36,7 @@ export async function GET(event: RequestEvent) {
outbox: id + '/outbox',
summary: user.bio,
name: actor.username,
preferredUsername: user.username,
preferredUsername: actor.preferred_username,
followers: id + '/followers',
following: id + '/following',
url: `${env.ORIGIN}/profile/@${username}`,

View File

@@ -41,15 +41,21 @@ export async function GET(event: RequestEvent) {
remoteComments.items = remoteComments.items.filter(c => {
const iriId = c.iri?.substring(c.iri.length - 15) ?? ""
if (deduplicationMap[c.id!] != undefined) {
deduplicationMap[c.id!] = {...c, author: deduplicationMap[c.id!].author}
deduplicationMap[c.id!] = { ...c, author: deduplicationMap[c.id!].author }
return false
} else if (deduplicationMap[iriId] != undefined) {
deduplicationMap[iriId] = {...c, author: deduplicationMap[iriId].author}
deduplicationMap[iriId] = { ...c, author: deduplicationMap[iriId].author }
return false
}
return true
})
remoteComments.items.forEach(c => {
if (!c.iri?.length) {
c.iri = `${url}/${c.id}`
}
})
const allCommentItems = <ListResult<Comment>>{
items: localComments.items.concat(remoteComments.items),
page: localComments.page,

View File

@@ -21,7 +21,7 @@ export async function POST(event: RequestEvent) {
r = await event.locals.ms.index("lists").search(data.q, { ...data.options, filter: `author = ${actor.id}` });
} else {
const origin = new URL(actor.iri).origin
const url = `${origin}/api/v1/profile/${actor.username}/lists?` + event.url.searchParams
const url = `${origin}/api/v1/profile/${actor.preferred_username}/lists?` + event.url.searchParams
const response = await event.fetch(url, { method: 'POST', body: JSON.stringify(data) })
if (!response.ok) {

View File

@@ -22,7 +22,7 @@ export async function GET(event: RequestEvent) {
.getList<SummitLog>(safeSearchParams.page, safeSearchParams.perPage, { ...safeSearchParams, filter: `author='${actor.id}'` })
} else {
const origin = new URL(actor.iri).origin
const summitLogURL = `${origin}/api/v1/profile/${actor.username}/stats?` + event.url.searchParams
const summitLogURL = `${origin}/api/v1/profile/${actor.preferred_username}/stats?` + event.url.searchParams
const response = await event.fetch(summitLogURL, { method: 'GET' })
if (!response.ok) {
const errorResponse = await response.json()

View File

@@ -23,7 +23,7 @@ export async function GET(event: RequestEvent) {
.getList<TimelineItem>(safeSearchParams.page, safeSearchParams.perPage, { ...safeSearchParams, filter: `author='${actor.iri}'` })
} else {
const origin = new URL(actor.iri).origin
const timelineURL = `${origin}/api/v1/profile/${actor.username}/timeline?` + event.url.searchParams
const timelineURL = `${origin}/api/v1/profile/${actor.preferred_username}/timeline?` + event.url.searchParams
const response = await event.fetch(timelineURL, { method: 'GET' })
if (!response.ok) {

View File

@@ -20,7 +20,7 @@ export async function POST(event: RequestEvent) {
r = await event.locals.ms.index("trails").search(data.q, { ...data.options, filter: `author = ${actor.id}` });
} else {
const origin = new URL(actor.iri).origin
const url = `${origin}/api/v1/profile/${actor.username}/trails?` + event.url.searchParams
const url = `${origin}/api/v1/profile/${actor.preferred_username}/trails?` + event.url.searchParams
const response = await event.fetch(url, { method: 'POST', body: JSON.stringify(data) })
if (!response.ok) {

View File

@@ -32,7 +32,8 @@ export async function GET(event: RequestEvent) {
}
t = {
iri: iri,
author: actor.id
author: actor.id,
like_count: 0
} as Trail
}

View File

@@ -64,13 +64,13 @@
<img
class="rounded-full w-16 aspect-square overflow-hidden shrink-0"
src={data.profile.icon ||
`https://api.dicebear.com/7.x/initials/svg?seed=${data.profile.username}&backgroundType=gradientLinear`}
`https://api.dicebear.com/7.x/initials/svg?seed=${data.profile.preferredUsername}&backgroundType=gradientLinear`}
alt="avatar"
/>
<div>
<h4 class="text-2xl font-semibold col-start-2">
{data.profile.preferredUsername ??
data.profile.username}
{data.profile.username ??
"?"}
</h4>
<p class="text-sm text-gray-500 mb-4 break-all">
{data.profile.acct}

View File

@@ -69,7 +69,7 @@
<div class="space-y-4">
<h4 class="text-xl font-semibold">
{$_("about")}
{data.profile.preferredUsername}
{data.profile.username}
{#if data.isOwnProfile && data.profile.bio.length}
<a aria-label="Edit bio" class="ml-4" href="/settings/profile"
><i class="fa fa-pen text-base"></i></a

View File

@@ -64,7 +64,7 @@
<ul class="space-y-4">
{#each follows.items as follow}
<a
href="/profile/@{follow.username}{follow.isLocal
href="/profile/@{follow.preferred_username}{follow.isLocal
? ''
: '@' + follow.domain}"
>
@@ -74,15 +74,15 @@
<img
class="rounded-full w-10 aspect-square overflow-hidden"
src={follow.icon ||
`https://api.dicebear.com/7.x/initials/svg?seed=${follow.username}&backgroundType=gradientLinear`}
`https://api.dicebear.com/7.x/initials/svg?seed=${follow.preferred_username}&backgroundType=gradientLinear`}
alt="avatar"
/>
<div>
<p class="text-lg font-medium">
{follow.preferred_username}
{follow.username}
</p>
<p class="text-sm text-gray-500 break-all">
@{follow.username}@{follow.domain}
@{follow.preferred_username}@{follow.domain}
</p>
</div>
</li>