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} -
- -
- + event.preventDefault()}> +
+
Apply Customization? A link is requesting to customize your app.
-
- + - -

This link will apply the following changes:

-
    - {#if t} -
  • Set theme to "{t}"
  • - {/if} - {#if relays.length > 0} -
  • Add {relays.length} relay{relays.length > 1 ? "s" : ""} to your settings
  • - {/if} - {#if blossoms.length > 0} -
  • Add {blossoms.length} blossom server{blossoms.length > 1 ? "s" : ""}
  • - {/if} - {#if follows.length > 0} -
  • Follow {follows.length} person{follows.length > 1 ? "s" : ""}
  • - {/if} - {#if joins.length > 0} -
  • Join {joins.length} communit{joins.length > 1 ? "ies" : "y"}
  • - {/if} - {#if hasProfile} -
  • Update your profile metadata
  • - {/if} - {#if hasShare} -
  • Open a new post dialog in a specific room
  • - {/if} -
-
+ +

This link will apply the following changes:

+
    + {#if t} +
  • Set theme to "{t}"
  • + {/if} + {#if relays.length > 0} +
  • Add {relays.length} relay{relays.length > 1 ? "s" : ""} to your settings
  • + {/if} + {#if blossoms.length > 0} +
  • Add {blossoms.length} blossom server{blossoms.length > 1 ? "s" : ""}
  • + {/if} + {#if follows.length > 0} +
  • Follow {follows.length} person{follows.length > 1 ? "s" : ""}
  • + {/if} + {#if joins.length > 0} +
  • Join {joins.length} communit{joins.length > 1 ? "ies" : "y"}
  • + {/if} + {#if hasProfile} +
  • Update your profile metadata
  • + {/if} + {#if hasShare} +
  • Open a new post dialog in a specific room
  • + {/if} +
+
- - - - - + + + + +
+ {/if} diff --git a/src/lib/components/Dialog.svelte b/src/lib/components/Dialog.svelte index 261cce23..4a9a58f3 100644 --- a/src/lib/components/Dialog.svelte +++ b/src/lib/components/Dialog.svelte @@ -6,7 +6,6 @@ import Close from "@assets/icons/close.svg?dataurl" import Icon from "@lib/components/Icon.svelte" import Button from "@lib/components/Button.svelte" - import {clearModals} from "@app/util/modal" type Props = { onClose?: any @@ -56,7 +55,7 @@
{#if !noEscape} - {/if} diff --git a/src/routes/intent/+page.svelte b/src/routes/intent/+page.svelte index 15708a89..ef30915c 100644 --- a/src/routes/intent/+page.svelte +++ b/src/routes/intent/+page.svelte @@ -13,4 +13,4 @@ } - + goto("/home")} /> diff --git a/src/routes/join/+page.svelte b/src/routes/join/+page.svelte index 1083d874..abf101ed 100644 --- a/src/routes/join/+page.svelte +++ b/src/routes/join/+page.svelte @@ -13,4 +13,4 @@ } - + goto("/home")} /> diff --git a/src/routes/settings/+layout.svelte b/src/routes/settings/+layout.svelte index 4b24ac9e..3603ffb4 100644 --- a/src/routes/settings/+layout.svelte +++ b/src/routes/settings/+layout.svelte @@ -67,6 +67,6 @@ - + {@render children?.()}