From 8bf8642703986e7aea9bdeafead016d12c8cccc4 Mon Sep 17 00:00:00 2001 From: Christian Beutel <> Date: Tue, 24 Jun 2025 17:55:59 +0200 Subject: [PATCH] switches username and preferred_username --- db/federation/actor.go | 2 +- db/federation/announce.go | 4 +- db/federation/create.go | 12 ++-- db/federation/follow.go | 2 +- db/federation/like.go | 4 +- .../1750774093_swap_preferred_username.go | 58 +++++++++++++++++++ db/migrations/1750780092_updated_timeline.go | 40 +++++++++++++ db/util/activitypub.go | 10 ++-- db/util/meilisearch.go | 4 +- db/util/notification.go | 2 +- web/src/lib/components/actor_search.svelte | 8 +-- web/src/lib/components/base/editor.svelte | 6 +- .../components/comment/comment_card.svelte | 2 +- web/src/lib/components/list/list_card.svelte | 2 +- web/src/lib/components/list/list_panel.svelte | 2 +- .../components/list/list_share_modal.svelte | 4 +- .../notification/notification_card.svelte | 2 +- .../components/profile/activity_card.svelte | 2 +- web/src/lib/components/share_info.svelte | 4 +- .../summit_log/summit_log_card.svelte | 2 +- .../summit_log/summit_log_table_row.svelte | 6 +- .../lib/components/trail/trail_card.svelte | 4 +- .../components/trail/trail_info_panel.svelte | 2 +- .../components/trail/trail_list_item.svelte | 2 +- .../lib/components/trail/trail_table.svelte | 4 +- web/src/lib/stores/list_store.ts | 2 +- web/src/lib/stores/trail_store.ts | 2 +- web/src/lib/util/activitypub_util.ts | 4 +- web/src/routes/+page.svelte | 8 +-- .../v1/activitypub/user/[handle]/+server.ts | 2 +- web/src/routes/api/v1/comment/+server.ts | 10 +++- .../api/v1/profile/[handle]/lists/+server.ts | 2 +- .../api/v1/profile/[handle]/stats/+server.ts | 2 +- .../v1/profile/[handle]/timeline/+server.ts | 2 +- .../api/v1/profile/[handle]/trails/+server.ts | 2 +- web/src/routes/api/v1/trail/[id]/+server.ts | 3 +- .../routes/profile/[handle]/+layout.svelte | 6 +- web/src/routes/profile/[handle]/+page.svelte | 2 +- .../[handle]/users/[type]/+page.svelte | 8 +-- 39 files changed, 175 insertions(+), 70 deletions(-) create mode 100644 db/migrations/1750774093_swap_preferred_username.go create mode 100644 db/migrations/1750780092_updated_timeline.go diff --git a/db/federation/actor.go b/db/federation/actor.go index c048f849..d678e31a 100644 --- a/db/federation/actor.go +++ b/db/federation/actor.go @@ -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 { diff --git a/db/federation/announce.go b/db/federation/announce.go index e757b61d..8a921c09 100644 --- a/db/federation/announce.go +++ b/db/federation/announce.go @@ -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, diff --git a/db/federation/create.go b/db/federation/create.go index b8a5b382..55626669 100644 --- a/db/federation/create.go +++ b/db/federation/create.go @@ -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, diff --git a/db/federation/follow.go b/db/federation/follow.go index 33b4c6c6..620bd6f9 100644 --- a/db/federation/follow.go +++ b/db/federation/follow.go @@ -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, diff --git a/db/federation/like.go b/db/federation/like.go index 107e940d..cadd2409 100644 --- a/db/federation/like.go +++ b/db/federation/like.go @@ -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, diff --git a/db/migrations/1750774093_swap_preferred_username.go b/db/migrations/1750774093_swap_preferred_username.go new file mode 100644 index 00000000..963cd904 --- /dev/null +++ b/db/migrations/1750774093_swap_preferred_username.go @@ -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 + }) +} diff --git a/db/migrations/1750780092_updated_timeline.go b/db/migrations/1750780092_updated_timeline.go new file mode 100644 index 00000000..e25b371c --- /dev/null +++ b/db/migrations/1750780092_updated_timeline.go @@ -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) + }) +} diff --git a/db/util/activitypub.go b/db/util/activitypub.go index ba424e2a..29d1eb3c 100644 --- a/db/util/activitypub.go +++ b/db/util/activitypub.go @@ -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("

%s

%s

%s

", 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

%s

", list.GetString("description"), activityURL, activityURL) listObject := pub.ObjectNew(pub.NoteType) diff --git a/db/util/meilisearch.go b/db/util/meilisearch.go index 5970c9c4..7c613948 100644 --- a/db/util/meilisearch.go +++ b/db/util/meilisearch.go @@ -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"), diff --git a/db/util/notification.go b/db/util/notification.go index a339fccb..1a52bcad 100644 --- a/db/util/notification.go +++ b/db/util/notification.go @@ -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 } diff --git a/web/src/lib/components/actor_search.svelte b/web/src/lib/components/actor_search.svelte index cb7a0d64..e018baa6 100644 --- a/web/src/lib/components/actor_search.svelte +++ b/web/src/lib/components/actor_search.svelte @@ -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 @@ avatar {/snippet} diff --git a/web/src/lib/components/base/editor.svelte b/web/src/lib/components/base/editor.svelte index 3fc2b048..2da3c1fe 100644 --- a/web/src/lib/components/base/editor.svelte +++ b/web/src/lib/components/base/editor.svelte @@ -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); diff --git a/web/src/lib/components/comment/comment_card.svelte b/web/src/lib/components/comment/comment_card.svelte index dd2ca1f9..5696d373 100644 --- a/web/src/lib/components/comment/comment_card.svelte +++ b/web/src/lib/components/comment/comment_card.svelte @@ -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 ?? ""))); diff --git a/web/src/lib/components/list/list_card.svelte b/web/src/lib/components/list/list_card.svelte index 9aaa1f33..0de89d9d 100644 --- a/web/src/lib/components/list/list_card.svelte +++ b/web/src/lib/components/list/list_card.svelte @@ -66,7 +66,7 @@ avatar {handleFromRecordWithIRI(list)} diff --git a/web/src/lib/components/list/list_panel.svelte b/web/src/lib/components/list/list_panel.svelte index d76ad587..c048876d 100644 --- a/web/src/lib/components/list/list_panel.svelte +++ b/web/src/lib/components/list/list_panel.svelte @@ -143,7 +143,7 @@ avatar

- {`@${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}`}

diff --git a/web/src/lib/components/share_info.svelte b/web/src/lib/components/share_info.svelte index c14649f2..c3f0bb91 100644 --- a/web/src/lib/components/share_info.svelte +++ b/web/src/lib/components/share_info.svelte @@ -53,7 +53,7 @@ avatar

@@ -82,7 +82,7 @@ avatar

diff --git a/web/src/lib/components/summit_log/summit_log_card.svelte b/web/src/lib/components/summit_log/summit_log_card.svelte index 5cb19569..a490292d 100644 --- a/web/src/lib/components/summit_log/summit_log_card.svelte +++ b/web/src/lib/components/summit_log/summit_log_card.svelte @@ -103,7 +103,7 @@ avatar {handleFromRecordWithIRI(log)} diff --git a/web/src/lib/components/summit_log/summit_log_table_row.svelte b/web/src/lib/components/summit_log/summit_log_table_row.svelte index b44eb589..41bf2da6 100644 --- a/web/src/lib/components/summit_log/summit_log_table_row.svelte +++ b/web/src/lib/components/summit_log/summit_log_table_row.svelte @@ -189,13 +189,13 @@

diff --git a/web/src/lib/components/trail/trail_card.svelte b/web/src/lib/components/trail/trail_card.svelte index 87260a9b..1fd714cc 100644 --- a/web/src/lib/components/trail/trail_card.svelte +++ b/web/src/lib/components/trail/trail_card.svelte @@ -130,10 +130,10 @@ avatar - {trail.expand.author.username}{trail.expand.author.isLocal + {trail.expand.author.preferred_username}{trail.expand.author.isLocal ? "" : "@" + trail.expand.author.domain}

diff --git a/web/src/lib/components/trail/trail_info_panel.svelte b/web/src/lib/components/trail/trail_info_panel.svelte index 1f0e054d..3feaf294 100644 --- a/web/src/lib/components/trail/trail_info_panel.svelte +++ b/web/src/lib/components/trail/trail_info_panel.svelte @@ -377,7 +377,7 @@ avatar {handleFromRecordWithIRI(trail)} diff --git a/web/src/lib/components/trail/trail_table.svelte b/web/src/lib/components/trail/trail_table.svelte index eab2ea8a..d11d7488 100644 --- a/web/src/lib/components/trail/trail_table.svelte +++ b/web/src/lib/components/trail/trail_table.svelte @@ -88,10 +88,10 @@ {#if trail.expand && trail.expand.author}
avatar
diff --git a/web/src/lib/stores/list_store.ts b/web/src/lib/stores/list_store.ts index 5b440914..9d3b52b2 100644 --- a/web/src/lib/stores/list_store.ts +++ b/web/src/lib/stores/list_store.ts @@ -275,7 +275,7 @@ export async function searchResultToLists(hits: Hits): 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", diff --git a/web/src/lib/stores/trail_store.ts b/web/src/lib/stores/trail_store.ts index 6625359b..71f0a254 100644 --- a/web/src/lib/stores/trail_store.ts +++ b/web/src/lib/stores/trail_store.ts @@ -477,7 +477,7 @@ export async function searchResultToTrailList(hits: Hits): 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 => ({ diff --git a/web/src/lib/util/activitypub_util.ts b/web/src/lib/util/activitypub_util.ts index a6c5e24f..20bf1b83 100644 --- a/web/src/lib/util/activitypub_util.ts +++ b/web/src/lib/util/activitypub_util.ts @@ -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}` } \ No newline at end of file diff --git a/web/src/routes/+page.svelte b/web/src/routes/+page.svelte index c5365da0..e11f0885 100644 --- a/web/src/routes/+page.svelte +++ b/web/src/routes/+page.svelte @@ -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}`); diff --git a/web/src/routes/api/v1/activitypub/user/[handle]/+server.ts b/web/src/routes/api/v1/activitypub/user/[handle]/+server.ts index 1da4e2ae..256c44f1 100644 --- a/web/src/routes/api/v1/activitypub/user/[handle]/+server.ts +++ b/web/src/routes/api/v1/activitypub/user/[handle]/+server.ts @@ -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}`, diff --git a/web/src/routes/api/v1/comment/+server.ts b/web/src/routes/api/v1/comment/+server.ts index 4c38a880..a4cc1c3d 100644 --- a/web/src/routes/api/v1/comment/+server.ts +++ b/web/src/routes/api/v1/comment/+server.ts @@ -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 = >{ items: localComments.items.concat(remoteComments.items), page: localComments.page, diff --git a/web/src/routes/api/v1/profile/[handle]/lists/+server.ts b/web/src/routes/api/v1/profile/[handle]/lists/+server.ts index ad87b93b..14f9d37c 100644 --- a/web/src/routes/api/v1/profile/[handle]/lists/+server.ts +++ b/web/src/routes/api/v1/profile/[handle]/lists/+server.ts @@ -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) { diff --git a/web/src/routes/api/v1/profile/[handle]/stats/+server.ts b/web/src/routes/api/v1/profile/[handle]/stats/+server.ts index 068ad756..4559a66a 100644 --- a/web/src/routes/api/v1/profile/[handle]/stats/+server.ts +++ b/web/src/routes/api/v1/profile/[handle]/stats/+server.ts @@ -22,7 +22,7 @@ export async function GET(event: RequestEvent) { .getList(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() diff --git a/web/src/routes/api/v1/profile/[handle]/timeline/+server.ts b/web/src/routes/api/v1/profile/[handle]/timeline/+server.ts index 646ba045..06c3d07b 100644 --- a/web/src/routes/api/v1/profile/[handle]/timeline/+server.ts +++ b/web/src/routes/api/v1/profile/[handle]/timeline/+server.ts @@ -23,7 +23,7 @@ export async function GET(event: RequestEvent) { .getList(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) { diff --git a/web/src/routes/api/v1/profile/[handle]/trails/+server.ts b/web/src/routes/api/v1/profile/[handle]/trails/+server.ts index bdeafc70..40b1492e 100644 --- a/web/src/routes/api/v1/profile/[handle]/trails/+server.ts +++ b/web/src/routes/api/v1/profile/[handle]/trails/+server.ts @@ -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) { diff --git a/web/src/routes/api/v1/trail/[id]/+server.ts b/web/src/routes/api/v1/trail/[id]/+server.ts index 388ddb51..1874a068 100644 --- a/web/src/routes/api/v1/trail/[id]/+server.ts +++ b/web/src/routes/api/v1/trail/[id]/+server.ts @@ -32,7 +32,8 @@ export async function GET(event: RequestEvent) { } t = { iri: iri, - author: actor.id + author: actor.id, + like_count: 0 } as Trail } diff --git a/web/src/routes/profile/[handle]/+layout.svelte b/web/src/routes/profile/[handle]/+layout.svelte index 0be3b72b..642a7c44 100644 --- a/web/src/routes/profile/[handle]/+layout.svelte +++ b/web/src/routes/profile/[handle]/+layout.svelte @@ -64,13 +64,13 @@ avatar

- {data.profile.preferredUsername ?? - data.profile.username} + {data.profile.username ?? + "?"}

{data.profile.acct} diff --git a/web/src/routes/profile/[handle]/+page.svelte b/web/src/routes/profile/[handle]/+page.svelte index dcf077f8..1a9f7130 100644 --- a/web/src/routes/profile/[handle]/+page.svelte +++ b/web/src/routes/profile/[handle]/+page.svelte @@ -69,7 +69,7 @@