Support invite links on discover page

This commit is contained in:
Jon Staab
2025-11-04 16:39:34 -08:00
parent 806a7c2609
commit 2d89ca6c0e
3 changed files with 46 additions and 33 deletions
+2 -20
View File
@@ -1,7 +1,5 @@
<script lang="ts">
import type {Snippet} from "svelte"
import {tryCatch, fromPairs} from "@welshman/lib"
import {isRelayUrl, normalizeRelayUrl} from "@welshman/util"
import {Pool, AuthStatus} from "@welshman/net"
import {preventDefault} from "@lib/html"
import {slideAndFade} from "@lib/transition"
@@ -19,6 +17,7 @@
import {pushToast} from "@app/util/toast"
import {pushModal} from "@app/util/modal"
import {attemptRelayAccess} from "@app/core/commands"
import {parseInviteLink} from "@app/core/state"
type Props = {
invite: string
@@ -57,24 +56,7 @@
let loading = $state(false)
const inviteData = $derived.by(
() =>
tryCatch(() => {
const {r: relay = "", c: claim = ""} = fromPairs(Array.from(new URL(invite).searchParams))
const url = normalizeRelayUrl(relay)
if (isRelayUrl(url)) {
return {url, claim}
}
}) ||
tryCatch(() => {
const url = normalizeRelayUrl(invite)
if (isRelayUrl(url)) {
return {url, claim: ""}
}
}),
)
const inviteData = $derived(parseInviteLink(invite))
</script>
<form class="column gap-4" onsubmit={preventDefault(join)}>
+20
View File
@@ -25,6 +25,7 @@ import {
groupBy,
always,
tryCatch,
fromPairs,
} from "@welshman/lib"
import type {Socket} from "@welshman/net"
import {
@@ -1004,3 +1005,22 @@ export const deriveRelayAuthError = (url: string, claim = "") => {
},
)
}
export type InviteData = {url: string; claim: string}
export const parseInviteLink = (invite: string): InviteData | undefined =>
tryCatch(() => {
const {r: relay = "", c: claim = ""} = fromPairs(Array.from(new URL(invite).searchParams))
const url = normalizeRelayUrl(relay)
if (isRelayUrl(url)) {
return {url, claim}
}
}) ||
tryCatch(() => {
const url = normalizeRelayUrl(invite)
if (isRelayUrl(url)) {
return {url, claim: ""}
}
})