|
41 | 41 | } |
42 | 42 | }); |
43 | 43 | refreshBaseUiElements(); |
44 | | - setToolbarBadgeCount(res.totalCount); |
| 44 | + refreshToolbarWidget(); |
45 | 45 | }).catch(function () { |
46 | 46 | // Silently ignore network errors for background notification fetch |
47 | 47 | }); |
|
106 | 106 | }); |
107 | 107 | newAlertNode.addEventListener('closed.bs.alert', function () { |
108 | 108 | refreshBaseUiElements(); |
109 | | - updateToolbarBadge(-1); |
| 109 | + updateToolbarBadgeCount(Math.max(0, getToolbarBadgeCount() - 1)); |
110 | 110 | }); |
111 | 111 | } |
112 | 112 |
|
|
145 | 145 | refreshBaseUiElements(); |
146 | 146 | } |
147 | 147 |
|
148 | | - // Update the toolbar badge count |
149 | | - updateToolbarBadge(1); |
| 148 | + // Update the toolbar badge count directly to avoid stale server cache |
| 149 | + updateToolbarBadgeCount(getToolbarBadgeCount() + 1); |
150 | 150 | }); |
151 | 151 |
|
152 | 152 | connection.onreconnected(function () { |
|
185 | 185 | } |
186 | 186 | } |
187 | 187 |
|
188 | | - function setToolbarBadgeCount(count) { |
189 | | - var newCount = Math.min(99, Math.max(0, count)); |
190 | | - for (const randomId of (window.toolbarNotificationsWidgetAreaRandomIds || [])) { |
191 | | - var $wrapper = $('#ToolbarNotificationsWidgetArea-' + randomId); |
192 | | - var $link = $wrapper.find('.notifications-toolbar-item'); |
193 | | - if ($link.length) { |
194 | | - $link.html('<i class="fas fa-bell"></i> ' + newCount); |
195 | | - } |
196 | | - } |
| 188 | + function updateToolbarBadgeCount(count) { |
| 189 | + $('.notifications-toolbar-item').each(function () { |
| 190 | + var $icon = $(this).find('i'); |
| 191 | + $(this).text(' ' + count).prepend($icon); |
| 192 | + }); |
197 | 193 | } |
198 | 194 |
|
199 | | - function updateToolbarBadge(delta) { |
200 | | - for (const randomId of (window.toolbarNotificationsWidgetAreaRandomIds || [])) { |
201 | | - var $wrapper = $('#ToolbarNotificationsWidgetArea-' + randomId); |
202 | | - var $link = $wrapper.find('.notifications-toolbar-item'); |
203 | | - if ($link.length) { |
204 | | - var currentText = $link.text().trim(); |
205 | | - var currentCount = parseInt(currentText) || 0; |
206 | | - setToolbarBadgeCount(currentCount + delta); |
207 | | - break; |
208 | | - } |
209 | | - } |
| 195 | + function getToolbarBadgeCount() { |
| 196 | + var $first = $('.notifications-toolbar-item').first(); |
| 197 | + if (!$first.length) return 0; |
| 198 | + var text = $first.text().trim(); |
| 199 | + return parseInt(text) || 0; |
210 | 200 | } |
211 | 201 |
|
212 | 202 | function refreshToolbarWidget() { |
|
293 | 283 | maxCreationTime: maxNotificationTime |
294 | 284 | }; |
295 | 285 | easyAbp.processManagement.notifications.notification.dismiss(dismissOpts).then(function () { |
| 286 | + var dismissedCount = existingAlertIds.size; |
296 | 287 | existingAlertIds.forEach(function (alert, id) { |
297 | 288 | removeAlert(alert) |
298 | 289 | }); |
299 | 290 | if (dismiss === 'DismissAll') { |
300 | | - setToolbarBadgeCount(0); |
| 291 | + updateToolbarBadgeCount(0); |
| 292 | + } else { |
| 293 | + updateToolbarBadgeCount(Math.max(0, getToolbarBadgeCount() - dismissedCount)); |
301 | 294 | } |
302 | 295 | }); |
303 | 296 | } |
|
0 commit comments