Improve space join flow

This commit is contained in:
Jon Staab
2026-01-08 16:01:36 -08:00
parent f86afc08fa
commit 9a0ad0c663
7 changed files with 54 additions and 55 deletions
+38 -6
View File
@@ -1,6 +1,6 @@
import {nwc} from "@getalby/sdk"
import * as nip19 from "nostr-tools/nip19"
import {get} from "svelte/store"
import {get, derived} from "svelte/store"
import type {Override, MakeOptional} from "@welshman/lib"
import {
first,
@@ -90,6 +90,7 @@ import {
getPubkeyRelays,
userBlossomServerList,
shouldUnwrap,
getThunkError,
} from "@welshman/app"
import {compressFile} from "@lib/html"
import {kv, db} from "@app/core/storage"
@@ -106,6 +107,9 @@ import {
getSetting,
userGroupList,
shouldIgnoreError,
stripPrefix,
relaysMostlyRestricted,
deriveSocket,
} from "@app/core/state"
import {loadAlertStatuses} from "@app/core/requests"
import {platform, platformName, getPushInfo} from "@app/util/push"
@@ -281,12 +285,40 @@ export const attemptRelayAccess = async (url: string, claim = "") => {
if (shouldIgnoreError(error)) return
if (claim) {
const ignoreClaimError =
error.includes("invalid invite code size") || error.includes("failed to validate invite code")
if (error.includes("invite code")) return "join request rejected"
if (!ignoreClaimError) return error?.replace(/^\w+: /, "")
}
return stripPrefix(error)
}
export const deriveRelayAuthError = (url: string, claim = "") => {
// Kick off the auth process
Pool.get().get(url).auth.attemptAuth(sign)
// Attempt to join the relay
const thunk = publishJoinRequest({url, claim})
return derived(
[thunk, relaysMostlyRestricted, deriveSocket(url)],
([$thunk, $relaysMostlyRestricted, $socket]) => {
if ($socket.auth.status === AuthStatus.Forbidden && $socket.auth.details) {
return stripPrefix($socket.auth.details)
}
if ($relaysMostlyRestricted[url]) {
return stripPrefix($relaysMostlyRestricted[url])
}
const error = getThunkError($thunk)
if (error) {
const isEmptyInvite = !claim && error.includes("invite code")
if (!shouldIgnoreError(error) && !isEmptyInvite) {
return stripPrefix(error) || "join request rejected"
}
}
},
)
}
// Deletions
+1 -39
View File
@@ -97,7 +97,6 @@ import {
getTagValue,
getTagValues,
isRelayUrl,
makeEvent,
normalizeRelayUrl,
readList,
verifyEvent,
@@ -115,12 +114,9 @@ import {
createSearch,
userFollowList,
ensurePlaintext,
sign,
signer,
makeOutboxLoader,
appContext,
getThunkError,
publishThunk,
deriveRelay,
makeUserData,
makeUserLoader,
@@ -986,41 +982,7 @@ export const shouldIgnoreError = (error: string) => {
return isIgnored || isAborted || isStrictNip29Relay
}
export const deriveRelayAuthError = (url: string, claim = "") => {
const stripPrefix = (m: string) => m.replace(/^\w+: /, "")
// Kick off the auth process
Pool.get().get(url).auth.attemptAuth(sign)
// Attempt to join the relay
const thunk = publishThunk({
event: makeEvent(RELAY_JOIN, {tags: [["claim", claim]]}),
relays: [url],
})
return derived(
[thunk, relaysMostlyRestricted, deriveSocket(url)],
([$thunk, $relaysMostlyRestricted, $socket]) => {
if ($socket.auth.status === AuthStatus.Forbidden && $socket.auth.details) {
return stripPrefix($socket.auth.details)
}
if ($relaysMostlyRestricted[url]) {
return stripPrefix($relaysMostlyRestricted[url])
}
const error = getThunkError($thunk)
if (error) {
const isEmptyInvite = !claim && error.includes("invite code")
if (!shouldIgnoreError(error) && !isEmptyInvite) {
return stripPrefix(error) || "join request rejected"
}
}
},
)
}
export const stripPrefix = (m: string) => m.replace(/^\w+: /, "")
export type InviteData = {url: string; claim: string}