Update push impl

This commit is contained in:
Jon Staab
2026-02-04 10:37:50 -08:00
parent ec54a0dbce
commit b6b78591bc
2 changed files with 21 additions and 26 deletions
-2
View File
@@ -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_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_ACCENT` - A hex color for the app's accent color
- `VITE_PLATFORM_DESCRIPTION` - A description of the app - `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. 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.
+21 -24
View File
@@ -5,9 +5,9 @@ import {Badge} from "@capawesome/capacitor-badge"
import {PushNotifications} from "@capacitor/push-notifications" import {PushNotifications} from "@capacitor/push-notifications"
import type {ActionPerformed, RegistrationError, Token} from "@capacitor/push-notifications" import type {ActionPerformed, RegistrationError, Token} from "@capacitor/push-notifications"
import {synced, throttled} from "@welshman/store" import {synced, throttled} from "@welshman/store"
import {load, LOCAL_RELAY_URL} from "@welshman/net"
import { import {
pubkey, pubkey,
signer,
tracker, tracker,
repository, repository,
relaysByUrl, relaysByUrl,
@@ -23,7 +23,6 @@ import {
poll, poll,
prop, prop,
hash, hash,
parseJson,
flatten, flatten,
find, find,
spec, spec,
@@ -47,6 +46,7 @@ import {
getPubkeyTagValues, getPubkeyTagValues,
getRelaysFromList, getRelaysFromList,
matchFilters, matchFilters,
getIdFilters,
sortEventsDesc, sortEventsDesc,
makeEvent, makeEvent,
Address, Address,
@@ -451,7 +451,7 @@ class CapacitorNotifications implements IPushAdapter {
_getSubscriptionIdentifier = (relay: string, key: string) => _getSubscriptionIdentifier = (relay: string, key: string) =>
String(hash(relay + key + device.get())) String(hash(relay + key + device.get()))
_getPushStuff = async (url: string) => { _getPushUrl = async (url: string) => {
let relay = await loadRelay(url) let relay = await loadRelay(url)
if (!relay?.self || !relay?.supported_nips?.map(String)?.includes("9a")) { if (!relay?.self || !relay?.supported_nips?.map(String)?.includes("9a")) {
@@ -459,7 +459,7 @@ class CapacitorNotifications implements IPushAdapter {
} }
if (relay?.self) { if (relay?.self) {
return {url: relay.url, pubkey: relay.self} return relay.url
} }
} }
@@ -471,33 +471,24 @@ class CapacitorNotifications implements IPushAdapter {
return 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`) console.warn(`Failed to subscribe ${relay} to notifications: unsupported`)
return return
} }
const {url, pubkey} = stuff
const identifier = this._getSubscriptionIdentifier(relay, key) const identifier = this._getSubscriptionIdentifier(relay, key)
const thunk = publishThunk({ const thunk = publishThunk({
relays: [url], relays: [url],
event: makeEvent(30390, { 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: [ tags: [
["d", identifier], ["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) => { _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`) console.warn(`Failed to unsubscribe ${relay} from notifications: unsupported`)
return return
} }
const relays = [stuff.url] const relays = [url]
const identifier = this._getSubscriptionIdentifier(relay, key) const identifier = this._getSubscriptionIdentifier(relay, key)
const address = new Address(30390, pubkey.get()!, identifier).toString() const address = new Address(30390, pubkey.get()!, identifier).toString()
const event = makeEvent(DELETE, {tags: [["a", address]]}) const event = makeEvent(DELETE, {tags: [["a", address]]})
@@ -598,11 +589,17 @@ class CapacitorNotifications implements IPushAdapter {
PushNotifications.addListener( PushNotifications.addListener(
"pushNotificationActionPerformed", "pushNotificationActionPerformed",
async (action: ActionPerformed) => { async (action: ActionPerformed) => {
const {relay, pubkey, payload} = action.notification.data const {relay, id} = action.notification.data
const event = parseJson(await signer.get().nip44.decrypt(pubkey, payload))
const [event] = await load({
relays: [relay, LOCAL_RELAY_URL],
filters: getIdFilters([id]),
})
if (event) { if (event) {
goto(await getEventPath(event, [relay])) goto(await getEventPath(event, [relay]))
} else {
goto(makeSpacePath(relay))
} }
}, },
) )