Skip to content

Commit

Permalink
Merge pull request #6970 from nextcloud/bugfix/prevent-renotification
Browse files Browse the repository at this point in the history
Make sure we do not renotify notifications when we have received the same etag as during the last check
  • Loading branch information
mgallien authored Sep 12, 2024
2 parents 804cb1d + 6b0e485 commit 4cd63d8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/gui/tray/notificationhandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.isEmpty() || _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));
Expand Down
1 change: 1 addition & 0 deletions src/gui/tray/notificationhandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ private slots:
private:
QPointer<JsonApiJob> _notificationJob;
AccountState *_accountState;
QString _preFetchEtagHeader;
};
}

Expand Down

0 comments on commit 4cd63d8

Please sign in to comment.