2024-08-16 19:42:00 +00:00
|
|
|
<script lang="ts">
|
2026-02-19 19:08:06 +00:00
|
|
|
import {debounce} from "throttle-debounce"
|
|
|
|
|
import {dissoc, maybe} from "@welshman/lib"
|
2025-02-04 03:28:29 +00:00
|
|
|
import {preventDefault} from "@lib/html"
|
2025-09-06 00:20:12 +00:00
|
|
|
import {slideAndFade} from "@lib/transition"
|
2024-08-16 19:42:00 +00:00
|
|
|
import Spinner from "@lib/components/Spinner.svelte"
|
|
|
|
|
import Button from "@lib/components/Button.svelte"
|
|
|
|
|
import Field from "@lib/components/Field.svelte"
|
2025-09-10 22:26:39 +00:00
|
|
|
import LinkRound from "@assets/icons/link-round.svg?dataurl"
|
|
|
|
|
import AltArrowLeft from "@assets/icons/alt-arrow-left.svg?dataurl"
|
|
|
|
|
import AltArrowRight from "@assets/icons/alt-arrow-right.svg?dataurl"
|
2024-08-16 19:42:00 +00:00
|
|
|
import Icon from "@lib/components/Icon.svelte"
|
2026-02-19 19:08:06 +00:00
|
|
|
import Scanner from "@lib/components/Scanner.svelte"
|
|
|
|
|
import QrCode from "@assets/icons/qr-code.svg?dataurl"
|
2026-01-30 22:14:12 +00:00
|
|
|
import Modal from "@lib/components/Modal.svelte"
|
|
|
|
|
import ModalBody from "@lib/components/ModalBody.svelte"
|
2024-10-09 23:11:23 +00:00
|
|
|
import ModalHeader from "@lib/components/ModalHeader.svelte"
|
2026-02-02 18:09:14 +00:00
|
|
|
import ModalTitle from "@lib/components/ModalTitle.svelte"
|
|
|
|
|
import ModalSubtitle from "@lib/components/ModalSubtitle.svelte"
|
2024-10-11 00:15:20 +00:00
|
|
|
import ModalFooter from "@lib/components/ModalFooter.svelte"
|
2025-09-06 00:20:12 +00:00
|
|
|
import RelaySummary from "@app/components/RelaySummary.svelte"
|
2026-07-04 00:17:57 +00:00
|
|
|
import SpaceJoinNotifications from "@app/components/SpaceJoinNotifications.svelte"
|
|
|
|
|
import SpaceJoinStatus from "@app/components/SpaceJoinStatus.svelte"
|
2026-06-08 21:14:40 +00:00
|
|
|
import {pushToast} from "@app/toast"
|
2026-06-16 22:04:39 +00:00
|
|
|
import {goToSpace} from "@app/routes"
|
2026-06-08 22:33:38 +00:00
|
|
|
import {relaysMostlyRestricted} from "@app/policies"
|
|
|
|
|
import {notificationSettings, setSpaceNotifications} from "@app/settings"
|
|
|
|
|
import {parseInviteLink} from "@app/invites"
|
2026-06-08 21:14:40 +00:00
|
|
|
import {Push} from "@app/push"
|
2026-06-08 22:33:38 +00:00
|
|
|
import {attemptRelayAccess} from "@app/relays"
|
|
|
|
|
import {addSpace} from "@app/groups"
|
|
|
|
|
import {broadcastUserData} from "@app/profiles"
|
2024-08-16 19:42:00 +00:00
|
|
|
|
2025-09-06 00:20:12 +00:00
|
|
|
type Props = {
|
|
|
|
|
invite: string
|
2026-01-30 22:14:12 +00:00
|
|
|
back?: () => void
|
2026-07-04 00:01:37 +00:00
|
|
|
hideHeader?: boolean
|
2025-09-06 00:20:12 +00:00
|
|
|
}
|
2025-05-20 16:35:33 +00:00
|
|
|
|
2026-07-04 00:01:37 +00:00
|
|
|
let {invite = "", back = () => history.back(), hideHeader}: Props = $props()
|
2025-05-20 16:35:33 +00:00
|
|
|
|
2026-02-19 19:08:06 +00:00
|
|
|
const toggleScanner = () => {
|
|
|
|
|
showScanner = !showScanner
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const onScan = debounce(1000, async (data: string) => {
|
|
|
|
|
showScanner = false
|
|
|
|
|
invite = data
|
|
|
|
|
})
|
|
|
|
|
|
2025-09-06 00:20:12 +00:00
|
|
|
const joinRelay = async () => {
|
|
|
|
|
const {url, claim} = inviteData!
|
2025-05-20 16:35:33 +00:00
|
|
|
|
2026-02-19 19:08:06 +00:00
|
|
|
error = await attemptRelayAccess(url, claim)
|
2024-09-11 17:48:34 +00:00
|
|
|
|
2026-02-19 19:08:06 +00:00
|
|
|
if (!error) {
|
|
|
|
|
if (notifications) {
|
|
|
|
|
if (!notificationSettings.get().push) {
|
|
|
|
|
await setSpaceNotifications(url, true)
|
|
|
|
|
} else {
|
|
|
|
|
const permissions = await Push.request()
|
2024-08-16 19:42:00 +00:00
|
|
|
|
2026-03-19 15:32:32 +00:00
|
|
|
if (permissions.startsWith("granted")) {
|
2026-02-19 19:08:06 +00:00
|
|
|
await setSpaceNotifications(url, true)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
await setSpaceNotifications(url, false)
|
|
|
|
|
}
|
2026-01-30 16:41:58 +00:00
|
|
|
|
2026-06-08 22:33:38 +00:00
|
|
|
await addSpace(url)
|
2026-06-16 22:04:39 +00:00
|
|
|
await goToSpace(url)
|
2026-02-19 19:08:06 +00:00
|
|
|
|
|
|
|
|
broadcastUserData([url])
|
|
|
|
|
relaysMostlyRestricted.update(dissoc(url))
|
|
|
|
|
pushToast({message: "Welcome to the space!"})
|
|
|
|
|
}
|
2024-08-16 19:42:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const join = async () => {
|
|
|
|
|
loading = true
|
|
|
|
|
|
|
|
|
|
try {
|
2025-05-20 16:35:33 +00:00
|
|
|
await joinRelay()
|
2024-08-16 19:42:00 +00:00
|
|
|
} finally {
|
|
|
|
|
loading = false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-19 19:08:06 +00:00
|
|
|
let error = $state(maybe<string>())
|
2025-02-04 00:37:14 +00:00
|
|
|
let loading = $state(false)
|
2026-02-19 19:08:06 +00:00
|
|
|
let showScanner = $state(false)
|
|
|
|
|
let notifications = $state(true)
|
2024-08-16 19:42:00 +00:00
|
|
|
|
2025-11-05 00:39:34 +00:00
|
|
|
const inviteData = $derived(parseInviteLink(invite))
|
2024-08-16 19:42:00 +00:00
|
|
|
</script>
|
|
|
|
|
|
2026-01-30 22:14:12 +00:00
|
|
|
<Modal tag="form" onsubmit={preventDefault(join)}>
|
|
|
|
|
<ModalBody>
|
2026-07-04 00:01:37 +00:00
|
|
|
{#if !hideHeader}
|
|
|
|
|
<ModalHeader>
|
|
|
|
|
<ModalTitle>Join a Space</ModalTitle>
|
|
|
|
|
<ModalSubtitle
|
|
|
|
|
>Enter a relay URL or invite link below to join an existing space.</ModalSubtitle>
|
|
|
|
|
</ModalHeader>
|
|
|
|
|
<Field>
|
|
|
|
|
{#snippet label()}
|
|
|
|
|
<p>Invite Link*</p>
|
|
|
|
|
{/snippet}
|
|
|
|
|
{#snippet input()}
|
|
|
|
|
<label class="input flex w-full items-center gap-2">
|
|
|
|
|
<Icon icon={LinkRound} />
|
|
|
|
|
<input bind:value={invite} class="grow" type="text" />
|
|
|
|
|
<Button onclick={toggleScanner} class="flex items-center justify-center">
|
|
|
|
|
<Icon icon={QrCode} />
|
|
|
|
|
</Button>
|
|
|
|
|
</label>
|
|
|
|
|
{/snippet}
|
|
|
|
|
</Field>
|
|
|
|
|
{#if showScanner}
|
|
|
|
|
<Scanner onscan={onScan} />
|
|
|
|
|
{/if}
|
2026-02-19 19:08:06 +00:00
|
|
|
{/if}
|
2025-09-06 00:20:12 +00:00
|
|
|
{#if inviteData}
|
2026-01-30 22:14:12 +00:00
|
|
|
<div class="-my-4">
|
|
|
|
|
<div transition:slideAndFade class="flex flex-col gap-4 py-4">
|
2026-06-24 20:56:53 +00:00
|
|
|
<div class="card flex flex-col gap-4">
|
2026-01-30 22:14:12 +00:00
|
|
|
<p class="opacity-75">You're about to join:</p>
|
|
|
|
|
<RelaySummary url={inviteData.url} />
|
2026-07-04 00:17:57 +00:00
|
|
|
<SpaceJoinNotifications bind:notifications />
|
2026-07-04 00:24:14 +00:00
|
|
|
{#if error}
|
|
|
|
|
<SpaceJoinStatus url={inviteData.url} {error} />
|
|
|
|
|
{/if}
|
2026-01-30 22:14:12 +00:00
|
|
|
</div>
|
2025-09-06 00:20:12 +00:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
{/if}
|
2026-01-30 22:14:12 +00:00
|
|
|
</ModalBody>
|
2024-10-10 21:33:50 +00:00
|
|
|
<ModalFooter>
|
2026-06-24 20:56:53 +00:00
|
|
|
<Button class="button button-link" onclick={back}>
|
2026-01-30 22:14:12 +00:00
|
|
|
<Icon icon={AltArrowLeft} />
|
|
|
|
|
Go back
|
|
|
|
|
</Button>
|
2026-06-24 20:56:53 +00:00
|
|
|
<Button type="submit" class="button button-primary" disabled={!inviteData || loading}>
|
2024-08-16 19:42:00 +00:00
|
|
|
<Spinner {loading}>Join Space</Spinner>
|
2025-09-10 22:26:39 +00:00
|
|
|
<Icon icon={AltArrowRight} />
|
2024-08-16 19:42:00 +00:00
|
|
|
</Button>
|
2024-10-10 21:33:50 +00:00
|
|
|
</ModalFooter>
|
2026-01-30 22:14:12 +00:00
|
|
|
</Modal>
|