diff --git a/src/app/commands.ts b/src/app/commands.ts index f69e741..8127183 100644 --- a/src/app/commands.ts +++ b/src/app/commands.ts @@ -372,12 +372,11 @@ export type AlertParams = { feed: Feed cron: string email: string - bunker: string - secret: string description: string + claims: Record } -export const makeAlert = async ({cron, email, feed, bunker, secret, description}: AlertParams) => { +export const makeAlert = async ({cron, email, feed, claims, description}: AlertParams) => { const tags = [ ["feed", JSON.stringify(feed)], ["cron", cron], @@ -394,8 +393,8 @@ export const makeAlert = async ({cron, email, feed, bunker, secret, description} ], ] - if (bunker) { - tags.push(["nip46", secret, bunker]) + for (const [relay, claim] of Object.entries(claims)) { + tags.push(["claim", relay, claim]) } return makeEvent(ALERT, { diff --git a/src/app/components/AlertAdd.svelte b/src/app/components/AlertAdd.svelte index 4717874..fdb9b18 100644 --- a/src/app/components/AlertAdd.svelte +++ b/src/app/components/AlertAdd.svelte @@ -3,7 +3,6 @@ import {randomInt, displayList, TIMEZONE, identity} from "@welshman/lib" import {displayRelayUrl, getTagValue, THREAD, MESSAGE, EVENT_TIME, COMMENT} from "@welshman/util" import type {Filter} from "@welshman/util" - import type {Nip46ResponseWithResult} from "@welshman/signer" import {makeIntersectionFeed, makeRelayFeed, feedFromFilters} from "@welshman/feeds" import {pubkey} from "@welshman/app" import Icon from "@lib/components/Icon.svelte" @@ -12,13 +11,10 @@ import Spinner from "@lib/components/Spinner.svelte" import ModalHeader from "@lib/components/ModalHeader.svelte" import ModalFooter from "@lib/components/ModalFooter.svelte" - import InfoBunker from "@app/components/InfoBunker.svelte" - import BunkerConnect, {BunkerConnectController} from "@app/components/BunkerConnect.svelte" import {alerts, getMembershipUrls, getMembershipRoomsByUrl, userMembership} from "@app/state" - import {loadAlertStatuses} from "@app/requests" + import {loadAlertStatuses, requestRelayClaims} from "@app/requests" import {publishAlert} from "@app/commands" import {pushToast} from "@app/toast" - import {pushModal} from "@app/modal" const timezoneOffset = parseInt(TIMEZONE.slice(3)) / 100 const minute = randomInt(0, 59) @@ -30,36 +26,12 @@ let cron = WEEKLY let email = $alerts.map(a => getTagValue("email", a.tags)).filter(identity)[0] || "" let relay = "" - let bunker = "" - let secret = "" let notifyThreads = true let notifyCalendar = true let notifyChat = false - let showBunker = false const back = () => history.back() - const controller = new BunkerConnectController({ - onNostrConnect: (response: Nip46ResponseWithResult) => { - bunker = controller.broker.getBunkerUrl() - secret = controller.broker.params.clientSecret - showBunker = false - }, - }) - - const connectBunker = () => { - showBunker = true - } - - const hideBunker = () => { - showBunker = false - } - - const clearBunker = () => { - bunker = "" - secret = "" - } - const submit = async () => { if (!email.includes("@")) { return pushToast({ @@ -108,10 +80,11 @@ loading = true try { + const claims = await requestRelayClaims([relay]) const cadence = cron?.endsWith("1") ? "Weekly" : "Daily" const description = `${cadence} alert for ${displayList(display)} on ${displayRelayUrl(relay)}, sent via email.` const feed = makeIntersectionFeed(feedFromFilters(filters), makeRelayFeed(relay)) - const thunk = await publishAlert({cron, email, feed, bunker, secret, description}) + const thunk = await publishAlert({cron, email, feed, claims, description}) await thunk.result await loadAlertStatuses($pubkey!) @@ -130,100 +103,67 @@ Add an Alert {/snippet} - {#if showBunker} -
-

Scan using a nostr signer, or click to copy.

- - -
- {:else} - - {#snippet label()} -

Email Address*

- {/snippet} - {#snippet input()} - - {/snippet} -
- - {#snippet label()} -

Frequency*

- {/snippet} - {#snippet input()} - - {/snippet} -
- - {#snippet label()} -

Space*

- {/snippet} - {#snippet input()} - - {/snippet} -
- - {#snippet label()} -

Notifications*

- {/snippet} - {#snippet input()} -
- - - Threads - - - - Calendar - - - - Chat - -
- {/snippet} -
-
-
- Connect a Bunker - - {#if bunker} - - Connected - {:else} - - Not Connected - {/if} + + {#snippet label()} +

Email Address*

+ {/snippet} + {#snippet input()} + + {/snippet} +
+ + {#snippet label()} +

Frequency*

+ {/snippet} + {#snippet input()} + + {/snippet} +
+ + {#snippet label()} +

Space*

+ {/snippet} + {#snippet input()} + + {/snippet} +
+ + {#snippet label()} +

Notifications*

+ {/snippet} + {#snippet input()} +
+ + + Threads + + + + Calendar + + + + Chat
-

- Required for receiving alerts about spaces with access controls. You can get one from your - . -

- {#if bunker} - - {:else} - - {/if} -
- {/if} + {/snippet} + - diff --git a/src/app/requests.ts b/src/app/requests.ts index aa33619..218685b 100644 --- a/src/app/requests.ts +++ b/src/app/requests.ts @@ -13,12 +13,17 @@ import { sortBy, assoc, now, + removeNil, + isNotNil, + filterVals, + fromPairs, } from "@welshman/lib" import { MESSAGE, DELETE, THREAD, EVENT_TIME, + AUTH_INVITE, COMMENT, matchFilters, getTagValues, @@ -430,3 +435,20 @@ export const discoverRelays = (lists: List[]) => .filter(isShareableRelayUrl) .map(url => loadRelay(url)), ) + +export const requestRelayClaim = async (url: string) => { + const relay = await loadRelay(url) + const authors = removeNil([relay?.profile?.self, relay?.profile?.pubkey]) + const filters = [{kinds: [AUTH_INVITE], authors, limit: 1}] + const events = await load({filters, relays: [url]}) + + if (events.length > 0) { + return getTagValue("claim", events[0].tags) + } +} + +export const requestRelayClaims = async (urls: string[]) => + filterVals( + isNotNil, + fromPairs(await Promise.all(urls.map(async url => [url, await requestRelayClaim(url)]))), + )