From e5e29101fdcf69689d34a1bf391a3da1bc166cdb Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Sun, 11 Feb 2024 16:46:19 +0200 Subject: [PATCH] web socket wait interval --- client/src/views/notification/badge.js | 39 ++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/client/src/views/notification/badge.js b/client/src/views/notification/badge.js index a9d656d1e4..71aba23802 100644 --- a/client/src/views/notification/badge.js +++ b/client/src/views/notification/badge.js @@ -34,6 +34,7 @@ class NotificationBadgeView extends View { notificationsCheckInterval = 10 groupedCheckInterval = 15 + waitInterval = 2 /** @private */ useWebSocket = false @@ -249,9 +250,7 @@ class NotificationBadgeView extends View { this.checkUpdates(isFirstCheck); if (this.useWebSocket) { - this.getHelper().webSocketManager.subscribe('newNotification', () => { - this.checkUpdates(); - }); + this.initWebSocketCheckUpdates(); return; } @@ -262,6 +261,40 @@ class NotificationBadgeView extends View { ); } + /** + * @private + */ + initWebSocketCheckUpdates() { + let isBlocked = false; + let hasBeenBlocked = false; + + const onWebSocketNewNotification = () => { + if (isBlocked) { + hasBeenBlocked = true; + + return; + } + + this.checkUpdates(); + + isBlocked = true; + + setTimeout(() => { + const reRun = hasBeenBlocked; + + isBlocked = false; + hasBeenBlocked = false; + + if (reRun) { + onWebSocketNewNotification(); + } + + }, this.waitInterval * 1000); + }; + + this.getHelper().webSocketManager.subscribe('newNotification', () => onWebSocketNewNotification()); + } + /** * @private * @return {boolean}