Rename to sendPushSubscriptionReply & remove unused nid argument (#2273)
* Refactor push subscription reply * Remove unused notification id
This commit is contained in:
parent
17aada6dbc
commit
bfced699ea
@ -2,7 +2,7 @@ import { decodeCursor, LIMIT, nextNoteCursorEncoded } from '@/lib/cursor'
|
||||
import { getItem, filterClause, whereClause, muteClause, activeOrMine } from './item'
|
||||
import { getInvoice, getWithdrawl } from './wallet'
|
||||
import { pushSubscriptionSchema, validateSchema } from '@/lib/validate'
|
||||
import { replyToSubscription } from '@/lib/webPush'
|
||||
import { sendPushSubscriptionReply } from '@/lib/webPush'
|
||||
import { getSub } from './sub'
|
||||
import { GqlAuthenticationError, GqlInputError } from '@/lib/error'
|
||||
import { WALLET_MAX_RETRIES, WALLET_RETRY_BEFORE_MS } from '@/lib/constants'
|
||||
@ -439,7 +439,7 @@ export default {
|
||||
console.log(`[webPush] created subscription for user ${me.id}: endpoint=${endpoint}`)
|
||||
}
|
||||
|
||||
await replyToSubscription(dbPushSubscription.id, { title: 'Stacker News notifications are now active' })
|
||||
await sendPushSubscriptionReply(dbPushSubscription)
|
||||
|
||||
return dbPushSubscription
|
||||
},
|
||||
|
@ -116,10 +116,9 @@ async function sendUserNotification (userId, notification) {
|
||||
}
|
||||
}
|
||||
|
||||
export async function replyToSubscription (subscriptionId, notification) {
|
||||
export async function sendPushSubscriptionReply (subscription) {
|
||||
try {
|
||||
const payload = createPayload(notification)
|
||||
const subscription = await models.pushSubscription.findUnique({ where: { id: subscriptionId } })
|
||||
const payload = createPayload({ title: 'Stacker News notifications are now active' })
|
||||
await sendNotification(subscription, payload)
|
||||
} catch (err) {
|
||||
console.log('[webPush] error sending subscription reply: ', err)
|
||||
|
@ -14,7 +14,6 @@ export function onPush (sw) {
|
||||
let payload = event.data?.json()
|
||||
if (!payload) return // ignore push events without payload, like isTrusted events
|
||||
const { tag } = payload.options
|
||||
const nid = crypto.randomUUID() // notification id for tracking
|
||||
|
||||
// iOS requirement: group all promises
|
||||
const promises = []
|
||||
@ -26,7 +25,7 @@ export function onPush (sw) {
|
||||
// Check if there are already notifications with the same tag and merge them
|
||||
promises.push(sw.registration.getNotifications({ tag }).then((notifications) => {
|
||||
if (notifications.length) {
|
||||
payload = mergeNotification(event, sw, payload, notifications, tag, nid)
|
||||
payload = mergeNotification(event, sw, payload, notifications, tag)
|
||||
}
|
||||
}))
|
||||
}
|
||||
@ -44,7 +43,7 @@ const immediatelyShowNotification = (tag) =>
|
||||
!tag || ['TIP', 'FORWARDEDTIP', 'EARN', 'STREAK', 'TERRITORY_TRANSFER'].includes(tag.split('-')[0])
|
||||
|
||||
// merge notifications with the same tag
|
||||
const mergeNotification = (event, sw, payload, currentNotifications, tag, nid) => {
|
||||
const mergeNotification = (event, sw, payload, currentNotifications, tag) => {
|
||||
// sanity check
|
||||
const otherTagNotifications = currentNotifications.filter(({ tag: nTag }) => nTag !== tag)
|
||||
if (otherTagNotifications.length > 0) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user