Make sure we do not renotify notifications when we have received the same etag as...
authorClaudio Cambra <claudio.cambra@nextcloud.com>
Tue, 6 Aug 2024 08:21:49 +0000 (16:21 +0800)
committerbackportbot[bot] <backportbot[bot]@users.noreply.github.com>
Thu, 12 Sep 2024 08:54:00 +0000 (08:54 +0000)
Do this regardless of what the server's response is

Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
src/gui/tray/notificationhandler.cpp
src/gui/tray/notificationhandler.h

index 74db3cd33f141c0921a455aeb4c63afdf36101c9..46e876b66a6972a0d2b54626c06f0986d94aa140 100644 (file)
@@ -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<AccountState *>(sender()->property(propertyAccountStateC));
index 8c3a079506610a859bd3eb218b18cbfc4d9581fb..e8c536372fd45810fa3e3db971691ad67f96b389 100644 (file)
@@ -30,6 +30,7 @@ private slots:
 private:
     QPointer<JsonApiJob> _notificationJob;
     AccountState *_accountState;
+    QString _preFetchEtagHeader;
 };
 }