@@ -94,6 +94,7 @@ const mergeNotification = (event, sw, payload, currentNotifications, tag, nid) =
94
94
// logger.info(`[sw:push] ${nid} - initial amount: ${initialAmount}`)
95
95
// logger.info(`[sw:push] ${nid} - initial sats: ${initialSats}`)
96
96
97
+ // currentNotifications.reduce causes iOS to sum n notifications + initialAmount which is already n notifications
97
98
const mergedPayload = {
98
99
...incomingData ,
99
100
amount : initialAmount + 1 ,
@@ -132,23 +133,26 @@ const mergeNotification = (event, sw, payload, currentNotifications, tag, nid) =
132
133
133
134
const options = { icon : payload . options ?. icon , tag, data : { url : '/notifications' , ...mergedPayload } }
134
135
// logger.info(`[sw:push] ${nid} - show notification with title "${title}"`)
135
- return { title, options }
136
+ return { title, options } // send the new, merged, payload
136
137
}
137
138
139
+ // iOS-specific bug, notificationclick event only works when the app is closed
138
140
export function onNotificationClick ( sw ) {
139
141
return ( event ) => {
142
+ const promises = [ ]
140
143
// const logger = getLogger('sw:onNotificationClick', ['onNotificationClick'])
141
144
const url = event . notification . data ?. url
142
145
// logger.info(`[sw:onNotificationClick] clicked notification with url ${url}`)
143
146
if ( url ) {
144
- event . waitUntil ( sw . clients . openWindow ( url ) )
147
+ promises . push ( sw . clients . openWindow ( url ) )
145
148
}
146
149
activeCount = Math . max ( 0 , activeCount - 1 )
147
150
if ( activeCount === 0 ) {
148
- clearAppBadge ( sw )
151
+ promises . push ( clearAppBadge ( sw ) )
149
152
} else {
150
- setAppBadge ( sw , activeCount )
153
+ promises . push ( setAppBadge ( sw , activeCount ) )
151
154
}
155
+ event . waitUntil ( Promise . all ( promises ) )
152
156
event . notification . close ( )
153
157
}
154
158
}
0 commit comments