Move alerts to their own page, add direct message alerts
This commit is contained in:
+19
-12
@@ -2,7 +2,7 @@ import * as nip19 from "nostr-tools/nip19"
|
||||
import {Capacitor} from "@capacitor/core"
|
||||
import type {ActionPerformed, RegistrationError, Token} from "@capacitor/push-notifications"
|
||||
import {PushNotifications} from "@capacitor/push-notifications"
|
||||
import {parseJson, poll} from "@welshman/lib"
|
||||
import {parseJson, sleep, poll} from "@welshman/lib"
|
||||
import {isSignedEvent} from "@welshman/util"
|
||||
import {goto} from "$app/navigation"
|
||||
import {ucFirst} from "@lib/util"
|
||||
@@ -50,6 +50,8 @@ export const getWebPushInfo = async () => {
|
||||
}
|
||||
|
||||
const registration = await navigator.serviceWorker.ready
|
||||
|
||||
// This will hang on firefox in development builds, but works in production
|
||||
let subscription = await registration.pushManager.getSubscription()
|
||||
|
||||
if (!subscription) {
|
||||
@@ -118,14 +120,19 @@ export const getCapacitorPushInfo = async () => {
|
||||
return info
|
||||
}
|
||||
|
||||
export const getPushInfo = (): Promise<Record<string, string>> => {
|
||||
switch (platform) {
|
||||
case "web":
|
||||
return getWebPushInfo()
|
||||
case "ios":
|
||||
case "android":
|
||||
return getCapacitorPushInfo()
|
||||
default:
|
||||
throw new Error(`Invalid push platform: ${platform}`)
|
||||
}
|
||||
}
|
||||
export const getPushInfo = (): Promise<Record<string, string>> =>
|
||||
new Promise((resolve, reject) => {
|
||||
sleep(3000).then(() => reject("Failed to request notification permissions"))
|
||||
|
||||
switch (platform) {
|
||||
case "web":
|
||||
getWebPushInfo().then(resolve, reject)
|
||||
break
|
||||
case "ios":
|
||||
case "android":
|
||||
getCapacitorPushInfo().then(resolve, reject)
|
||||
break
|
||||
default:
|
||||
reject(`Invalid push platform: ${platform}`)
|
||||
}
|
||||
})
|
||||
|
||||
+17
-11
@@ -14,8 +14,10 @@ import {
|
||||
THREAD,
|
||||
ZAP_GOAL,
|
||||
EVENT_TIME,
|
||||
getPubkeyTagValues,
|
||||
} from "@welshman/util"
|
||||
import {
|
||||
ensureUnwrapped,
|
||||
makeChatId,
|
||||
entityLink,
|
||||
decodeRelay,
|
||||
@@ -74,24 +76,28 @@ export const getPrimaryNavItemIndex = ($page: Page) => {
|
||||
}
|
||||
|
||||
export const goToEvent = async (event: TrustedEvent, options: Record<string, any> = {}) => {
|
||||
if (event.kind === DIRECT_MESSAGE || event.kind === DIRECT_MESSAGE_FILE) {
|
||||
await scrollToEvent(event.id)
|
||||
}
|
||||
const unwrapped = await ensureUnwrapped(event)
|
||||
|
||||
const urls = Array.from(tracker.getRelays(event.id))
|
||||
const path = await getEventPath(event, urls)
|
||||
if (unwrapped) {
|
||||
const urls = Array.from(tracker.getRelays(unwrapped.id))
|
||||
const path = await getEventPath(unwrapped, urls)
|
||||
|
||||
if (path.includes("://")) {
|
||||
window.open(path)
|
||||
} else {
|
||||
goto(path, options)
|
||||
if (path.includes("://")) {
|
||||
window.open(path)
|
||||
} else {
|
||||
goto(path, options)
|
||||
|
||||
await sleep(300)
|
||||
await scrollToEvent(event.id)
|
||||
await sleep(300)
|
||||
await scrollToEvent(unwrapped.id)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const getEventPath = async (event: TrustedEvent, urls: string[]) => {
|
||||
if (event.kind === DIRECT_MESSAGE || event.kind === DIRECT_MESSAGE_FILE) {
|
||||
return makeChatPath([event.pubkey, ...getPubkeyTagValues(event.tags)])
|
||||
}
|
||||
|
||||
const room = getTagValue(ROOM, event.tags)
|
||||
|
||||
if (urls.length > 0) {
|
||||
|
||||
Reference in New Issue
Block a user