Fix push notification taps landing on the space, and DM notifications never firing (#401)
Co-authored-by: Coracle-Bot <npub1klq6260@nostr.local>
This commit is contained in:
parent
133cd1bba2
commit
a4cec9caf2
1 changed files with 30 additions and 9 deletions
|
|
@ -17,6 +17,7 @@ import {
|
||||||
tagSpec,
|
tagSpec,
|
||||||
tagValue,
|
tagValue,
|
||||||
MESSAGE,
|
MESSAGE,
|
||||||
|
WRAP,
|
||||||
type Filter,
|
type Filter,
|
||||||
type TrustedEvent,
|
type TrustedEvent,
|
||||||
} from "@welshman/util"
|
} from "@welshman/util"
|
||||||
|
|
@ -25,7 +26,7 @@ import {User} from "@welshman/app"
|
||||||
import {app, messagingRelayLists, network, roomLists} from "@app/core"
|
import {app, messagingRelayLists, network, roomLists} from "@app/core"
|
||||||
import {DM_KINDS, CONTENT_KINDS, makeCommentFilter} from "@app/content"
|
import {DM_KINDS, CONTENT_KINDS, makeCommentFilter} from "@app/content"
|
||||||
import {getMutedRooms, notificationSettings, shouldNotify, userSettingsValues} from "@app/settings"
|
import {getMutedRooms, notificationSettings, shouldNotify, userSettingsValues} from "@app/settings"
|
||||||
import {makeEventPath, goToSpace} from "@app/routes"
|
import {makeEventPath, goToChat, goToSpace} from "@app/routes"
|
||||||
|
|
||||||
export type PushSubscription = {
|
export type PushSubscription = {
|
||||||
key: string
|
key: string
|
||||||
|
|
@ -101,16 +102,36 @@ export const onNotification = call(() => {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
export const onPushNotificationAction = async (action: ActionPerformed) => {
|
const loadNotificationEvent = (relay: string, id: string) =>
|
||||||
const {relay, id} = action.notification.data
|
network.get().request({
|
||||||
|
|
||||||
const [event] = await network.get().load({
|
|
||||||
relays: [relay, LOCAL_RELAY_URL],
|
|
||||||
filters: getIdFilters([id]),
|
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),
|
||||||
})
|
})
|
||||||
|
|
||||||
if (event) {
|
// Wraps are ingested into the repository and unwrapped in the background, so wait for the rumor
|
||||||
goto(await makeEventPath(event, [relay]))
|
const loadNotificationRumor = async (wrap: TrustedEvent) => {
|
||||||
|
const getRumor = () => app.get().wrapManager.getRumor(wrap.id)
|
||||||
|
|
||||||
|
await poll({condition: () => Boolean(getRumor()), signal: AbortSignal.timeout(5000)})
|
||||||
|
|
||||||
|
return getRumor()
|
||||||
|
}
|
||||||
|
|
||||||
|
export const onPushNotificationAction = async (action: ActionPerformed) => {
|
||||||
|
const {relay, id} = action.notification.data
|
||||||
|
const [event] = await loadNotificationEvent(relay, id)
|
||||||
|
const target = event?.kind === WRAP ? await loadNotificationRumor(event) : event
|
||||||
|
const path = target && makeEventPath(target, [relay])
|
||||||
|
|
||||||
|
// Kinds we have no route for get a coracle.social permalink, which goto refuses
|
||||||
|
if (path && !path.includes("://")) {
|
||||||
|
goto(path)
|
||||||
|
} else if (event?.kind === WRAP) {
|
||||||
|
goToChat()
|
||||||
} else {
|
} else {
|
||||||
goToSpace(relay)
|
goToSpace(relay)
|
||||||
}
|
}
|
||||||
|
|
@ -209,7 +230,7 @@ export const syncRelaySubscriptions = (
|
||||||
const filters: Filter[] = []
|
const filters: Filter[] = []
|
||||||
|
|
||||||
if (messages) {
|
if (messages) {
|
||||||
filters.push({kinds: DM_KINDS, "#p": [$pubkey]})
|
filters.push({kinds: [WRAP], "#p": [$pubkey]})
|
||||||
}
|
}
|
||||||
|
|
||||||
sync(url, "messages", filters, [])
|
sync(url, "messages", filters, [])
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue