forked from coracle/flotilla
feat: prompt SpaceJoin when opening unjoined space via direct link
This commit is contained in:
@@ -1,15 +1,18 @@
|
||||
<script lang="ts">
|
||||
import type {Snippet} from "svelte"
|
||||
import {get} from "svelte/store"
|
||||
import {page} from "$app/stores"
|
||||
import {once} from "@welshman/lib"
|
||||
import {pubkey} from "@welshman/app"
|
||||
import Page from "@lib/components/Page.svelte"
|
||||
import SecondaryNav from "@lib/components/SecondaryNav.svelte"
|
||||
import SpaceMenu from "@app/components/SpaceMenu.svelte"
|
||||
import SpaceAuthError from "@app/components/SpaceAuthError.svelte"
|
||||
import SpaceTrustRelay from "@app/components/SpaceTrustRelay.svelte"
|
||||
import SpaceJoin from "@app/components/SpaceJoin.svelte"
|
||||
import {pushModal} from "@app/util/modal"
|
||||
import {makeSpacePath} from "@app/util/routes"
|
||||
import {decodeRelay, relaysPendingTrust} from "@app/core/state"
|
||||
import {decodeRelay, relaysPendingTrust, userSpaceUrls, loadUserGroupList} from "@app/core/state"
|
||||
import {deriveRelayAuthError} from "@app/core/commands"
|
||||
|
||||
type Props = {
|
||||
@@ -28,6 +31,8 @@
|
||||
|
||||
const showPendingTrust = once(() => pushModal(SpaceTrustRelay, {url}, {noEscape: true}))
|
||||
|
||||
const joinPrompted = new Set<string>()
|
||||
|
||||
// Watch for relay errors and notify the user
|
||||
$effect(() => {
|
||||
if ($authError) {
|
||||
@@ -36,6 +41,49 @@
|
||||
showPendingTrust()
|
||||
}
|
||||
})
|
||||
|
||||
// Direct links skip Discover — prompt to join when relay is not in the user's space list.
|
||||
$effect(() => {
|
||||
const spaceUrl = url
|
||||
const currentPubkey = get(pubkey)
|
||||
|
||||
if (!currentPubkey) {
|
||||
return
|
||||
}
|
||||
|
||||
if ($userSpaceUrls.includes(spaceUrl) || $authError || $relaysPendingTrust.includes(spaceUrl)) {
|
||||
return
|
||||
}
|
||||
|
||||
let cancelled = false
|
||||
|
||||
void loadUserGroupList().then(() => {
|
||||
if (cancelled) {
|
||||
return
|
||||
}
|
||||
|
||||
if (get(pubkey) !== currentPubkey) {
|
||||
return
|
||||
}
|
||||
|
||||
if (
|
||||
get(userSpaceUrls).includes(spaceUrl) ||
|
||||
get(authError) ||
|
||||
get(relaysPendingTrust).includes(spaceUrl) ||
|
||||
joinPrompted.has(spaceUrl)
|
||||
) {
|
||||
return
|
||||
}
|
||||
|
||||
joinPrompted.add(spaceUrl)
|
||||
pushModal(SpaceJoin, {url: spaceUrl})
|
||||
})
|
||||
|
||||
return () => {
|
||||
cancelled = true
|
||||
joinPrompted.delete(spaceUrl)
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
{#if $page.url.pathname === makeSpacePath(url)}
|
||||
|
||||
Reference in New Issue
Block a user