From 410e80b4236905d1684563c1d0f11a77fdf7b0f5 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Tue, 6 Aug 2024 16:21:49 +0800 Subject: [PATCH 1/2] Make sure we do not renotify notifications when we have received the same etag as during the last check Do this regardless of what the server's response is Signed-off-by: Claudio Cambra --- src/gui/tray/notificationhandler.cpp | 11 +++++++++++ src/gui/tray/notificationhandler.h | 1 + 2 files changed, 12 insertions(+) diff --git a/src/gui/tray/notificationhandler.cpp b/src/gui/tray/notificationhandler.cpp index 74db3cd33f141..46e876b66a697 100644 --- a/src/gui/tray/notificationhandler.cpp +++ b/src/gui/tray/notificationhandler.cpp @@ -78,6 +78,17 @@ void ServerNotificationHandler::slotNotificationsReceived(const QJsonDocument &j return; } + // In theory the server should five us a 304 Not Modified if there are no new notifications. + // But in practice, the server doesn't always do that. So we need to compare the ETag headers. + const auto postFetchEtagHeader = _accountState->notificationsEtagResponseHeader(); + if (_preFetchEtagHeader == postFetchEtagHeader) { + qCInfo(lcServerNotification) << "Notifications ETag header is the same as before, no new notifications."; + deleteLater(); + emit jobFinished(); + return; + } + _preFetchEtagHeader = postFetchEtagHeader; + auto notifies = json.object().value("ocs").toObject().value("data").toArray(); auto *ai = qvariant_cast(sender()->property(propertyAccountStateC)); diff --git a/src/gui/tray/notificationhandler.h b/src/gui/tray/notificationhandler.h index 8c3a079506610..e8c536372fd45 100644 --- a/src/gui/tray/notificationhandler.h +++ b/src/gui/tray/notificationhandler.h @@ -30,6 +30,7 @@ private slots: private: QPointer _notificationJob; AccountState *_accountState; + QString _preFetchEtagHeader; }; } From 4417d98c26ff24e39703d231b0935081c39a6c33 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Tue, 6 Aug 2024 16:52:39 +0800 Subject: [PATCH 2/2] Notify even if pre-fetch etag header is empty This prevents situations where the server does not provide an etag header. This would make the empty pre-fetch and empty post-fetch etag headers match, meaning notifications would never be notified Signed-off-by: Claudio Cambra --- src/gui/tray/notificationhandler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/tray/notificationhandler.cpp b/src/gui/tray/notificationhandler.cpp index 46e876b66a697..b2a9fc78b9b24 100644 --- a/src/gui/tray/notificationhandler.cpp +++ b/src/gui/tray/notificationhandler.cpp @@ -81,7 +81,7 @@ void ServerNotificationHandler::slotNotificationsReceived(const QJsonDocument &j // In theory the server should five us a 304 Not Modified if there are no new notifications. // But in practice, the server doesn't always do that. So we need to compare the ETag headers. const auto postFetchEtagHeader = _accountState->notificationsEtagResponseHeader(); - if (_preFetchEtagHeader == postFetchEtagHeader) { + if (!_preFetchEtagHeader.isEmpty() || _preFetchEtagHeader == postFetchEtagHeader) { qCInfo(lcServerNotification) << "Notifications ETag header is the same as before, no new notifications."; deleteLater(); emit jobFinished();