Compare commits

..

1 Commits

2 changed files with 40 additions and 26 deletions
-2
View File
@@ -772,8 +772,6 @@ export const getSpaceRoomsFromGroupList = (url: string, groupList: List | undefi
export const userGroupList = makeUserData(groupListsByPubkey, loadGroupList)
export const deriveUserGroupList = userGroupList
export const loadUserGroupList = makeUserLoader(loadGroupList)
export const userSpaceUrls = derived(userGroupList, getSpaceUrlsFromGroupList)
+40 -24
View File
@@ -1,9 +1,6 @@
<script module lang="ts">
const joinPrompted = new Set<string>()
</script>
<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"
@@ -15,12 +12,7 @@
import SpaceJoin from "@app/components/SpaceJoin.svelte"
import {pushModal} from "@app/util/modal"
import {makeSpacePath} from "@app/util/routes"
import {
decodeRelay,
deriveUserGroupList,
relaysPendingTrust,
userSpaceUrls,
} from "@app/core/state"
import {decodeRelay, relaysPendingTrust, userSpaceUrls, loadUserGroupList} from "@app/core/state"
import {deriveRelayAuthError} from "@app/core/commands"
type Props = {
@@ -39,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) {
@@ -49,24 +43,46 @@
})
// Direct links skip Discover — prompt to join when relay is not in the user's space list.
const shouldPromptJoin = $derived.by(() => {
void $deriveUserGroupList
return (
Boolean($pubkey) &&
!$userSpaceUrls.includes(url) &&
!$authError &&
!$relaysPendingTrust.includes(url)
)
})
$effect(() => {
if (!shouldPromptJoin || joinPrompted.has(url)) {
const spaceUrl = url
const currentPubkey = get(pubkey)
if (!currentPubkey) {
return
}
joinPrompted.add(url)
pushModal(SpaceJoin, {url})
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>