Add claim to alert add

This commit is contained in:
Jon Staab
2025-06-27 14:36:09 -07:00
parent f2249fe592
commit b9620f4443
5 changed files with 41 additions and 17 deletions

View File

@@ -306,20 +306,26 @@ export const attemptRelayAccess = async (url: string, claim = "") => {
// Actions // Actions
export const makeDelete = ({event}: {event: TrustedEvent}) => { export const makeDelete = ({event, tags = []}: {event: TrustedEvent; tags?: string[][]}) => {
const tags = [["k", String(event.kind)], ...tagEvent(event)] const thisTags = [["k", String(event.kind)], ...tagEvent(event), ...tags]
const groupTag = getTag("h", event.tags) const groupTag = getTag("h", event.tags)
if (groupTag) { if (groupTag) {
tags.push(PROTECTED) thisTags.push(PROTECTED, groupTag)
tags.push(groupTag)
} }
return makeEvent(DELETE, {tags}) return makeEvent(DELETE, {tags: thisTags})
} }
export const publishDelete = ({relays, event}: {relays: string[]; event: TrustedEvent}) => export const publishDelete = ({
publishThunk({event: makeDelete({event}), relays}) relays,
event,
tags = [],
}: {
relays: string[]
event: TrustedEvent
tags?: string[][]
}) => publishThunk({event: makeDelete({event, tags}), relays})
export type ReportParams = { export type ReportParams = {
event: TrustedEvent event: TrustedEvent

View File

@@ -29,7 +29,7 @@
NOTIFIER_PUBKEY, NOTIFIER_PUBKEY,
NOTIFIER_RELAY, NOTIFIER_RELAY,
} from "@app/state" } from "@app/state"
import {loadAlertStatuses, requestRelayClaims} from "@app/requests" import {loadAlertStatuses, requestRelayClaim} from "@app/requests"
import {publishAlert, attemptAuth} from "@app/commands" import {publishAlert, attemptAuth} from "@app/commands"
import type {AlertParams} from "@app/commands" import type {AlertParams} from "@app/commands"
import {platform, canSendPushNotifications, getPushInfo} from "@app/push" import {platform, canSendPushNotifications, getPushInfo} from "@app/push"
@@ -59,6 +59,7 @@
let loading = $state(false) let loading = $state(false)
let cron = $state(WEEKLY) let cron = $state(WEEKLY)
let claim = $state("")
let email = $state($alerts.map(a => getTagValue("email", a.tags)).filter(identity)[0] || "") let email = $state($alerts.map(a => getTagValue("email", a.tags)).filter(identity)[0] || "")
const back = () => history.back() const back = () => history.back()
@@ -108,7 +109,7 @@
loading = true loading = true
try { try {
const claims = await requestRelayClaims([relay]) const claims = claim ? {[relay]: claim} : {}
const feed = makeIntersectionFeed(feedFromFilters(filters), makeRelayFeed(relay)) const feed = makeIntersectionFeed(feedFromFilters(filters), makeRelayFeed(relay))
const description = `for ${displayList(display)} on ${displayRelayUrl(relay)}` const description = `for ${displayList(display)} on ${displayRelayUrl(relay)}`
const params: AlertParams = {feed, claims, description} const params: AlertParams = {feed, claims, description}
@@ -177,6 +178,12 @@
if (!canSendPushNotifications()) { if (!canSendPushNotifications()) {
channel = "email" channel = "email"
} }
requestRelayClaim(relay).then(code => {
if (code) {
claim = code
}
})
}) })
</script> </script>
@@ -256,6 +263,22 @@
</div> </div>
{/snippet} {/snippet}
</FieldInline> </FieldInline>
<FieldInline>
{#snippet label()}
<p>Invite Code</p>
{/snippet}
{#snippet input()}
<label class="input input-bordered flex w-full items-center gap-2">
<input bind:value={claim} />
</label>
{/snippet}
{#snippet info()}
<p>
To get notifications from private spaces, please provide an invite code which grants access
to the space.
</p>
{/snippet}
</FieldInline>
<ModalFooter> <ModalFooter>
<Button class="btn btn-link" onclick={back}> <Button class="btn btn-link" onclick={back}>
<Icon icon="alt-arrow-left" /> <Icon icon="alt-arrow-left" />

View File

@@ -1,7 +1,7 @@
<script lang="ts"> <script lang="ts">
import Confirm from "@lib/components/Confirm.svelte" import Confirm from "@lib/components/Confirm.svelte"
import type {Alert} from "@app/state" import type {Alert} from "@app/state"
import {NOTIFIER_RELAY} from "@app/state" import {NOTIFIER_RELAY, NOTIFIER_PUBKEY} from "@app/state"
import {publishDelete} from "@app/commands" import {publishDelete} from "@app/commands"
import {pushToast} from "@app/toast" import {pushToast} from "@app/toast"
@@ -12,7 +12,7 @@
const {alert}: Props = $props() const {alert}: Props = $props()
const confirm = () => { const confirm = () => {
publishDelete({event: alert.event, relays: [NOTIFIER_RELAY]}) publishDelete({event: alert.event, relays: [NOTIFIER_RELAY], tags: [["p", NOTIFIER_PUBKEY]]})
pushToast({message: "Your alert has been deleted!"}) pushToast({message: "Your alert has been deleted!"})
history.back() history.back()
} }

View File

@@ -62,8 +62,6 @@
} }
let limit = $state(3) let limit = $state(3)
$inspect($messages)
</script> </script>
<div class="card2 bg-alt"> <div class="card2 bg-alt">

View File

@@ -13,7 +13,6 @@ import {
sortBy, sortBy,
assoc, assoc,
now, now,
removeNil,
isNotNil, isNotNil,
filterVals, filterVals,
fromPairs, fromPairs,
@@ -442,9 +441,7 @@ export const discoverRelays = (lists: List[]) =>
) )
export const requestRelayClaim = async (url: string) => { export const requestRelayClaim = async (url: string) => {
const relay = await loadRelay(url) const filters = [{kinds: [AUTH_INVITE], limit: 1}]
const authors = removeNil([relay?.profile?.self, relay?.profile?.pubkey])
const filters = [{kinds: [AUTH_INVITE], authors, limit: 1}]
const events = await load({filters, relays: [url]}) const events = await load({filters, relays: [url]})
if (events.length > 0) { if (events.length > 0) {