Skip to content

armgit / alook

Public Imported from GitHub
0

Multi-Agent Collaboration for Team and Friends

fix(community): show correct self profile from UserBar on /c/me (#377)

Generec7f57547089
diff --git a/src/web/src/components/community/profile-lookup.test.ts b/src/web/src/components/community/profile-lookup.test.ts
index 4742aadcf..9ab479906 100644
--- a/src/web/src/components/community/profile-lookup.test.ts
+++ b/src/web/src/components/community/profile-lookup.test.ts
@@ -1,6 +1,7 @@
import { describe, it, expect } from "vitest"
-import { resolveProfileTarget } from "./profile-lookup"
+import { resolveProfileTarget, buildSelfProfile } from "./profile-lookup"
import type { Member, Friend } from "./_types"
+import type { CurrentUser } from "@/contexts/community/current-user"
function member(overrides: Partial<Member>): Member {
return {
@@ -46,3 +47,39 @@ describe("resolveProfileTarget", () => {
expect(resolveProfileTarget([], [friend], { name: "Ren", userId: "user_c" })).toBe(friend)
})
})
+
+function currentUser(overrides: Partial<CurrentUser> = {}): CurrentUser {
+ return {
+ id: overrides.id ?? "user_self",
+ name: overrides.name ?? "Me",
+ email: overrides.email ?? "[email protected]",
+ avatar: overrides.avatar ?? "M",
+ aboutMe: overrides.aboutMe,
+ discriminator: overrides.discriminator,
+ statusEmoji: overrides.statusEmoji,
+ statusText: overrides.statusText,
+ }
+}
+
+describe("buildSelfProfile", () => {
+ it("builds the viewer's own card from currentUser, independent of any member/friend list — regression for the /c/me UserBar bug where a same-named friend was shown instead of the viewer", () => {
+ const me = currentUser({ id: "user_self", name: "Ren", discriminator: "0001", aboutMe: "hi" })
+ const profile = buildSelfProfile(me, new Set())
+
+ expect(profile.userId).toBe("user_self")
+ expect(profile.name).toBe("Ren")
+ expect(profile.discriminator).toBe("0001")
+ expect(profile.about).toBe("hi")
+ expect(profile.role).toBe("You")
+ })
+
+ it("always resolves self presence to online, even when the viewer's id is absent from the online set", () => {
+ const profile = buildSelfProfile(currentUser({ id: "user_self" }), new Set())
+ expect(profile.presence).toBe("online")
+ })
+
+ it("falls back to an avatar initial when the viewer has no avatar", () => {
+ const profile = buildSelfProfile(currentUser({ name: "alice", avatar: "" }), new Set())
+ expect(profile.avatar).toBe("A")
+ })
+})
diff --git a/src/web/src/components/community/profile-lookup.ts b/src/web/src/components/community/profile-lookup.ts
index 49243eaec..2b30da691 100644
--- a/src/web/src/components/community/profile-lookup.ts
+++ b/src/web/src/components/community/profile-lookup.ts
@@ -1,4 +1,33 @@
-import type { Member, Friend } from "./_types"
+import type { Member, Friend, Profile } from "./_types"
+import type { CurrentUser } from "@/contexts/community/current-user"
+import { resolveProfilePresence } from "@/lib/community/presence"
+import { avatarInitial } from "@/lib/community/avatar"
+
+/**
+ * The signed-in viewer's own profile card, built straight from `currentUser`.
+ *
+ * A profile-card click that already knows it targets the viewer (UserBar, or
+ * any caller passing the viewer's own userId) resolves here instead of through
+ * `resolveProfileTarget`. Name-based resolution can't be trusted for self: the
+ * viewer's own member row only exists in `members` while a server is active, so
+ * on `/c/me` the name-only fallback would match a same-named friend (or miss
+ * entirely) and show the wrong person.
+ */
+export function buildSelfProfile(
+ currentUser: CurrentUser,
+ onlineUserIds: ReadonlySet<string>,
+): Profile {
+ return {
+ name: currentUser.name,
+ userId: currentUser.id,
+ discriminator: currentUser.discriminator,
+ avatar: currentUser.avatar || avatarInitial(currentUser.name),
+ role: "You",
+ about: currentUser.aboutMe ?? "",
+ mutual: 0,
+ presence: resolveProfilePresence(true, undefined, onlineUserIds),
+ }
+}
/**
* Resolves the exact member/friend a profile-card click refers to.
diff --git a/src/web/src/components/community/shell-frame.tsx b/src/web/src/components/community/shell-frame.tsx
index b7358cda1..5f5ba3398 100644
--- a/src/web/src/components/community/shell-frame.tsx
+++ b/src/web/src/components/community/shell-frame.tsx
@@ -23,7 +23,7 @@ import { ImageLightbox } from "./image-lightbox"
import { ImageCropDialog } from "./image-crop-dialog"
import { validateIconSourceFile } from "@/lib/community/image-crop"
import type { MobileZone, Profile, View } from "./_types"
-import { resolveProfileTarget } from "./profile-lookup"
+import { resolveProfileTarget, buildSelfProfile } from "./profile-lookup"
import { resolveProfilePresence } from "@/lib/community/presence"
import { avatarInitial } from "@/lib/community/avatar"
import { signOut } from "@/lib/auth-client"
@@ -310,18 +310,8 @@ export function ShellFrame({
(name: string, e: React.MouseEvent, discriminator?: string, targetUserId?: string) => {
const isSelf = !!targetUserId && targetUserId === currentUser.id
if (isSelf) {
- const data: Profile = {
- name: currentUser.name,
- userId: currentUser.id,
- discriminator: currentUser.discriminator,
- avatar: currentUser.avatar || avatarInitial(currentUser.name),
- role: "You",
- about: currentUser.aboutMe ?? "",
- mutual: 0,
- presence: resolveProfilePresence(true, undefined, onlineUserIds),
- }
setProfile({
- data,
+ data: buildSelfProfile(currentUser, onlineUserIds),
x: e.clientX,
y: e.clientY,
initialStatusEmoji: currentUser.statusEmoji ?? null,
diff --git a/src/web/src/components/community/user-bar.tsx b/src/web/src/components/community/user-bar.tsx
index 16fc5714b..fd3cfb744 100644
--- a/src/web/src/components/community/user-bar.tsx
+++ b/src/web/src/components/community/user-bar.tsx
@@ -36,10 +36,10 @@ function Inner({ user, onOpenProfile, onEditProfile, inbox, hasUnread }: {
}) {
return (
<div className="flex flex-1 items-center gap-2">
- <button onClick={(e) => onOpenProfile?.(user.name, e)} className="shrink-0 rounded-full focus-visible:ring-2 focus-visible:ring-ring focus-visible:outline-none">
+ <button onClick={(e) => onOpenProfile?.(user.name, e, undefined, user.id)} className="shrink-0 rounded-full focus-visible:ring-2 focus-visible:ring-ring focus-visible:outline-none">
<Avatar label={user.avatar} seed={user.id} size={28} presence={resolveProfilePresence(true, user.id, EMPTY_ONLINE_SET)} ringColor="var(--muted)" />
</button>
- <button onClick={(e) => onOpenProfile?.(user.name, e)} className="min-w-0 flex-1 text-left rounded focus-visible:ring-2 focus-visible:ring-ring focus-visible:outline-none">
+ <button onClick={(e) => onOpenProfile?.(user.name, e, undefined, user.id)} className="min-w-0 flex-1 text-left rounded focus-visible:ring-2 focus-visible:ring-ring focus-visible:outline-none">
<div className="truncate text-sm font-medium leading-tight">{user.name}</div>
</button>
<div className="flex items-center gap-1">