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

@@ -43,7 +43,7 @@ func SplitHandle(handle string) (string, string) {
func GetActorByHandle(app core.App, handle string, includeFollows bool) (*core.Record, error) {
username, domain := SplitHandle(handle)
filter := "username={:username}&&"
filter := "preferred_username={:username}&&"
if domain != "" {
filter += "domain={:domain}"
} else {

View File

@@ -196,7 +196,7 @@ func processTrailAnnounceActivity(app core.App, actor *core.Record, activity pub
Metadata: map[string]string{
"id": trail.Id,
"trail": trail.GetString("name"),
"author": fmt.Sprintf("@%s@%s", actor.GetString("username"), actor.GetString("domain")),
"author": fmt.Sprintf("@%s@%s", actor.GetString("preferred_username"), actor.GetString("domain")),
},
Seen: false,
Author: actor.Id,
@@ -261,7 +261,7 @@ func processListAnnounceActivity(app core.App, actor *core.Record, activity pub.
Metadata: map[string]string{
"id": list.Id,
"list": list.GetString("name"),
"author": fmt.Sprintf("@%s@%s", actor.GetString("username"), actor.GetString("domain")),
"author": fmt.Sprintf("@%s@%s", actor.GetString("preferred_username"), actor.GetString("domain")),
},
Seen: false,
Author: actor.Id,

View File

@@ -322,7 +322,7 @@ func CreateSummitLogActivity(app core.App, summitLog *core.Record, typ pub.Activ
logObject.AttributedTo = pub.IRI(summitLogAuthor.GetString("iri"))
logObject.Published = summitLog.GetDateTime("created").Time()
logObject.ID = pub.IRI(fmt.Sprintf("%s/api/v1/summit-log/%s", origin, summitLog.Id))
logObject.URL = pub.IRI(fmt.Sprintf("%s/trail/view/@%s/%s", origin, summitLogTrailAuthor.GetString("username"), summitLog.GetString("trail")))
logObject.URL = pub.IRI(fmt.Sprintf("%s/trail/view/@%s/%s", origin, summitLogTrailAuthor.GetString("preferred_username"), summitLog.GetString("trail")))
logObject.InReplyTo = trailIRI
logObject.Tag = tags
@@ -487,7 +487,7 @@ func processCreateOrUpdateTrailActivity(activity pub.Activity, app core.App, act
Type: util.TrailMention,
Metadata: map[string]string{
"id": trail.Id,
"author": fmt.Sprintf("@%s@%s", actor.GetString("username"), actor.GetString("domain")),
"author": fmt.Sprintf("@%s@%s", actor.GetString("preferred_username"), actor.GetString("domain")),
},
Seen: false,
Author: actor.Id,
@@ -584,7 +584,7 @@ func processCreateOrUpdateCommentActivity(activity pub.Activity, app core.App, a
"comment": commentObject.Content.First().Value.String(),
"trail_id": trail.Id,
"trail_name": trail.GetString("name"),
"trail_author": fmt.Sprintf("@%s@%s", trailAuthor.GetString("username"), trailAuthor.GetString("domain")),
"trail_author": fmt.Sprintf("@%s@%s", trailAuthor.GetString("preferred_username"), trailAuthor.GetString("domain")),
},
Seen: false,
Author: actor.Id,
@@ -600,7 +600,7 @@ func processCreateOrUpdateCommentActivity(activity pub.Activity, app core.App, a
"comment": commentObject.Content.First().Value.String(),
"trail_id": trail.Id,
"trail_name": trail.GetString("name"),
"trail_author": fmt.Sprintf("@%s@%s", trailAuthor.GetString("username"), trailAuthor.GetString("domain")),
"trail_author": fmt.Sprintf("@%s@%s", trailAuthor.GetString("preferred_username"), trailAuthor.GetString("domain")),
},
Seen: false,
Author: actor.Id,
@@ -764,7 +764,7 @@ func processCreateOrUpdateSummitLogActivity(activity pub.Activity, app core.App,
Metadata: map[string]string{
"trail_id": trail.Id,
"trail_name": trail.GetString("name"),
"trail_author": fmt.Sprintf("@%s@%s", trailAuthor.GetString("username"), trailAuthor.GetString("domain")),
"trail_author": fmt.Sprintf("@%s@%s", trailAuthor.GetString("preferred_username"), trailAuthor.GetString("domain")),
},
Seen: false,
Author: actor.Id,
@@ -780,7 +780,7 @@ func processCreateOrUpdateSummitLogActivity(activity pub.Activity, app core.App,
Metadata: map[string]string{
"trail_id": trail.Id,
"trail_name": trail.GetString("name"),
"trail_author": fmt.Sprintf("@%s@%s", trailAuthor.GetString("username"), trailAuthor.GetString("domain")),
"trail_author": fmt.Sprintf("@%s@%s", trailAuthor.GetString("preferred_username"), trailAuthor.GetString("domain")),
},
Seen: false,
Author: actor.Id,

View File

@@ -124,7 +124,7 @@ func ProcessFollowActivity(app core.App, actor *core.Record, activity pub.Activi
notification := util.Notification{
Type: util.NewFollower,
Metadata: map[string]string{
"follower": fmt.Sprintf("@%s@%s", actor.GetString("username"), actor.GetString("domain")),
"follower": fmt.Sprintf("@%s@%s", actor.GetString("preferred_username"), actor.GetString("domain")),
},
Seen: false,
Author: actor.Id,

View File

@@ -107,8 +107,8 @@ func ProcessLikeActivity(app core.App, actor *core.Record, activity pub.Activity
Metadata: map[string]string{
"trail_id": trail.Id,
"trail_name": trail.GetString("name"),
"trail_author": fmt.Sprintf("@%s", trailAuthor.GetString("username")),
"liker": fmt.Sprintf("@%s@%s", actor.GetString("username"), actor.GetString("domain")),
"trail_author": fmt.Sprintf("@%s", trailAuthor.GetString("preferred_username")),
"liker": fmt.Sprintf("@%s@%s", actor.GetString("preferred_username"), actor.GetString("domain")),
},
Seen: false,
Author: actor.Id,

View File

@@ -0,0 +1,58 @@
package migrations
import (
"github.com/pocketbase/pocketbase/core"
m "github.com/pocketbase/pocketbase/migrations"
)
func init() {
m.Register(func(app core.App) error {
actors, err := app.FindAllRecords("activitypub_actors")
if err != nil {
return err
}
for _, a := range actors {
if !a.GetBool("isLocal") {
continue
}
username := a.GetString("username")
preferredUsername := a.GetString("preferred_username")
a.Set("username", preferredUsername)
a.Set("preferred_username", username)
err = app.Save(a)
if err != nil {
return err
}
}
return nil
}, func(app core.App) error {
actors, err := app.FindAllRecords("activitypub_actors")
if err != nil {
return err
}
for _, a := range actors {
if !a.GetBool("isLocal") {
continue
}
username := a.GetString("username")
preferredUsername := a.GetString("preferred_username")
a.Set("username", preferredUsername)
a.Set("preferred_username", username)
err = app.Save(a)
if err != nil {
return err
}
}
return nil
})
}

View File

@@ -0,0 +1,40 @@
package migrations
import (
"encoding/json"
"github.com/pocketbase/pocketbase/core"
m "github.com/pocketbase/pocketbase/migrations"
)
func init() {
m.Register(func(app core.App) error {
collection, err := app.FindCollectionByNameOrId("pbc_468398817")
if err != nil {
return err
}
// update collection data
if err := json.Unmarshal([]byte(`{
"viewQuery": "SELECT\n id,\n trail_id,\n trail_author_username,\n trail_author_domain,\n trail_iri,\n date,\n name,\n description,\n gpx,\n author,\n photos,\n distance,\n duration,\n elevation_gain,\n elevation_loss,\n created,\n type\nFROM\n (\n SELECT\n summit_logs.id,\n summit_logs.trail as trail_id,\n tapa.preferred_username as trail_author_username,\n tapa.domain as trail_author_domain,\n trails.iri as trail_iri,\n summit_logs.date,\n trails.name,\n text as description,\n summit_logs.gpx,\n sapa.iri as author,\n summit_logs.photos,\n summit_logs.distance,\n summit_logs.duration,\n summit_logs.elevation_gain,\n summit_logs.elevation_loss,\n summit_logs.created,\n \"summit_log\" as type\n FROM\n summit_logs\n JOIN trails ON summit_logs.trail = trails.id\n JOIN activitypub_actors sapa ON sapa.id = summit_logs.author\n JOIN activitypub_actors tapa ON tapa.id = trails.author\n UNION\n SELECT\n trails.id,\n trails.id as trail_id,\n activitypub_actors.preferred_username as trail_author_username,\n activitypub_actors.domain as trail_author_domain,\n trails.iri as trail_iri,\n date,\n trails.name,\n description,\n gpx,\n activitypub_actors.iri as author,\n photos,\n distance,\n duration,\n elevation_gain,\n elevation_loss,\n trails.created,\n \"trail\" as type\n FROM\n trails\n JOIN activitypub_actors ON activitypub_actors.id = trails.author\n )\nORDER BY\n created DESC;\n"
}`), &collection); err != nil {
return err
}
return app.Save(collection)
}, func(app core.App) error {
collection, err := app.FindCollectionByNameOrId("pbc_468398817")
if err != nil {
return err
}
// update collection data
if err := json.Unmarshal([]byte(`{
"viewQuery": "SELECT\n id,\n trail_id,\n trail_author_username,\n trail_author_domain,\n trail_iri,\n date,\n name,\n description,\n gpx,\n author,\n photos,\n distance,\n duration,\n elevation_gain,\n elevation_loss,\n created,\n type\nFROM\n (\n SELECT\n summit_logs.id,\n summit_logs.trail as trail_id,\n tapa.username as trail_author_username,\n tapa.domain as trail_author_domain,\n trails.iri as trail_iri,\n summit_logs.date,\n trails.name,\n text as description,\n summit_logs.gpx,\n sapa.iri as author,\n summit_logs.photos,\n summit_logs.distance,\n summit_logs.duration,\n summit_logs.elevation_gain,\n summit_logs.elevation_loss,\n summit_logs.created,\n \"summit_log\" as type\n FROM\n summit_logs\n JOIN trails ON summit_logs.trail = trails.id\n JOIN activitypub_actors sapa ON sapa.id = summit_logs.author\n JOIN activitypub_actors tapa ON tapa.id = trails.author\n UNION\n SELECT\n trails.id,\n trails.id as trail_id,\n activitypub_actors.username as trail_author_username,\n activitypub_actors.domain as trail_author_domain,\n trails.iri as trail_iri,\n date,\n trails.name,\n description,\n gpx,\n activitypub_actors.iri as author,\n photos,\n distance,\n duration,\n elevation_gain,\n elevation_loss,\n trails.created,\n \"trail\" as type\n FROM\n trails\n JOIN activitypub_actors ON activitypub_actors.id = trails.author\n )\nORDER BY\n created DESC;\n"
}`), &collection); err != nil {
return err
}
return app.Save(collection)
})
}

View File

@@ -64,7 +64,7 @@ func ActorFromUser(app core.App, u *core.Record) (*core.Record, error) {
if origin == "" {
return nil, fmt.Errorf("ORIGIN environment variable not set")
}
id := fmt.Sprintf("%s/api/v1/activitypub/user/%s", origin, strings.ToLower(u.GetString("username")))
id := fmt.Sprintf("%s/api/v1/activitypub/user/%s", origin, strings.ToLower(u.GetString("preferred_username")))
url, err := url.Parse(origin)
if err != nil {
@@ -72,8 +72,8 @@ func ActorFromUser(app core.App, u *core.Record) (*core.Record, error) {
}
domain := strings.TrimPrefix(url.Hostname(), "www.")
record.Set("username", strings.ToLower(u.GetString("username")))
record.Set("preferred_username", u.GetString("username"))
record.Set("username", u.GetString("username"))
record.Set("preferred_username", strings.ToLower(u.GetString("username")))
record.Set("domain", domain)
record.Set("summary", settings.GetString("bio"))
record.Set("published", u.GetDateTime("created"))
@@ -398,7 +398,7 @@ func ObjectFromTrail(app core.App, trail *core.Record, mentions *pub.ItemCollect
})
}
activityURL := fmt.Sprintf("%s/trail/view/@%s/%s", origin, trailAuthor.GetString("username"), trail.Id)
activityURL := fmt.Sprintf("%s/trail/view/@%s/%s", origin, trailAuthor.GetString("preferred_username"), trail.Id)
activityContent := fmt.Sprintf("<h1>%s</h1>%s<p><a href=\"%s\">%s</a></p>", trail.GetString("name"), trail.GetString("description"), activityURL, activityURL)
trailObject := pub.ObjectNew(pub.NoteType)
@@ -508,7 +508,7 @@ func ObjectFromList(app core.App, list *core.Record) (*pub.Object, error) {
}
}
activityURL := fmt.Sprintf("%s/lists/@%s/%s", origin, listAuthor.GetString("username"), list.Id)
activityURL := fmt.Sprintf("%s/lists/@%s/%s", origin, listAuthor.GetString("preferred_username"), list.Id)
activityContent := fmt.Sprintf("%s<p><a href=\"%s\">%s</a></p>", list.GetString("description"), activityURL, activityURL)
listObject := pub.ObjectNew(pub.NoteType)

View File

@@ -60,7 +60,7 @@ func documentFromTrailRecord(app core.App, r *core.Record, author *core.Record,
document := map[string]any{
"id": r.Id,
"author": author.Id,
"author_name": author.GetString("username"),
"author_name": author.GetString("preferred_username"),
"author_avatar": author.GetString("icon"),
"name": r.GetString("name"),
"description": r.GetString("description"),
@@ -174,7 +174,7 @@ func documentFromListRecord(r *core.Record, author *core.Record, includeShares b
document := map[string]interface{}{
"id": r.Id,
"author": author.Id,
"author_name": author.GetString("username"),
"author_name": author.GetString("preferred_username"),
"author_avatar": author.GetString("icon"),
"avatar": r.GetString("avatar"),
"name": r.GetString("name"),

View File

@@ -96,7 +96,7 @@ func SendNotification(app core.App, notification Notification, recipient *core.R
if err != nil {
return err
}
html, err := GenerateHTML(app.Settings().Meta.AppURL, recipientActor.GetString("username"), authorActor.GetString("username"), notification.Type, notification.Metadata)
html, err := GenerateHTML(app.Settings().Meta.AppURL, recipientActor.GetString("preferred_username"), authorActor.GetString("preferred_username"), notification.Type, notification.Metadata)
if err != nil {
return err
}

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

@@ -50,6 +50,12 @@ export async function GET(event: RequestEvent) {
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>