Follow-up (#1394)
This commit is contained in:
parent
b7953f545b
commit
b485a247dc
@ -208,6 +208,11 @@ export function handleClientMessage(e: ExtendableMessageEvent) {
|
||||
e.waitUntil(showNotification(notification));
|
||||
shownNotifications.add(notification.messageId);
|
||||
}
|
||||
if (e.data.type === 'notificationHandled') {
|
||||
const notification: NotificationData = e.data.payload;
|
||||
// mark this notification as shown if it was handled locally
|
||||
shownNotifications.add(notification.messageId);
|
||||
}
|
||||
}
|
||||
|
||||
self.onsync = () => {
|
||||
|
||||
@ -321,7 +321,7 @@ type NotificationData = {
|
||||
icon?: string;
|
||||
};
|
||||
|
||||
const shownNotifications = new Set();
|
||||
const handledNotifications = new Set();
|
||||
let pendingNotifications: Record<number, NotificationData[]> = {};
|
||||
|
||||
async function showNotifications(groupLimit: number = 2) {
|
||||
@ -362,8 +362,8 @@ const flushNotifications = debounce(showNotifications, 1000, false);
|
||||
|
||||
async function handleNotification(data: NotificationData, groupLimit?: number) {
|
||||
// Dont show already triggered notification
|
||||
if (shownNotifications.has(data.messageId)) {
|
||||
shownNotifications.delete(data.messageId);
|
||||
if (handledNotifications.has(data.messageId)) {
|
||||
handledNotifications.delete(data.messageId);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -373,6 +373,18 @@ async function handleNotification(data: NotificationData, groupLimit?: number) {
|
||||
}
|
||||
pendingNotifications[groupId].push(data);
|
||||
await flushNotifications(groupLimit);
|
||||
|
||||
if (checkIfPushSupported()) {
|
||||
if (navigator.serviceWorker.controller) {
|
||||
// notify service worker that notification was handled locally
|
||||
navigator.serviceWorker.controller.postMessage({
|
||||
type: 'notificationHandled',
|
||||
payload: data,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
handledNotifications.add(data.messageId);
|
||||
}
|
||||
|
||||
function showNotification(data: NotificationData) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user