Skip to content

Commit 0dda0ad

Browse files
authored
fix(desktop): preserve profile descriptions across communities (#2068)
Signed-off-by: Pavlenex <[email protected]>
1 parent f347dca commit 0dda0ad

4 files changed

Lines changed: 54 additions & 1 deletion

File tree

‎desktop/src/features/profile/hooks.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ async function persistSelfProfile(
7373
version: 1,
7474
displayName: profile.displayName,
7575
avatarUrl: profile.avatarUrl,
76+
about: profile.about,
7677
avatarDataUrl,
7778
updatedAt: Date.now(),
7879
// Only persist the presence bit when true — no-event fallbacks
@@ -106,7 +107,7 @@ export function useProfileQuery(enabled = true) {
106107
pubkey,
107108
displayName: cached.displayName,
108109
avatarUrl: cached.avatarUrl,
109-
about: null,
110+
about: cached.about,
110111
nip05Handle: null,
111112
ownerPubkey: null,
112113
// Only true when the cache entry was explicitly written with a

‎desktop/src/features/profile/lib/selfProfileStorage.test.mjs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ test("parseSelfProfileCache: valid v1 payload round-trips", () => {
5353
version: 1,
5454
displayName: "Alice",
5555
avatarUrl: "https://relay.example.com/media/abc.jpg",
56+
about: "Building better communities",
5657
avatarDataUrl: "data:image/jpeg;base64,/9j/4A==",
5758
updatedAt: 1700000000000,
5859
};
@@ -65,6 +66,7 @@ test("parseSelfProfileCache: null fields are preserved", () => {
6566
version: 1,
6667
displayName: null,
6768
avatarUrl: null,
69+
about: null,
6870
avatarDataUrl: null,
6971
updatedAt: 0,
7072
};

‎desktop/src/features/profile/lib/selfProfileStorage.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export type SelfProfileCache = {
3636
displayName: string | null;
3737
/** Original relay URL from the kind-0 profile event. */
3838
avatarUrl: string | null;
39+
about: string | null;
3940
/**
4041
* Base64 data URL captured while the relay was reachable. Capped at 256 KB
4142
* to keep localStorage usage bounded. Null if never captured or too large.
@@ -58,6 +59,7 @@ const DEFAULT_CACHE: SelfProfileCache = Object.freeze({
5859
version: 1,
5960
displayName: null,
6061
avatarUrl: null,
62+
about: null,
6163
avatarDataUrl: null,
6264
updatedAt: 0,
6365
});
@@ -85,6 +87,7 @@ export function parseSelfProfileCache(json: unknown): SelfProfileCache | null {
8587
const displayName =
8688
typeof obj.displayName === "string" ? obj.displayName : null;
8789
const avatarUrl = typeof obj.avatarUrl === "string" ? obj.avatarUrl : null;
90+
const about = typeof obj.about === "string" ? obj.about : null;
8891
// Defense-in-depth: avatarDataUrl flows into an <img src> sink; only accept
8992
// values that are provably safe image data URLs.
9093
const avatarDataUrl =
@@ -105,6 +108,7 @@ export function parseSelfProfileCache(json: unknown): SelfProfileCache | null {
105108
version: 1,
106109
displayName,
107110
avatarUrl,
111+
about,
108112
avatarDataUrl,
109113
updatedAt,
110114
...(hasProfileEvent !== undefined && { hasProfileEvent }),

‎desktop/tests/e2e/profile.spec.ts‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,52 @@ test.beforeEach(async ({ page }) => {
164164
await installMockBridge(page);
165165
});
166166

167+
test("keeps the saved profile description after a community round trip", async ({
168+
page,
169+
}) => {
170+
const communities = [
171+
{
172+
id: "profile-community-a",
173+
name: "Alpha",
174+
relayUrl: "ws://localhost:3000",
175+
addedAt: "2026-01-01T00:00:00.000Z",
176+
},
177+
{
178+
id: "profile-community-b",
179+
name: "Bravo",
180+
relayUrl: "ws://localhost:3001",
181+
addedAt: "2026-01-02T00:00:00.000Z",
182+
},
183+
];
184+
await page.addInitScript((seed) => {
185+
window.localStorage.setItem("buzz-communities", JSON.stringify(seed));
186+
window.localStorage.setItem("buzz-active-community-id", seed[0].id);
187+
}, communities);
188+
await page.goto("/");
189+
190+
const description = "Description that should survive switching";
191+
await openSettings(page, "profile");
192+
await page.getByTestId("profile-metadata-edit").click();
193+
await page.getByTestId("profile-about").fill(description);
194+
await page.getByTestId("profile-metadata-edit").click();
195+
await expect(page.getByTestId("profile-about-value")).toHaveText(description);
196+
await page.getByTestId("settings-back-to-app").click();
197+
198+
const communityA = page.getByTestId(
199+
"community-rail-button-profile-community-a",
200+
);
201+
const communityB = page.getByTestId(
202+
"community-rail-button-profile-community-b",
203+
);
204+
await communityB.click();
205+
await expect(communityB).toHaveAttribute("aria-current", "true");
206+
await communityA.click();
207+
await expect(communityA).toHaveAttribute("aria-current", "true");
208+
209+
await openSettings(page, "profile");
210+
await expect(page.getByTestId("profile-about-value")).toHaveText(description);
211+
});
212+
167213
test("updates the relay-backed profile from settings", async ({ page }) => {
168214
const stamp = Date.now();
169215
const displayName = `Tyler QA ${stamp}`;

0 commit comments

Comments
 (0)