diff options
| author | Acid Chicken (硫酸鶏) <root@acid-chicken.com> | 2023-04-05 00:41:49 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-04-05 00:41:49 +0900 |
| commit | 7bd0001e763a12c2b2aeb5cf4417f802cd4fbb4c (patch) | |
| tree | 62ca232417372612f78761f26669b56a80d35733 /packages/sw/src/scripts | |
| parent | Merge branch 'develop' into fix/visibility-widening (diff) | |
| parent | enhance(backend): improve cache (diff) | |
| download | misskey-7bd0001e763a12c2b2aeb5cf4417f802cd4fbb4c.tar.gz misskey-7bd0001e763a12c2b2aeb5cf4417f802cd4fbb4c.tar.bz2 misskey-7bd0001e763a12c2b2aeb5cf4417f802cd4fbb4c.zip | |
Merge branch 'develop' into fix/visibility-widening
Diffstat (limited to 'packages/sw/src/scripts')
| -rw-r--r-- | packages/sw/src/scripts/notification-read.ts | 58 |
1 files changed, 0 insertions, 58 deletions
diff --git a/packages/sw/src/scripts/notification-read.ts b/packages/sw/src/scripts/notification-read.ts deleted file mode 100644 index 3b1dde0cd5..0000000000 --- a/packages/sw/src/scripts/notification-read.ts +++ /dev/null @@ -1,58 +0,0 @@ -import { get } from 'idb-keyval'; -import { pushNotificationDataMap } from '@/types'; -import { api } from '@/scripts/operations'; - -type Accounts = { - [x: string]: { - queue: string[], - timeout: number | null - } -}; - -class SwNotificationReadManager { - private accounts: Accounts = {}; - - public async construct() { - const accounts = await get('accounts'); - if (!accounts) Error('Accounts are not recorded'); - - this.accounts = accounts.reduce((acc, e) => { - acc[e.id] = { - queue: [], - timeout: null - }; - return acc; - }, {} as Accounts); - - return this; - } - - // プッシュ通知の既読をサーバーに送信 - public async read(data: pushNotificationDataMap[keyof pushNotificationDataMap]) { - if (data.type !== 'notification' || !(data.userId in this.accounts)) return; - - const account = this.accounts[data.userId]; - - account.queue.push(data.body.id as string); - - if (account.queue.length >= 20) { - if (account.timeout) clearTimeout(account.timeout); - const notificationIds = account.queue; - account.queue = []; - await api('notifications/read', data.userId, { notificationIds }); - return; - } - - // 最後の呼び出しから200ms待ってまとめて処理する - if (account.timeout) clearTimeout(account.timeout); - account.timeout = setTimeout(() => { - account.timeout = null; - - const notificationIds = account.queue; - account.queue = []; - api('notifications/read', data.userId, { notificationIds }); - }, 200); - } -} - -export const swNotificationRead = (new SwNotificationReadManager()).construct(); |