From 9e0f53a7e76dcfdc4ce58b9ff2f9e611686e03ef Mon Sep 17 00:00:00 2001 From: tamaina Date: Wed, 10 Feb 2021 22:30:02 +0900 Subject: [PATCH] fix --- src/client/sw/notification-read.ts | 46 +++++++++++++++--------------- src/client/sw/sw.ts | 4 +-- src/types.ts | 6 ++-- 3 files changed, 28 insertions(+), 28 deletions(-) diff --git a/src/client/sw/notification-read.ts b/src/client/sw/notification-read.ts index b4fad05632..e45f2623cf 100644 --- a/src/client/sw/notification-read.ts +++ b/src/client/sw/notification-read.ts @@ -1,47 +1,47 @@ -import { get } from "idb-keyval"; +import { get } from 'idb-keyval'; import { pushNotificationData } from '../../types'; type Accounts = { - [x: string]: { - queue: string[], - timeout: number | null, - token: string, - } + [x: string]: { + queue: string[], + timeout: number | null, + token: string, + } }; class SwNotificationRead { private accounts: Accounts = {}; - public async construct() { - const accounts = await get('accounts') as { i: string, id: string }[]; - if (accounts) Error('Account is not recorded'); + public async construct() { + const accounts = await get('accounts') as { i: string, id: string }[]; + if (accounts) Error('Account is not recorded'); this.accounts = accounts.reduce((acc, e) => { - acc[e.id] = { - queue: [], - timeout: null, - token: e.i, - }; - return acc; - }, {} as Accounts); + acc[e.id] = { + queue: [], + timeout: null, + token: e.i, + }; + return acc; + }, {} as Accounts); - return this; - } + return this; + } // プッシュ通知の既読をサーバーに送信 public async read(data: pushNotificationData) { - if (data.type !== 'notification' || !(data.userId in this.accounts)) return; + 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待ってまとめて処理する + // 最後の呼び出しから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({ diff --git a/src/client/sw/sw.ts b/src/client/sw/sw.ts index e76a49392d..43e9afd9c8 100644 --- a/src/client/sw/sw.ts +++ b/src/client/sw/sw.ts @@ -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; } diff --git a/src/types.ts b/src/types.ts index e012baf849..b9b676c861 100644 --- a/src/types.ts +++ b/src/types.ts @@ -5,7 +5,7 @@ export const noteVisibilities = ['public', 'home', 'followers', 'specified'] as export const mutedNoteReasons = ['word', 'manual', 'spam', 'other'] as const; export type pushNotificationData = { - type: 'notification' | 'unreadMessagingMessage' | 'readNotifications' | 'readAllNotifications', - body: any, - userId: string + type: 'notification' | 'unreadMessagingMessage' | 'readNotifications' | 'readAllNotifications', + body: any, + userId: string };