This commit is contained in:
tamaina 2021-02-10 22:30:02 +09:00
parent 1fca78f0a1
commit 9e0f53a7e7
3 changed files with 28 additions and 28 deletions

View file

@ -1,4 +1,4 @@
import { get } from "idb-keyval";
import { get } from 'idb-keyval';
import { pushNotificationData } from '../../types';
type Accounts = {
@ -32,16 +32,16 @@ class SwNotificationRead {
public async read(data: pushNotificationData) {
if (data.type !== 'notification' || !(data.userId in this.accounts)) return;
const account = this.accounts[data.userId]
const account = this.accounts[data.userId];
account.queue.push(data.body.id)
account.queue.push(data.body.id);
// 最後の呼び出しから100ms待ってまとめて処理する
if (account.timeout) clearTimeout(account.timeout);
account.timeout = setTimeout(() => {
account.timeout = null;
console.info(account.token, account.queue)
console.info(account.token, account.queue);
fetch(`${location.origin}/api/notifications/read`, {
method: 'POST',
body: JSON.stringify({

View file

@ -71,8 +71,8 @@ self.addEventListener('push', ev => {
case 'readNotifications':
for (const notification of await self.registration.getNotifications()) {
if (data.body.notificationIds.includes(notification.data.body.id)) {
notification.close()
};
notification.close();
}
}
break;
}