Use the event in the push payload when the relay sends one (#420)
Co-authored-by: Coracle-Bot <npub1klq6260@nostr.local>
This commit is contained in:
parent
434fc954ce
commit
27fd98408f
2 changed files with 26 additions and 12 deletions
|
|
@ -109,6 +109,7 @@ export class CapacitorNotifications implements IPushAdapter {
|
||||||
["d", identifier],
|
["d", identifier],
|
||||||
["relay", relay],
|
["relay", relay],
|
||||||
["callback", subscription.callback],
|
["callback", subscription.callback],
|
||||||
|
["include_event"],
|
||||||
...ignore.map(filter => ["ignore", JSON.stringify(filter)]),
|
...ignore.map(filter => ["ignore", JSON.stringify(filter)]),
|
||||||
...filters.map(filter => ["filter", JSON.stringify(filter)]),
|
...filters.map(filter => ["filter", JSON.stringify(filter)]),
|
||||||
],
|
],
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ import {
|
||||||
} from "@capacitor/push-notifications"
|
} from "@capacitor/push-notifications"
|
||||||
import type {PluginListenerHandle} from "@capacitor/core"
|
import type {PluginListenerHandle} from "@capacitor/core"
|
||||||
import {goto} from "$app/navigation"
|
import {goto} from "$app/navigation"
|
||||||
import {assoc, call, now, on, poll, spec, throttle, uniq} from "@welshman/lib"
|
import {assoc, call, now, on, parseJson, poll, spec, throttle, uniq} from "@welshman/lib"
|
||||||
import {LOCAL_RELAY_URL} from "@welshman/net"
|
import {LOCAL_RELAY_URL} from "@welshman/net"
|
||||||
import type {RepositoryUpdate} from "@welshman/net"
|
import type {RepositoryUpdate} from "@welshman/net"
|
||||||
import {
|
import {
|
||||||
|
|
@ -16,6 +16,7 @@ import {
|
||||||
matchFilters,
|
matchFilters,
|
||||||
tagSpec,
|
tagSpec,
|
||||||
tagValue,
|
tagValue,
|
||||||
|
verifyEvent,
|
||||||
MESSAGE,
|
MESSAGE,
|
||||||
WRAP,
|
WRAP,
|
||||||
type Filter,
|
type Filter,
|
||||||
|
|
@ -102,15 +103,27 @@ export const onNotification = call(() => {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
const loadNotificationEvent = (relay: string, id: string) =>
|
const ingestNotification = async (relay: string, id: string, json?: string) => {
|
||||||
network.get().request({
|
const pushed = parseJson<TrustedEvent>(json)
|
||||||
filters: getIdFilters([id]),
|
|
||||||
relays: [relay, LOCAL_RELAY_URL],
|
if (pushed && verifyEvent(pushed)) {
|
||||||
// The local relay eoses immediately, so anything less waits on it alone
|
app.get().tracker.track(pushed.id, relay)
|
||||||
threshold: 1,
|
app.get().repository.publish(pushed)
|
||||||
autoClose: true,
|
|
||||||
signal: AbortSignal.timeout(5000),
|
return pushed
|
||||||
})
|
} else {
|
||||||
|
const events = await network.get().request({
|
||||||
|
filters: getIdFilters([id]),
|
||||||
|
relays: [relay, LOCAL_RELAY_URL],
|
||||||
|
// The local relay eoses immediately, so anything less waits on it alone
|
||||||
|
threshold: 1,
|
||||||
|
autoClose: true,
|
||||||
|
signal: AbortSignal.timeout(5000),
|
||||||
|
})
|
||||||
|
|
||||||
|
return events[0]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Wraps are ingested into the repository and unwrapped in the background, so wait for the rumor
|
// Wraps are ingested into the repository and unwrapped in the background, so wait for the rumor
|
||||||
const loadNotificationRumor = async (wrap: TrustedEvent) => {
|
const loadNotificationRumor = async (wrap: TrustedEvent) => {
|
||||||
|
|
@ -122,8 +135,8 @@ const loadNotificationRumor = async (wrap: TrustedEvent) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
export const onPushNotificationAction = async (action: ActionPerformed) => {
|
export const onPushNotificationAction = async (action: ActionPerformed) => {
|
||||||
const {relay, id} = action.notification.data
|
const {relay, id, event: json} = action.notification.data
|
||||||
const [event] = await loadNotificationEvent(relay, id)
|
const event = await ingestNotification(relay, id, json)
|
||||||
const target = event?.kind === WRAP ? await loadNotificationRumor(event) : event
|
const target = event?.kind === WRAP ? await loadNotificationRumor(event) : event
|
||||||
const path = target && makeEventPath(target, [relay])
|
const path = target && makeEventPath(target, [relay])
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue