forked from coracle/flotilla
Update alerts to use new anchor
This commit is contained in:
+7
-10
@@ -1,6 +1,8 @@
|
||||
import * as nip19 from "nostr-tools/nip19"
|
||||
import {get} from "svelte/store"
|
||||
import {randomId, ifLet, poll, uniq, equals} from "@welshman/lib"
|
||||
import type {Feed} from "@welshman/feeds"
|
||||
import type {TrustedEvent, EventContent, EventTemplate} from "@welshman/util"
|
||||
import {
|
||||
DELETE,
|
||||
REPORT,
|
||||
@@ -28,11 +30,9 @@ import {
|
||||
getRelayTags,
|
||||
getRelayTagValues,
|
||||
toNostrURI,
|
||||
unionFilters,
|
||||
getRelaysFromList,
|
||||
RelayMode,
|
||||
} from "@welshman/util"
|
||||
import type {TrustedEvent, Filter, EventContent, EventTemplate} from "@welshman/util"
|
||||
import {Pool, PublishStatus, AuthStatus, SocketStatus} from "@welshman/net"
|
||||
import {Nip59, stamp} from "@welshman/signer"
|
||||
import {Router} from "@welshman/router"
|
||||
@@ -431,19 +431,20 @@ export const publishComment = ({relays, ...params}: CommentParams & {relays: str
|
||||
publishThunk({event: makeComment(params), relays})
|
||||
|
||||
export type AlertParams = {
|
||||
feed: Feed
|
||||
cron: string
|
||||
email: string
|
||||
relay: string
|
||||
filters: Filter[]
|
||||
bunker: string
|
||||
secret: string
|
||||
description: string
|
||||
}
|
||||
|
||||
export const makeAlert = async ({cron, email, relay, filters, bunker, secret}: AlertParams) => {
|
||||
export const makeAlert = async ({cron, email, feed, bunker, secret, description}: AlertParams) => {
|
||||
const tags = [
|
||||
["feed", JSON.stringify(feed)],
|
||||
["cron", cron],
|
||||
["email", email],
|
||||
["relay", relay],
|
||||
["description", description],
|
||||
["channel", "email"],
|
||||
[
|
||||
"handler",
|
||||
@@ -453,10 +454,6 @@ export const makeAlert = async ({cron, email, relay, filters, bunker, secret}: A
|
||||
],
|
||||
]
|
||||
|
||||
for (const filter of unionFilters(filters)) {
|
||||
tags.push(["filter", JSON.stringify(filter)])
|
||||
}
|
||||
|
||||
if (bunker) {
|
||||
tags.push(["nip46", secret, bunker])
|
||||
}
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
<script lang="ts">
|
||||
import {preventDefault} from "@lib/html"
|
||||
import {randomInt, TIMEZONE} from "@welshman/lib"
|
||||
import {randomInt, displayList, TIMEZONE} from "@welshman/lib"
|
||||
import {displayRelayUrl, 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"
|
||||
import Button from "@lib/components/Button.svelte"
|
||||
@@ -82,18 +83,22 @@
|
||||
}
|
||||
|
||||
const filters: Filter[] = []
|
||||
const display: string[] = []
|
||||
|
||||
if (notifyThreads) {
|
||||
display.push("threads")
|
||||
filters.push({kinds: [THREAD]})
|
||||
filters.push({kinds: [COMMENT], "#k": [String(THREAD)]})
|
||||
}
|
||||
|
||||
if (notifyCalendar) {
|
||||
display.push("calendar events")
|
||||
filters.push({kinds: [EVENT_TIME]})
|
||||
filters.push({kinds: [COMMENT], "#k": [String(EVENT_TIME)]})
|
||||
}
|
||||
|
||||
if (notifyChat) {
|
||||
display.push("chat")
|
||||
filters.push({
|
||||
kinds: [MESSAGE],
|
||||
"#h": [GENERAL, ...getMembershipRoomsByUrl(relay, $userMembership)],
|
||||
@@ -103,7 +108,10 @@
|
||||
loading = true
|
||||
|
||||
try {
|
||||
const thunk = await publishAlert({cron, email, relay, filters, bunker, secret})
|
||||
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})
|
||||
|
||||
await thunk.result
|
||||
await loadAlertStatuses($pubkey!)
|
||||
|
||||
@@ -1,21 +1,12 @@
|
||||
<script lang="ts">
|
||||
import {parseJson, displayList, nthEq} from "@welshman/lib"
|
||||
import {
|
||||
getAddress,
|
||||
getTagValue,
|
||||
getTagValues,
|
||||
displayRelayUrl,
|
||||
EVENT_TIME,
|
||||
MESSAGE,
|
||||
THREAD,
|
||||
} from "@welshman/util"
|
||||
import Link from "@lib/components/Link.svelte"
|
||||
import {parseJson, nthEq} from "@welshman/lib"
|
||||
import {displayFeeds} from "@welshman/feeds"
|
||||
import {getAddress, getTagValue, getTagValues} from "@welshman/util"
|
||||
import Icon from "@lib/components/Icon.svelte"
|
||||
import Button from "@lib/components/Button.svelte"
|
||||
import AlertDelete from "@app/components/AlertDelete.svelte"
|
||||
import type {Alert} from "@app/state"
|
||||
import {alertStatuses} from "@app/state"
|
||||
import {makeSpacePath} from "@app/routes"
|
||||
import {pushModal} from "@app/modal"
|
||||
|
||||
type Props = {
|
||||
@@ -28,17 +19,15 @@
|
||||
const status = $derived($alertStatuses.find(s => s.event.tags.some(nthEq(1, address))))
|
||||
const cron = $derived(getTagValue("cron", alert.tags))
|
||||
const channel = $derived(getTagValue("channel", alert.tags))
|
||||
const relay = $derived(getTagValue("relay", alert.tags)!)
|
||||
const filters = $derived(getTagValues("filter", alert.tags).map(parseJson))
|
||||
const types = $derived.by(() => {
|
||||
const t: string[] = []
|
||||
|
||||
if (filters.some(f => f.kinds?.includes(THREAD))) t.push("threads")
|
||||
if (filters.some(f => f.kinds?.includes(EVENT_TIME))) t.push("calendar events")
|
||||
if (filters.some(f => f.kinds?.includes(MESSAGE))) t.push("chat")
|
||||
|
||||
return t
|
||||
})
|
||||
const feeds = $derived(getTagValues("feed", alert.tags))
|
||||
const description = $derived(
|
||||
getTagValue("description", alert.tags) ||
|
||||
[
|
||||
`${cron?.endsWith("1") ? "Weekly" : "Daily"} alert for events`,
|
||||
displayFeeds(feeds.map(parseJson)),
|
||||
`sent via ${channel}.`,
|
||||
].join(" "),
|
||||
)
|
||||
|
||||
const startDelete = () => pushModal(AlertDelete, {alert})
|
||||
</script>
|
||||
@@ -48,13 +37,7 @@
|
||||
<Button class="py-1" onclick={startDelete}>
|
||||
<Icon icon="trash-bin-2" />
|
||||
</Button>
|
||||
<div class="flex-inline gap-1">
|
||||
{cron?.endsWith("1") ? "Weekly" : "Daily"} alert for
|
||||
{displayList(types)} on
|
||||
<Link class="link" href={makeSpacePath(relay)}>
|
||||
{displayRelayUrl(relay)}
|
||||
</Link>, sent via {channel}.
|
||||
</div>
|
||||
<div class="flex-inline gap-1">{description}</div>
|
||||
</div>
|
||||
{#if status}
|
||||
{@const statusText = getTagValue("status", status.tags) || "error"}
|
||||
|
||||
Reference in New Issue
Block a user