diff --git a/src/app/components/RoomForm.svelte b/src/app/components/RoomForm.svelte index db13cbd..ff228e3 100644 --- a/src/app/components/RoomForm.svelte +++ b/src/app/components/RoomForm.svelte @@ -170,26 +170,38 @@ {#snippet label()} -

Access Control

+ Restricted {/snippet} {#snippet input()} -
- - - Closed - - - - Private - - - - Hidden - -
+ + Only allow members to send messages {/snippet} - {#snippet info()} -

Only members can send messages to closed groups and read messages from private groups.

+
+ + {#snippet label()} + Private + {/snippet} + {#snippet input()} + + Only allow members to read messages + {/snippet} + + + {#snippet label()} + Hidden + {/snippet} + {#snippet input()} + + Hide this group from non-members + {/snippet} + + + {#snippet label()} + Closed + {/snippet} + {#snippet input()} + + Ignore requests to join {/snippet} {@render footer({loading})} diff --git a/src/app/components/SpaceAccessRequest.svelte b/src/app/components/SpaceAccessRequest.svelte index e8dced4..979c62b 100644 --- a/src/app/components/SpaceAccessRequest.svelte +++ b/src/app/components/SpaceAccessRequest.svelte @@ -14,7 +14,7 @@ import SpaceJoinConfirm, {confirmSpaceJoin} from "@app/components/SpaceJoinConfirm.svelte" import {pushToast} from "@app/util/toast" import {pushModal} from "@app/util/modal" - import {checkRelayAccess} from "@app/core/commands" + import {attemptRelayAccess} from "@app/core/commands" import {deriveSocket} from "@app/core/state" type Props = { @@ -31,7 +31,7 @@ loading = true try { - const message = await checkRelayAccess(url, claim) + const message = await attemptRelayAccess(url, claim) if (message) { return pushToast({theme: "error", message, timeout: 30_000}) diff --git a/src/app/core/commands.ts b/src/app/core/commands.ts index 155dc66..441ebbe 100644 --- a/src/app/core/commands.ts +++ b/src/app/core/commands.ts @@ -84,7 +84,6 @@ import { userRelaySelections, userInboxRelaySelections, nip44EncryptToSelf, - loadRelay, dropSession, tagEventForComment, tagEventForQuote, @@ -264,43 +263,7 @@ export const canEnforceNip70 = async (url: string) => { return socket.auth.status !== AuthStatus.None } -export const checkRelayAccess = async (url: string, claim = "") => { - const socket = Pool.get().get(url) - - await attemptAuth(url) - - const thunk = publishJoinRequest({url, claim}) - const error = await waitForThunkError(thunk) - - if (error) { - const message = - socket.auth.details?.replace(/^\w+: /, "") || - error.replace(/^\w+: /, "") || - "join request rejected" - - // If it's a strict NIP 29 relay don't worry about requesting access - // TODO: remove this if relay29 ever gets less strict - if (message === "missing group (`h`) tag") return - - // Ignore messages about the relay ignoring ours - if (error?.startsWith("mute: ")) return - - // Ignore rejected empty claims - if (!claim && error?.includes("invite code")) return - - return message - } -} - -export const checkRelayProfile = async (url: string) => { - const relay = await loadRelay(url) - - if (!relay) { - return "Sorry, we weren't able to find that relay." - } -} - -export const checkRelayConnection = async (url: string) => { +export const attemptRelayAccess = async (url: string, claim = "") => { const socket = Pool.get().get(url) socket.attemptToOpen() @@ -313,39 +276,30 @@ export const checkRelayConnection = async (url: string) => { if (socket.status !== SocketStatus.Open) { return `Failed to connect` } -} - -export const checkRelayAuth = async (url: string) => { - const socket = Pool.get().get(url) - const okStatuses = [AuthStatus.None, AuthStatus.Ok] await attemptAuth(url) // Only raise an error if it's not a timeout. // If it is, odds are the problem is with our signer, not the relay - if (!okStatuses.includes(socket.auth.status)) { + if (![AuthStatus.None, AuthStatus.Ok].includes(socket.auth.status)) { if (socket.auth.details) { return `Failed to authenticate (${socket.auth.details})` } else { return `Failed to authenticate (${last(socket.auth.status.split(":"))})` } } -} -export const attemptRelayAccess = async (url: string, claim = "") => { - const checks = [ - () => checkRelayConnection(url), - () => checkRelayAccess(url, claim), - () => checkRelayAuth(url), - ] + const thunk = publishJoinRequest({url, claim}) + const error = await waitForThunkError(thunk) - for (const check of checks) { - const error = await check() + // Ignore messages about the relay ignoring our messages + if (error?.startsWith("mute: ")) return - if (error) { - return error - } - } + // If it's a strict NIP 29 relay don't worry about requesting access + // TODO: remove this if relay29 ever gets less strict + if (error?.includes("missing group (`h`) tag")) return + + return error?.replace(/^\w+: /, "") } // Deletions diff --git a/src/routes/spaces/[relay]/[h]/+page.svelte b/src/routes/spaces/[relay]/[h]/+page.svelte index 8737312..d7f01b1 100644 --- a/src/routes/spaces/[relay]/[h]/+page.svelte +++ b/src/routes/spaces/[relay]/[h]/+page.svelte @@ -390,20 +390,22 @@

You aren't currently a member of this room.

- {#if $membershipStatus === MembershipStatus.Pending} - - {:else} - + {#if !$room?.isClosed} + {#if $membershipStatus === MembershipStatus.Pending} + + {:else} + + {/if} {/if}
@@ -452,23 +454,25 @@
{#if $room?.isPrivate && $membershipStatus !== MembershipStatus.Granted} - {:else if $room?.isClosed && $membershipStatus !== MembershipStatus.Granted} + {:else if $room?.isRestricted && $membershipStatus !== MembershipStatus.Granted}

Only members are allowed to post to this room.

- {#if $membershipStatus === MembershipStatus.Pending} - - {:else} - + {#if !$room?.isClosed} + {#if $membershipStatus === MembershipStatus.Pending} + + {:else} + + {/if} {/if}
{:else}