diff --git a/src/app/components/IntentHandler.svelte b/src/app/components/IntentHandler.svelte index 0b357ef3..8ce3a763 100644 --- a/src/app/components/IntentHandler.svelte +++ b/src/app/components/IntentHandler.svelte @@ -10,6 +10,7 @@ addRelay, pubkey, profilesByPubkey, + waitForThunkError, } from "@welshman/app" import { makeEvent, @@ -29,11 +30,11 @@ import ModalTitle from "@lib/components/ModalTitle.svelte" import ModalSubtitle from "@lib/components/ModalSubtitle.svelte" import Button from "@lib/components/Button.svelte" - import Icon from "@lib/components/Icon.svelte" - import AltArrowLeft from "@assets/icons/alt-arrow-left.svg?dataurl" import {theme} from "@app/util/theme" import {pushModal} from "@app/util/modal" import {pushToast} from "@app/util/toast" + import {errorMessage} from "@lib/util" + import Modal from "@lib/components/Modal.svelte" import ThreadCreate from "@app/components/ThreadCreate.svelte" import {addSpaceMembership, updateProfile} from "@app/core/commands" @@ -54,12 +55,20 @@ const profile_about = params.get("profile_about") const profile_picture = params.get("profile_picture") const profile_banner = params.get("profile_banner") + const profile_nip05 = params.get("profile_nip05") + const profile_lud16 = params.get("profile_lud16") const shareRelay = params.get("share_relay") || params.get("share_url") const shareH = params.get("share_h") const shareText = params.get("share_text") - const hasProfile = !!profile_name || !!profile_about || !!profile_picture || !!profile_banner + const hasProfile = + !!profile_name || + !!profile_about || + !!profile_picture || + !!profile_banner || + !!profile_nip05 || + !!profile_lud16 const hasSettings = !!t || relays.length > 0 || @@ -74,7 +83,7 @@ onMount(() => { if (!hasSettings) { if (hasShare) { - doShare() + void openShare() } else { pushToast({message: "No valid intent actions found", theme: "error"}) back() @@ -82,120 +91,149 @@ } }) - const doShare = () => { - back() - goto(`/spaces/${encodeURIComponent(shareRelay!)}/${shareH}`).then(() => { - pushModal(ThreadCreate, {url: shareRelay!, h: shareH!, initialContent: shareText || ""}) - }) + const openShare = async () => { + await goto(`/spaces/${encodeURIComponent(shareRelay!)}/${shareH}`) + + pushModal(ThreadCreate, {url: shareRelay!, h: shareH!, initialContent: shareText || ""}) } const accept = async () => { processing = true - - if (t === "dark" || t === "light" || t === "system") { - theme.set(t) - } - - if (relays.length > 0) { - for (const url of relays) { - addRelay(url, RelayMode.Read) - addRelay(url, RelayMode.Write) + try { + if (t) { + theme.set(t) } - } - if (blossoms.length > 0) { - const current = getTagValues("server", getListTags(get(userBlossomServerList))) - const updated = Array.from(new Set([...current, ...blossoms])) - publishThunk({ - event: makeEvent(BLOSSOM_SERVERS, {tags: updated.map(tagger("server"))}), - relays: Router.get().FromUser().getUrls(), - }) - } - - if (follows.length > 0) { - const current = getPubkeyTagValues(getListTags(get(userFollowList))) - const updated = Array.from(new Set([...current, ...follows])) - publishThunk({ - event: makeEvent(FOLLOWS, {tags: updated.map(tagPubkey)}), - relays: Router.get().FromUser().getUrls(), - }) - } - - if (joins.length > 0) { - for (const url of joins) { - await addSpaceMembership(url) + if (relays.length > 0) { + for (const url of relays) { + addRelay(url, RelayMode.Read) + addRelay(url, RelayMode.Write) + } } - } - if (hasProfile) { - const p = get(profilesByPubkey).get(get(pubkey)!) || makeProfile() - if (profile_name) p.name = profile_name - if (profile_about) p.about = profile_about - if (profile_picture) p.picture = profile_picture - if (profile_banner) p.banner = profile_banner - // assuming shouldBroadcast makes it public - await updateProfile({profile: p, shouldBroadcast: true}) - } + if (blossoms.length > 0) { + const current = getTagValues("server", getListTags(get(userBlossomServerList))) + const updated = Array.from(new Set([...current, ...blossoms])) + const error = await waitForThunkError( + publishThunk({ + event: makeEvent(BLOSSOM_SERVERS, {tags: updated.map(tagger("server"))}), + relays: Router.get().FromUser().getUrls(), + }), + ) - pushToast({message: "Customizations Applied!"}) + if (error) { + pushToast({ + theme: "error", + message: `Failed to update blossom servers: ${errorMessage(error)}`, + }) + return + } + } - if (hasShare) { - doShare() - } else { - back() + if (follows.length > 0) { + const current = getPubkeyTagValues(getListTags(get(userFollowList))) + const updated = Array.from(new Set([...current, ...follows])) + const error = await waitForThunkError( + publishThunk({ + event: makeEvent(FOLLOWS, {tags: updated.map(tagPubkey)}), + relays: Router.get().FromUser().getUrls(), + }), + ) + + if (error) { + pushToast({theme: "error", message: `Failed to update follows: ${errorMessage(error)}`}) + return + } + } + + if (joins.length > 0) { + for (const url of joins) { + await addSpaceMembership(url) + } + } + + if (hasProfile) { + const profile = {...(get(profilesByPubkey).get(get(pubkey)!) || makeProfile())} + if (profile_name) profile.name = profile_name + if (profile_about) profile.about = profile_about + if (profile_picture) profile.picture = profile_picture + if (profile_banner) profile.banner = profile_banner + if (profile_nip05) profile.nip05 = profile_nip05 + if (profile_lud16) profile.lud16 = profile_lud16 + + const error = await waitForThunkError(updateProfile({profile, shouldBroadcast: true})) + + if (error) { + if (error.includes("rate-limited") || error.startsWith("blocked:")) { + pushToast({ + message: "Profile update was requested, but one relay rate-limited or blocked it.", + }) + } else { + pushToast({theme: "error", message: `Failed to update profile: ${errorMessage(error)}`}) + return + } + } + } + + pushToast({message: "Customizations Applied!"}) + + if (hasShare) { + await openShare() + } else { + back() + } + } finally { + processing = false } } {#if hasSettings} -