From b6b78591bc1cce47e8c42490ec45d6b9503cba98 Mon Sep 17 00:00:00 2001 From: Jon Staab Date: Wed, 4 Feb 2026 10:37:50 -0800 Subject: [PATCH] Update push impl --- README.md | 2 -- src/app/util/notifications.ts | 45 ++++++++++++++++------------------- 2 files changed, 21 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index 74d6dcda..51731e26 100644 --- a/README.md +++ b/README.md @@ -15,8 +15,6 @@ You can also optionally create an `.env` file and populate it with the following - `VITE_PLATFORM_RELAYS` - A list of comma-separated relay urls that will make flotilla operate in "platform mode". Disables all space browse/add/select functionality and makes the first platform relay the home page. - `VITE_PLATFORM_ACCENT` - A hex color for the app's accent color - `VITE_PLATFORM_DESCRIPTION` - A description of the app -- `VITE_GLITCHTIP_API_KEY` - A Sentry DSN for use with glitchtip (error reporting) -- `GLITCHTIP_AUTH_TOKEN` - A glitchtip auth token for error reporting If you're deploying a custom version of flotilla, be sure to remove the `plausible.coracle.social` script from `app.html`. This sends analytics to a server hosted by the developer. diff --git a/src/app/util/notifications.ts b/src/app/util/notifications.ts index 8d842eed..12f4b883 100644 --- a/src/app/util/notifications.ts +++ b/src/app/util/notifications.ts @@ -5,9 +5,9 @@ import {Badge} from "@capawesome/capacitor-badge" import {PushNotifications} from "@capacitor/push-notifications" import type {ActionPerformed, RegistrationError, Token} from "@capacitor/push-notifications" import {synced, throttled} from "@welshman/store" +import {load, LOCAL_RELAY_URL} from "@welshman/net" import { pubkey, - signer, tracker, repository, relaysByUrl, @@ -23,7 +23,6 @@ import { poll, prop, hash, - parseJson, flatten, find, spec, @@ -47,6 +46,7 @@ import { getPubkeyTagValues, getRelaysFromList, matchFilters, + getIdFilters, sortEventsDesc, makeEvent, Address, @@ -451,7 +451,7 @@ class CapacitorNotifications implements IPushAdapter { _getSubscriptionIdentifier = (relay: string, key: string) => String(hash(relay + key + device.get())) - _getPushStuff = async (url: string) => { + _getPushUrl = async (url: string) => { let relay = await loadRelay(url) if (!relay?.self || !relay?.supported_nips?.map(String)?.includes("9a")) { @@ -459,7 +459,7 @@ class CapacitorNotifications implements IPushAdapter { } if (relay?.self) { - return {url: relay.url, pubkey: relay.self} + return relay.url } } @@ -471,33 +471,24 @@ class CapacitorNotifications implements IPushAdapter { return } - const stuff = await this._getPushStuff(relay) + const url = await this._getPushUrl(relay) - if (!stuff) { + if (!url) { console.warn(`Failed to subscribe ${relay} to notifications: unsupported`) return } - const {url, pubkey} = stuff const identifier = this._getSubscriptionIdentifier(relay, key) const thunk = publishThunk({ relays: [url], event: makeEvent(30390, { - content: await signer - .get() - .nip44.encrypt( - pubkey, - JSON.stringify([ - ["relay", relay], - ["callback", subscription.callback], - ...ignore.map(filter => ["ignore", JSON.stringify(filter)]), - ...filters.map(filter => ["filter", JSON.stringify(filter)]), - ]), - ), tags: [ ["d", identifier], - ["p", pubkey], + ["relay", relay], + ["callback", subscription.callback], + ...ignore.map(filter => ["ignore", JSON.stringify(filter)]), + ...filters.map(filter => ["filter", JSON.stringify(filter)]), ], }), }) @@ -510,14 +501,14 @@ class CapacitorNotifications implements IPushAdapter { } _unsyncRelay = async (relay: string, key: string) => { - const stuff = await this._getPushStuff(relay) + const url = await this._getPushUrl(relay) - if (!stuff) { + if (!url) { console.warn(`Failed to unsubscribe ${relay} from notifications: unsupported`) return } - const relays = [stuff.url] + const relays = [url] const identifier = this._getSubscriptionIdentifier(relay, key) const address = new Address(30390, pubkey.get()!, identifier).toString() const event = makeEvent(DELETE, {tags: [["a", address]]}) @@ -598,11 +589,17 @@ class CapacitorNotifications implements IPushAdapter { PushNotifications.addListener( "pushNotificationActionPerformed", async (action: ActionPerformed) => { - const {relay, pubkey, payload} = action.notification.data - const event = parseJson(await signer.get().nip44.decrypt(pubkey, payload)) + const {relay, id} = action.notification.data + + const [event] = await load({ + relays: [relay, LOCAL_RELAY_URL], + filters: getIdFilters([id]), + }) if (event) { goto(await getEventPath(event, [relay])) + } else { + goto(makeSpacePath(relay)) } }, )