Skip to content

armgit / alook

Public Imported from GitHub
0

Multi-Agent Collaboration for Team and Friends

fix(web): hydrate uploaded profile avatar

Gus36e55b8efb99
diff --git a/src/web/src/app/api/community/users/me/profile/route.test.ts b/src/web/src/app/api/community/users/me/profile/route.test.ts
index 4ffb8667b..c9a33fec2 100644
--- a/src/web/src/app/api/community/users/me/profile/route.test.ts
+++ b/src/web/src/app/api/community/users/me/profile/route.test.ts
@@ -83,7 +83,7 @@ describe("GET /api/community/users/me/profile", () => {
beforeEach(() => {
vi.clearAllMocks()
actorKind = "human"
- getUser.mockResolvedValue({ id: "u1", discriminator: "4242" })
+ getUser.mockResolvedValue({ id: "u1", discriminator: "4242", image: "/api/community/users/u1/avatar" })
})
it("returns defaults when no profile row exists", async () => {
@@ -92,6 +92,7 @@ describe("GET /api/community/users/me/profile", () => {
expect(res.status).toBe(200)
expect(await res.json()).toEqual({
aboutMe: "",
+ avatar: "/api/community/users/u1/avatar",
bannerColor: null,
discriminator: "4242",
statusEmoji: null,
@@ -104,6 +105,7 @@ describe("GET /api/community/users/me/profile", () => {
const res = await GET(new NextRequest("http://localhost/api/community/users/me/profile"), {} as never)
expect(await res.json()).toEqual({
aboutMe: "hi",
+ avatar: "/api/community/users/u1/avatar",
bannerColor: "#aabbcc",
discriminator: "4242",
statusEmoji: "🎧",
@@ -117,6 +119,7 @@ describe("GET /api/community/users/me/profile", () => {
const res = await GET(new NextRequest("http://localhost/api/community/users/me/profile"), {} as never)
expect(await res.json()).toEqual({
aboutMe: "",
+ avatar: "",
bannerColor: null,
discriminator: "0000",
statusEmoji: null,
diff --git a/src/web/src/app/api/community/users/me/profile/route.ts b/src/web/src/app/api/community/users/me/profile/route.ts
index 0f72f53d7..9a5ca6779 100644
--- a/src/web/src/app/api/community/users/me/profile/route.ts
+++ b/src/web/src/app/api/community/users/me/profile/route.ts
@@ -30,6 +30,7 @@ export const GET = withCommunityActor(async (_req, ctx) => {
])
return writeJSON({
aboutMe: profile?.aboutMe ?? "",
+ avatar: viewer?.image ?? "",
bannerColor: profile?.bannerColor ?? null,
discriminator: viewer?.discriminator ?? "0000",
statusEmoji: profile?.statusEmoji ?? null,
diff --git a/src/web/src/app/c/community-shell.tsx b/src/web/src/app/c/community-shell.tsx
index 54d599bc2..96f3820e7 100644
--- a/src/web/src/app/c/community-shell.tsx
+++ b/src/web/src/app/c/community-shell.tsx
@@ -59,20 +59,19 @@ function CommunityBootstrap({ children }: { children: ReactNode }) {
// flag stuck at false for the viewer's own reactions.
useCommunityWs({ viewerUserId: currentUser.id })
- // Hydrate `aboutMe`/status — the community identity holds email/name/avatar
- // from the session, but the free-text "about me" and custom status live on
- // the community profile row. Fetch it once so the settings dialog and
- // UserBar/ProfileCard open pre-filled instead of blank until the next save
- // or WS event (see plans/profile-card.md).
+ // Hydrate the live public profile. The auth session can retain a stale image
+ // after an avatar upload, while this self endpoint reads the canonical user
+ // row alongside the community profile fields.
const currentUserId = currentUser.id
useEffect(() => {
- apiFetch<{ aboutMe: string; discriminator: string; statusEmoji: string | null; statusText: string }>(
+ apiFetch<{ aboutMe: string; avatar: string; discriminator: string; statusEmoji: string | null; statusText: string }>(
"/api/community/users/me/profile",
)
.then((data) => {
setCurrentUser((u) => ({
...u,
aboutMe: data.aboutMe,
+ avatar: data.avatar || u.avatar,
discriminator: data.discriminator,
statusEmoji: data.statusEmoji,
statusText: data.statusText,