diff --git a/src/app/commands.ts b/src/app/commands.ts index 6ffe9b3b..9e6fe42e 100644 --- a/src/app/commands.ts +++ b/src/app/commands.ts @@ -20,7 +20,6 @@ import { ALERT_ANDROID, isSignedEvent, makeEvent, - getAddress, displayProfile, normalizeRelayUrl, makeList, @@ -62,7 +61,6 @@ import { NOTIFIER_PUBKEY, NOTIFIER_RELAY, userRoomsByUrl, - deviceAlertAddresses, } from "@app/state" // Utils @@ -445,10 +443,5 @@ export const makeAlert = async (params: AlertParams) => { }) } -export const publishAlert = async (params: AlertParams) => { - const event = await signer.get().sign(await makeAlert(params)) - - deviceAlertAddresses.update($addresses => [...$addresses, getAddress(event)]) - - return publishThunk({event, relays: [NOTIFIER_RELAY]}) -} +export const publishAlert = async (params: AlertParams) => + publishThunk({event: await makeAlert(params), relays: [NOTIFIER_RELAY]}) diff --git a/src/app/components/AlertAdd.svelte b/src/app/components/AlertAdd.svelte index 6d5e9903..98a8d6da 100644 --- a/src/app/components/AlertAdd.svelte +++ b/src/app/components/AlertAdd.svelte @@ -1,7 +1,6 @@ @@ -237,7 +238,7 @@

Space*

{/snippet} {#snippet input()} - {#each getMembershipUrls($userMembership) as url (url)} diff --git a/src/app/components/Alerts.svelte b/src/app/components/Alerts.svelte index 69da8795..416e6122 100644 --- a/src/app/components/Alerts.svelte +++ b/src/app/components/Alerts.svelte @@ -1,20 +1,25 @@
@@ -29,10 +34,10 @@
- {#each $alerts as alert (alert.event.id)} + {#each filteredAlerts as alert (alert.event.id)} {:else} -

No alerts found

+

Nothing here yet!

{/each}
diff --git a/src/app/components/MenuSpace.svelte b/src/app/components/MenuSpace.svelte index d5dc5fbd..32bec002 100644 --- a/src/app/components/MenuSpace.svelte +++ b/src/app/components/MenuSpace.svelte @@ -1,7 +1,7 @@ -
+
@@ -192,9 +182,10 @@ Where did my rooms go? {/if} -
+
+
- diff --git a/src/app/push.ts b/src/app/push.ts index 59e938f8..87a2e9b1 100644 --- a/src/app/push.ts +++ b/src/app/push.ts @@ -5,10 +5,13 @@ import {PushNotifications} from "@capacitor/push-notifications" import {parseJson, poll} from "@welshman/lib" import {isSignedEvent} from "@welshman/util" import {goto} from "$app/navigation" +import {ucFirst} from "@lib/util" import {VAPID_PUBLIC_KEY} from "@app/state" export const platform = Capacitor.getPlatform() +export const platformName = platform === "ios" ? "iOS" : ucFirst(platform) + export const initializePushNotifications = () => { if (platform === "web") return diff --git a/src/app/state.ts b/src/app/state.ts index ed34650e..57610a52 100644 --- a/src/app/state.ts +++ b/src/app/state.ts @@ -65,7 +65,6 @@ import { getTag, getTagValue, getTagValues, - getAddress, } from "@welshman/util" import type {TrustedEvent, SignedEvent, PublishedList, List, Filter} from "@welshman/util" import {Nip59, decrypt} from "@welshman/signer" @@ -349,27 +348,21 @@ export const { // Alerts -export const deviceAlertAddresses = synced("deviceAlertAddresses", []) - export type Alert = { event: TrustedEvent tags: string[][] } -export const alerts = deriveEventsMapped(repository, { - filters: [{kinds: [ALERT_EMAIL, ALERT_WEB, ALERT_IOS, ALERT_ANDROID]}], - itemToEvent: item => item.event, - eventToItem: async event => { - const tags = parseJson(await decrypt(signer.get(), NOTIFIER_PUBKEY, event.content)) +export const alerts = withGetter( + deriveEventsMapped(repository, { + filters: [{kinds: [ALERT_EMAIL, ALERT_WEB, ALERT_IOS, ALERT_ANDROID]}], + itemToEvent: item => item.event, + eventToItem: async event => { + const tags = parseJson(await decrypt(signer.get(), NOTIFIER_PUBKEY, event.content)) - return {event, tags} - }, -}) - -export const deviceAlerts = derived( - [deviceAlertAddresses, alerts], - ([$deviceAlertAddresses, $alerts]) => - $alerts.filter(a => $deviceAlertAddresses.includes(getAddress(a.event))), + return {event, tags} + }, + }), ) // Alert Statuses @@ -379,15 +372,17 @@ export type AlertStatus = { tags: string[][] } -export const alertStatuses = deriveEventsMapped(repository, { - filters: [{kinds: [ALERT_STATUS]}], - itemToEvent: item => item.event, - eventToItem: async event => { - const tags = parseJson(await decrypt(signer.get(), NOTIFIER_PUBKEY, event.content)) +export const alertStatuses = withGetter( + deriveEventsMapped(repository, { + filters: [{kinds: [ALERT_STATUS]}], + itemToEvent: item => item.event, + eventToItem: async event => { + const tags = parseJson(await decrypt(signer.get(), NOTIFIER_PUBKEY, event.content)) - return {event, tags} - }, -}) + return {event, tags} + }, + }), +) export const deriveAlertStatus = (address: string) => derived(alertStatuses, statuses => statuses.find(s => getTagValue("d", s.event.tags) === address))