Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/features/communities/FindCommunity.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,9 @@ it.each([
],
[
"a Buzz relay with no community here",
Response.json({ name: "Buzz Relay" }),
new Response("relay: no community is configured for this host", {
status: 404,
}),
"No community is set up at this address.",
],
])("%s offers only Cancel", async (_label, answer, message) => {
Expand Down
21 changes: 19 additions & 2 deletions src/features/communities/find-community.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,9 @@ it.each([
[
"a Buzz relay with no community bound to this host",
{
"/": Response.json({ name: "Buzz Relay", version: "1.4.2" }),
"/api/join-policy": Response.json({}),
"/": new Response("relay: no community is configured for this host", {
status: 404,
}),
},
"no-community",
],
Expand All @@ -130,6 +131,22 @@ it.each([
},
);

it("finds a released relay that does not advertise host-bound fields", async () => {
// relay-v0.2.1 (the Helm chart's image) serves NIP-11 without
// read_state_snapshot or buzz_v1, and without icon until one is set.
await expect(
find({
"/": Response.json({
name: "Buzz Relay",
software: "https://github.com/block/buzz",
version: "0.2.1",
self,
}),
"/api/join-policy": Response.json({}),
}),
).resolves.toMatchObject({ host: "relay.example.com:8443", policy: null });
});

it.each([
["404", html(404), null],
["{}", Response.json({}), null],
Expand Down
15 changes: 8 additions & 7 deletions src/features/communities/find-community.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,16 @@ async function policyAnswer(response: Response) {
}
}

/** buzz-relay's NIP-11 answer for a host it maps to no community. */
const NO_COMMUNITY = "relay: no community is configured for this host";

async function relayInfo(response: Response) {
if (response.status >= 500) throw new FindCommunityError("unreachable");
if (
response.status === 404 &&
(await response.text().catch(() => "")) === NO_COMMUNITY
)
throw new FindCommunityError("no-community");
Comment thread
johnmatthewtennant marked this conversation as resolved.
Resolved
const body: unknown = response.ok
? await response.json().catch(() => undefined)
: undefined;
Expand All @@ -94,12 +102,5 @@ async function relayInfo(response: Response) {
)
)
throw new FindCommunityError("not-buzz");
// Host-bound fields are present only when the relay maps this host to a community.
if (
info.read_state_snapshot === undefined &&
info.icon === undefined &&
info.buzz_v1 === undefined
)
throw new FindCommunityError("no-community");
return info;
Comment thread
johnmatthewtennant marked this conversation as resolved.
Resolved
}
Loading