Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify and remove the notification "cache" #4508

Merged
merged 1 commit into from
May 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions src/gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,6 @@ set(client_SRCS
tray/usermodel.cpp
tray/notificationhandler.h
tray/notificationhandler.cpp
tray/notificationcache.h
tray/notificationcache.cpp
creds/credentialsfactory.h
tray/talkreply.cpp
creds/credentialsfactory.cpp
Expand Down
8 changes: 6 additions & 2 deletions src/gui/owncloudgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@

namespace OCC {

Q_LOGGING_CATEGORY(lcOwnCloudGui, "com.nextcloud.owncloudgui")

const char propertyAccountC[] = "oc_account";

ownCloudGui::ownCloudGui(Application *parent)
Expand Down Expand Up @@ -373,10 +375,12 @@ void ownCloudGui::hideAndShowTray()

void ownCloudGui::slotShowTrayMessage(const QString &title, const QString &msg)
{
if (_tray)
qCDebug(lcOwnCloudGui) << "Going to show notification with title: '" << title << "' and message: '" << msg << "'";
if (_tray) {
_tray->showMessage(title, msg);
else
} else {
qCWarning(lcApplication) << "Tray not ready: " << msg;
}
}

void ownCloudGui::slotShowTrayUpdateMessage(const QString &title, const QString &msg, const QUrl &webUrl)
Expand Down
24 changes: 0 additions & 24 deletions src/gui/tray/notificationcache.cpp

This file was deleted.

28 changes: 0 additions & 28 deletions src/gui/tray/notificationcache.h

This file was deleted.

31 changes: 19 additions & 12 deletions src/gui/tray/usermodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#include "syncfileitem.h"
#include "systray.h"
#include "tray/activitylistmodel.h"
#include "tray/notificationcache.h"
#include "tray/unifiedsearchresultslistmodel.h"
#include "tray/talkreply.h"
#include "userstatusconnector.h"
Expand Down Expand Up @@ -70,8 +69,6 @@ User::User(AccountStatePtr &account, const bool &isCurrent, QObject *parent)

connect(FolderMan::instance(), &FolderMan::folderListChanged, this, &User::hasLocalFolderChanged);

connect(this, &User::guiLog, Logger::instance(), &Logger::guiLog);

connect(_account->account().data(), &Account::accountChangedAvatar, this, &User::avatarChanged);
connect(_account->account().data(), &Account::userStatusChanged, this, &User::statusChanged);
connect(_account.data(), &AccountState::desktopNotificationsAllowedChanged, this, &User::desktopNotificationsAllowedChanged);
Expand All @@ -85,8 +82,15 @@ User::User(AccountStatePtr &account, const bool &isCurrent, QObject *parent)
connect(this, &User::sendReplyMessage, this, &User::slotSendReplyMessage);
}

void User::showDesktopNotification(const QString &title, const QString &message)
void User::showDesktopNotification(const QString &title, const QString &message, const long notificationId)
{
// Notification ids are uints, which are 4 bytes. Error activities don't have ids, however, so we generate one.
// To avoid possible collisions between the activity ids which are actually the notification ids received from
// the server (which are always positive) and our "fake" error activity ids, we assign a negative id to the
// error notification.
//
// To ensure that we can still treat an unsigned int as normal, we use a long, which is 8 bytes.

ConfigFile cfg;
if (!cfg.optionalServerNotifications() || !isDesktopNotificationsAllowed()) {
return;
Expand All @@ -95,16 +99,15 @@ void User::showDesktopNotification(const QString &title, const QString &message)
// after one hour, clear the gui log notification store
constexpr qint64 clearGuiLogInterval = 60 * 60 * 1000;
if (_guiLogTimer.elapsed() > clearGuiLogInterval) {
_notificationCache.clear();
_notifiedNotifications.clear();
}

const NotificationCache::Notification notification { title, message };
if (_notificationCache.contains(notification)) {
if (_notifiedNotifications.contains(notificationId)) {
return;
}

_notificationCache.insert(notification);
emit guiLog(notification.title, notification.message);
_notifiedNotifications.insert(notificationId);
Logger::instance()->postGuiLog(title, message);
// restart the gui log timer now that we show a new notification
_guiLogTimer.start();
}
Expand All @@ -119,7 +122,7 @@ void User::slotBuildNotificationDisplay(const ActivityList &list)
continue;
}
const auto message = AccountManager::instance()->accounts().count() == 1 ? "" : activity._accName;
allexzander marked this conversation as resolved.
Show resolved Hide resolved
showDesktopNotification(activity._subject, message);
showDesktopNotification(activity._subject, message, activity._id); // We assigned the notif. id to the activity id
_activityModel->addNotificationToActivityList(activity);
}
}
Expand Down Expand Up @@ -502,10 +505,13 @@ void User::slotAddErrorToGui(const QString &folderAlias, SyncFileItem::Status st
activity._accName = folderInstance->accountState()->account()->displayName();
activity._folder = folderAlias;

// Error notifications don't have ids by themselves so we will create one for it
activity._id = -static_cast<int>(qHash(activity._subject + activity._message));

// add 'other errors' to activity list
_activityModel->addErrorToActivityList(activity);

showDesktopNotification(activity._subject, activity._message);
showDesktopNotification(activity._subject, activity._message, activity._id);

if (!_expiredActivitiesCheckTimer.isActive()) {
_expiredActivitiesCheckTimer.start(expiredActivitiesCheckIntervalMsecs);
Expand Down Expand Up @@ -607,13 +613,14 @@ void User::processCompletedSyncItem(const Folder *folder, const SyncFileItemPtr
qCWarning(lcActivity) << "Item " << item->_file << " retrieved resulted in error " << item->_errorString;

activity._subject = item->_errorString;
activity._id = -static_cast<int>(qHash(activity._subject + activity._message));

if (item->_status == SyncFileItem::Status::FileIgnored) {
_activityModel->addIgnoredFileToList(activity);
} else {
// add 'protocol error' to activity list
if (item->_status == SyncFileItem::Status::FileNameInvalid) {
showDesktopNotification(item->_file, activity._subject);
showDesktopNotification(item->_file, activity._subject, activity._id);
}
_activityModel->addErrorToActivityList(activity);
}
Expand Down
6 changes: 2 additions & 4 deletions src/gui/tray/usermodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include "accountfwd.h"
#include "accountmanager.h"
#include "folderman.h"
#include "notificationcache.h"
#include "userstatusselectormodel.h"
#include "userstatusconnector.h"
#include <chrono>
Expand Down Expand Up @@ -76,7 +75,6 @@ class User : public QObject
void processCompletedSyncItem(const Folder *folder, const SyncFileItemPtr &item);

signals:
void guiLog(const QString &, const QString &);
void nameChanged();
void hasLocalFolderChanged();
void serverHasTalkChanged();
Expand Down Expand Up @@ -124,7 +122,7 @@ public slots:
bool isActivityOfCurrentAccount(const Folder *folder) const;
bool isUnsolvableConflict(const SyncFileItemPtr &item) const;

void showDesktopNotification(const QString &title, const QString &message);
void showDesktopNotification(const QString &title, const QString &message, const long notificationId);

private:
AccountStatePtr _account;
Expand All @@ -138,7 +136,7 @@ public slots:
QHash<AccountState *, QElapsedTimer> _timeSinceLastCheck;

QElapsedTimer _guiLogTimer;
NotificationCache _notificationCache;
QSet<long> _notifiedNotifications;
QMimeDatabase _mimeDb;

// number of currently running notification requests. If non zero,
Expand Down
1 change: 0 additions & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ nextcloud_add_test(Capabilities)
nextcloud_add_test(PushNotifications)
nextcloud_add_test(Theme)
nextcloud_add_test(IconUtils)
nextcloud_add_test(NotificationCache)
nextcloud_add_test(SetUserStatusDialog)
nextcloud_add_test(UnifiedSearchListmodel)
nextcloud_add_test(ActivityListModel)
Expand Down
40 changes: 0 additions & 40 deletions test/testnotificationcache.cpp

This file was deleted.