feat: prompt SpaceJoin when opening unjoined space via direct link #291

Merged
hodlbod merged 1 commits from userAdityaa/flotilla:286-prompt-space-join-on-direct-link into dev 2026-06-08 21:15:37 +00:00
+28 -1
View File
@@ -1,15 +1,21 @@
<script module lang="ts">
const joinPrompted = new Set<string>()
</script>
<script lang="ts">
import type {Snippet} from "svelte"
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, userGroupList, relaysPendingTrust, userSpaceUrls} from "@app/core/state"
import {deriveRelayAuthError} from "@app/core/commands"
type Props = {
2
@@ -36,6 +42,27 @@
showPendingTrust()
}
})
// Direct links skip Discover — prompt to join when relay is not in the user's space list.
const shouldPromptJoin = $derived.by(() => {
void $userGroupList
return (
Boolean($pubkey) &&
!$userSpaceUrls.includes(url) &&
!$authError &&
!$relaysPendingTrust.includes(url)
)
})
$effect(() => {
if (!shouldPromptJoin || joinPrompted.has(url)) {
return
hodlbod marked this conversation as resolved Outdated
Outdated
Review

deriveUserGroupList auto-loads, allowing you to avoid a lot of this complex logic. Switch to that and then you can use $derived instead of $effect (or at least a very small effect which reacts to a derived store)

deriveUserGroupList auto-loads, allowing you to avoid a lot of this complex logic. Switch to that and then you can use `$derived` instead of `$effect` (or at least a very small effect which reacts to a derived store)
Outdated
Review

Switched to deriveUserGroupList (alias for userGroupList) so the group list auto-loads on subscribe via makeUserData, instead of manually calling loadUserGroupList().then() with cancellation/pubkey re-check logic.

Switched to deriveUserGroupList (alias for userGroupList) so the group list auto-loads on subscribe via makeUserData, instead of manually calling loadUserGroupList().then() with cancellation/pubkey re-check logic.
}
joinPrompted.add(url)
pushModal(SpaceJoin, {url})
})
</script>
{#if $page.url.pathname === makeSpacePath(url)}