Skip to content

Commit 1229336

Browse files
committed
Auto-connect configured production relay
1 parent 6d04d27 commit 1229336

3 files changed

Lines changed: 32 additions & 2 deletions

File tree

‎desktop/src/features/communities/communityStorage.test.mjs‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import test from "node:test";
44
import {
55
clearCommunityStorage,
66
migrateLegacyCommunityStorage,
7+
shouldAutoConnectDefaultRelay,
78
} from "./communityStorage.ts";
89

910
function createMemoryStorage(initial = {}) {
@@ -46,6 +47,16 @@ test("migrateLegacyCommunityStorage does not overwrite new community state", ()
4647
assert.equal(storage.getItem("buzz-active-community-id"), "new");
4748
});
4849

50+
test("signed-build relay defaults auto-connect during first-run onboarding", () => {
51+
assert.equal(
52+
shouldAutoConnectDefaultRelay("wss://buzz.block.builderlab.xyz"),
53+
true,
54+
);
55+
assert.equal(shouldAutoConnectDefaultRelay("ws://localhost:3000"), false);
56+
assert.equal(shouldAutoConnectDefaultRelay("ws://127.0.0.1:3000"), false);
57+
assert.equal(shouldAutoConnectDefaultRelay("not a valid relay"), false);
58+
});
59+
4960
test("clearCommunityStorage removes new and legacy state", () => {
5061
const storage = createMemoryStorage({
5162
"buzz-communities": "new",

‎desktop/src/features/communities/communityStorage.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,15 @@ export function normalizeRelayUrl(url: string): string {
108108
return url;
109109
}
110110

111+
export function shouldAutoConnectDefaultRelay(relayUrl: string): boolean {
112+
try {
113+
const parsed = new URL(normalizeRelayUrl(relayUrl));
114+
return parsed.hostname !== "localhost" && parsed.hostname !== "127.0.0.1";
115+
} catch {
116+
return false;
117+
}
118+
}
119+
111120
export function deriveCommunityName(relayUrl: string): string {
112121
try {
113122
const url = new URL(

‎desktop/src/features/communities/useCommunityInit.ts‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ import { resetSidebarRelayConnectionCardState } from "@/features/sidebar/ui/useS
2323
import { clearMarkdownNodeCache } from "@/shared/ui/markdown/nodeCache";
2424
import { resetVideoPlayerState } from "@/shared/ui/videoPlayerState";
2525

26-
import { initFirstCommunity } from "./communityStorage";
26+
import {
27+
initFirstCommunity,
28+
shouldAutoConnectDefaultRelay,
29+
} from "./communityStorage";
2730
import type { Community } from "./types";
2831

2932
/**
@@ -94,7 +97,14 @@ export function useCommunityInit(
9497
try {
9598
const defaultRelayUrl = await getDefaultRelayUrl();
9699

97-
if (isSharedIdentity) {
100+
// Signed builds carry a reviewed production relay. Treat that as the
101+
// user's first community so first-run onboarding proceeds directly
102+
// from machine setup into profile/team setup. Local development keeps
103+
// the explicit add-a-community flow for ws://localhost defaults.
104+
if (
105+
isSharedIdentity ||
106+
shouldAutoConnectDefaultRelay(defaultRelayUrl)
107+
) {
98108
const identity = await getIdentity();
99109
if (cancelled) return;
100110
initFirstCommunity(defaultRelayUrl, identity.pubkey);

0 commit comments

Comments
 (0)