summaryrefslogtreecommitdiff
path: root/packages/sw/src/scripts
diff options
context:
space:
mode:
authortamaina <tamaina@hotmail.co.jp>2022-06-12 19:28:13 +0900
committerGitHub <noreply@github.com>2022-06-12 19:28:13 +0900
commit11a6bd890cc752ee7abd2890773054743433eae1 (patch)
tree06caab47ade7484de8fd933f61aa316946e6252a /packages/sw/src/scripts
parent12.111.0 (diff)
downloadsharkey-11a6bd890cc752ee7abd2890773054743433eae1.tar.gz
sharkey-11a6bd890cc752ee7abd2890773054743433eae1.tar.bz2
sharkey-11a6bd890cc752ee7abd2890773054743433eae1.zip
fix: some fixes of multiple notification read (#8819)
* fix: limit multiple notification read * fix * fix
Diffstat (limited to 'packages/sw/src/scripts')
-rw-r--r--packages/sw/src/scripts/notification-read.ts12
1 files changed, 11 insertions, 1 deletions
diff --git a/packages/sw/src/scripts/notification-read.ts b/packages/sw/src/scripts/notification-read.ts
index 8433f902b4..5c1de89088 100644
--- a/packages/sw/src/scripts/notification-read.ts
+++ b/packages/sw/src/scripts/notification-read.ts
@@ -37,12 +37,22 @@ class SwNotificationReadManager {
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;
- api('notifications/read', data.userId, { notificationIds: account.queue });
+ const notificationIds = account.queue;
+ account.queue = [];
+ api('notifications/read', data.userId, { notificationIds });
}, 200);
}
}