diff options
author | zeripath <art27@cantab.net> | 2021-07-17 17:18:10 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-17 17:18:10 +0100 |
commit | 93f31e1897562a588bed1227e46d1a5b34f52524 (patch) | |
tree | e7effbf4073f92b60dbf3db08ac4f1a1ea5fb1b9 /web_src | |
parent | b08e14bbcf1b30c5266d89f6fdcc3a6cfa0324fa (diff) | |
download | gitea-93f31e1897562a588bed1227e46d1a5b34f52524.tar.gz gitea-93f31e1897562a588bed1227e46d1a5b34f52524.zip |
Update notification table with only latest data (#16445)
When marking notifications read the results may be returned out of order
or be delayed. This PR sends a sequence number to gitea so that the
browser can ensure that only the results of the latest notification
change are shown.
Signed-off-by: Andrew Thornton <art27@cantab.net>
Co-authored-by: 6543 <6543@obermui.de>
Diffstat (limited to 'web_src')
-rw-r--r-- | web_src/js/features/notification.js | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/web_src/js/features/notification.js b/web_src/js/features/notification.js index 4fa2d3c29a..d964ffa305 100644 --- a/web_src/js/features/notification.js +++ b/web_src/js/features/notification.js @@ -1,5 +1,7 @@ const {AppSubUrl, csrf, NotificationSettings} = window.config; +let notificationSequenceNumber = 0; + export function initNotificationsTable() { $('#notification_table .button').on('click', async function () { const data = await updateNotification( @@ -10,8 +12,10 @@ export function initNotificationsTable() { $(this).data('notification-id'), ); - $('#notification_div').replaceWith(data); - initNotificationsTable(); + if ($(data).data('sequence-number') === notificationSequenceNumber) { + $('#notification_div').replaceWith(data); + initNotificationsTable(); + } await updateNotificationCount(); return false; @@ -139,10 +143,13 @@ async function updateNotificationTable() { url: `${AppSubUrl}/notifications?${notificationDiv.data('params')}`, data: { 'div-only': true, + 'sequence-number': ++notificationSequenceNumber, } }); - notificationDiv.replaceWith(data); - initNotificationsTable(); + if ($(data).data('sequence-number') === notificationSequenceNumber) { + notificationDiv.replaceWith(data); + initNotificationsTable(); + } } } @@ -182,6 +189,7 @@ async function updateNotification(url, status, page, q, notificationID) { page, q, noredirect: true, + 'sequence-number': ++notificationSequenceNumber, }, }); } |