check for nip-9a support
This commit is contained in:
parent
a7b948740c
commit
2b2515b1be
2 changed files with 77 additions and 0 deletions
26
src/app/components/EmailNotificationsInfo.svelte
Normal file
26
src/app/components/EmailNotificationsInfo.svelte
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
<script lang="ts">
|
||||||
|
import Button from "@lib/components/Button.svelte"
|
||||||
|
import Modal from "@lib/components/Modal.svelte"
|
||||||
|
import ModalBody from "@lib/components/ModalBody.svelte"
|
||||||
|
import ModalHeader from "@lib/components/ModalHeader.svelte"
|
||||||
|
import ModalTitle from "@lib/components/ModalTitle.svelte"
|
||||||
|
import {popModal} from "@app/modal"
|
||||||
|
|
||||||
|
const gotIt = () => popModal()
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<Modal
|
||||||
|
><ModalBody>
|
||||||
|
<ModalHeader>
|
||||||
|
<ModalTitle>Email notifications</ModalTitle>
|
||||||
|
</ModalHeader>
|
||||||
|
<p>
|
||||||
|
For a community's new messages to appear in your email digest, its relay must support NIP-9a
|
||||||
|
(email notifications).
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
If a community is missing from your digest, ask the community admin to enable NIP-9a on their
|
||||||
|
relay.
|
||||||
|
</p>
|
||||||
|
<Button class="button button-primary" onclick={gotIt}>Got it</Button>
|
||||||
|
</ModalBody></Modal>
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import cx from "classnames"
|
import cx from "classnames"
|
||||||
|
import {derived} from "svelte/store"
|
||||||
import {sleep} from "@welshman/lib"
|
import {sleep} from "@welshman/lib"
|
||||||
|
import type {Relay} from "@welshman/domain"
|
||||||
import {Capacitor} from "@capacitor/core"
|
import {Capacitor} from "@capacitor/core"
|
||||||
import {Badge} from "@capawesome/capacitor-badge"
|
import {Badge} from "@capawesome/capacitor-badge"
|
||||||
import Bell from "@assets/icons/bell.svg?dataurl"
|
import Bell from "@assets/icons/bell.svg?dataurl"
|
||||||
|
|
@ -12,12 +14,16 @@
|
||||||
import Button from "@lib/components/Button.svelte"
|
import Button from "@lib/components/Button.svelte"
|
||||||
import PageContent from "@lib/components/PageContent.svelte"
|
import PageContent from "@lib/components/PageContent.svelte"
|
||||||
import {pushToast} from "@app/toast"
|
import {pushToast} from "@app/toast"
|
||||||
|
import {pushModal} from "@app/modal"
|
||||||
import {clearBadges} from "@app/notifications"
|
import {clearBadges} from "@app/notifications"
|
||||||
import {Push} from "@app/push"
|
import {Push} from "@app/push"
|
||||||
import {Mail} from "@app/mail"
|
import {Mail} from "@app/mail"
|
||||||
import {notificationSettings, publishSettings, userSettingsValues} from "@app/settings"
|
import {notificationSettings, publishSettings, userSettingsValues} from "@app/settings"
|
||||||
import {emailNotificationState} from "@app/push/adapters/common"
|
import {emailNotificationState} from "@app/push/adapters/common"
|
||||||
import {EMAIL_NOTIFICATION_SERVER} from "@app/env"
|
import {EMAIL_NOTIFICATION_SERVER} from "@app/env"
|
||||||
|
import {relays} from "@app/core"
|
||||||
|
import {userSpaceUrls} from "@app/rooms"
|
||||||
|
import EmailNotificationsInfo from "@app/components/EmailNotificationsInfo.svelte"
|
||||||
|
|
||||||
const clearError = () => {
|
const clearError = () => {
|
||||||
if ($emailNotificationState.error) {
|
if ($emailNotificationState.error) {
|
||||||
|
|
@ -112,6 +118,34 @@
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// Communities whose relay doesn't advertise NIP-9a won't be included in the email digest.
|
||||||
|
// Subscribing to each space's NIP-11 info triggers a fetch for any that hasn't loaded yet.
|
||||||
|
const communitiesWithoutEmail = derived(
|
||||||
|
userSpaceUrls,
|
||||||
|
($urls, set: (value: string[]) => void) => {
|
||||||
|
const unsubscribers = $urls.map(url =>
|
||||||
|
relays
|
||||||
|
.get()
|
||||||
|
.one(url)
|
||||||
|
.subscribe(() =>
|
||||||
|
set(
|
||||||
|
$urls
|
||||||
|
.map(url => relays.get().get(url))
|
||||||
|
.filter((relay): relay is Relay => relay !== undefined && !relay.hasNip("9a"))
|
||||||
|
.map(relay => relay.display()),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
return () =>
|
||||||
|
unsubscribers.forEach(unsubscribe => {
|
||||||
|
unsubscribe()
|
||||||
|
})
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
const showEmailInfo = () => pushModal(EmailNotificationsInfo)
|
||||||
|
|
||||||
let loading = $state(false)
|
let loading = $state(false)
|
||||||
let settings = $state(buildSettings())
|
let settings = $state(buildSettings())
|
||||||
</script>
|
</script>
|
||||||
|
|
@ -198,6 +232,23 @@
|
||||||
{/snippet}
|
{/snippet}
|
||||||
</FieldInline>
|
</FieldInline>
|
||||||
{#if settings.email}
|
{#if settings.email}
|
||||||
|
{#if $communitiesWithoutEmail.length > 0}
|
||||||
|
<div class="flex flex-col gap-1 rounded-2xl border border-warning bg-warning/10 p-4">
|
||||||
|
<p class="flex items-center gap-2 text-sm text-warning">
|
||||||
|
{#if $communitiesWithoutEmail.length === 1}
|
||||||
|
1 of your communities does not support email notifications.
|
||||||
|
{:else}
|
||||||
|
{$communitiesWithoutEmail.length} of your communities do not support email notifications.
|
||||||
|
{/if}
|
||||||
|
<Button class="link" onclick={showEmailInfo}>Learn more</Button>
|
||||||
|
</p>
|
||||||
|
<ul class="list-inside list-disc text-sm text-warning">
|
||||||
|
{#each $communitiesWithoutEmail as name (name)}
|
||||||
|
<li>{name}</li>
|
||||||
|
{/each}
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
<FieldInline>
|
<FieldInline>
|
||||||
{#snippet label()}
|
{#snippet label()}
|
||||||
<p>Email address</p>
|
<p>Email address</p>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue