Skip to content

Commit c5efeda

Browse files
gotankersleyBradGroux
authored andcommitted
fix(desktop): migrate legacy welcome marker keys
Co-authored-by: Brad Groux <bradgroux@hotmail.com> Signed-off-by: Brad Groux <bradgroux@hotmail.com>
1 parent e200e5f commit c5efeda

3 files changed

Lines changed: 53 additions & 6 deletions

File tree

desktop/src/features/onboarding/welcome.test.mjs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,26 @@ test("Welcome ensured marker canonicalizes relay URL differences", () => {
302302
}
303303
});
304304

305+
test("Welcome ensured marker migrates the legacy raw relay URL key", () => {
306+
const { restore } = installWindowSessionStorage();
307+
try {
308+
const rawRelayUrl = "WSS://Community-A.Example/";
309+
const legacyKey = `buzz-welcome-channel-ensured.v2:${encodeURIComponent(rawRelayUrl)}:pubkey-a`;
310+
window.localStorage.setItem(legacyKey, "true");
311+
312+
assert.equal(
313+
hasEnsuredWelcomeChannel("pubkey-a", rawRelayUrl),
314+
true,
315+
);
316+
assert.equal(
317+
hasEnsuredWelcomeChannel("pubkey-a", "wss://community-a.example"),
318+
true,
319+
);
320+
} finally {
321+
restore();
322+
}
323+
});
324+
305325
test("ensureStarterChannels reuses existing open starter channels", async () => {
306326
const general = makeChannel({
307327
id: "general-channel",

desktop/src/features/onboarding/welcome.ts

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,15 @@ export function welcomeChannelEnsuredStorageKey(
291291
)}:${pubkey}`;
292292
}
293293

294+
function legacyWelcomeChannelEnsuredStorageKey(
295+
pubkey: string,
296+
communityScope: string,
297+
) {
298+
return `${WELCOME_CHANNEL_ENSURED_STORAGE_KEY}:${encodeURIComponent(
299+
communityScope,
300+
)}:${pubkey}`;
301+
}
302+
294303
export function hasEnsuredWelcomeChannel(
295304
pubkey: string | null | undefined,
296305
communityScope: string | null | undefined,
@@ -300,11 +309,29 @@ export function hasEnsuredWelcomeChannel(
300309
}
301310

302311
try {
303-
return (
304-
window.localStorage.getItem(
305-
welcomeChannelEnsuredStorageKey(pubkey, communityScope),
306-
) === "true"
312+
const canonicalKey = welcomeChannelEnsuredStorageKey(
313+
pubkey,
314+
communityScope,
307315
);
316+
if (window.localStorage.getItem(canonicalKey) === "true") {
317+
return true;
318+
}
319+
320+
// Existing installs wrote the raw relay URL into this key. Migrate the
321+
// exact legacy marker while the configured URL is still unchanged, so a
322+
// later formatting-only edit cannot trigger one final duplicate team.
323+
const legacyKey = legacyWelcomeChannelEnsuredStorageKey(
324+
pubkey,
325+
communityScope,
326+
);
327+
if (
328+
legacyKey !== canonicalKey &&
329+
window.localStorage.getItem(legacyKey) === "true"
330+
) {
331+
window.localStorage.setItem(canonicalKey, "true");
332+
return true;
333+
}
334+
return false;
308335
} catch {
309336
return false;
310337
}

desktop/src/features/onboarding/welcomeGuide.test.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ test("starter matching uses persona identity rather than display name", () => {
331331
);
332332
});
333333

334-
test("starter matching is relay scoped and normalizes trailing slashes", () => {
334+
test("starter matching is relay scoped and canonicalizes URL formatting", () => {
335335
const pollen = WELCOME_TEAM_STARTERS[2];
336336
const otherRelay = makeAgent({
337337
personaId: pollen.personaId,
@@ -340,7 +340,7 @@ test("starter matching is relay scoped and normalizes trailing slashes", () => {
340340
});
341341
const matchingRelay = makeAgent({
342342
personaId: pollen.personaId,
343-
relayUrl: `${RELAY_A}/`,
343+
relayUrl: `${RELAY_A.toUpperCase()}/`,
344344
pubkey: PUB_B,
345345
});
346346

0 commit comments

Comments
 (0)