Skip to content

Commit

Permalink
Improved error message.
Browse files Browse the repository at this point in the history
Signed-off-by: allexzander <blackslayer4@gmail.com>
  • Loading branch information
allexzander committed Jun 14, 2021
1 parent f205d77 commit 6b590be
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
33 changes: 29 additions & 4 deletions src/gui/tray/UserModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
// refreshes of the notifications
#define NOTIFICATION_REQUEST_FREE_PERIOD 15000

namespace {
constexpr qint64 expiredActivitiesCheckIntervalMs = 1000 * 60;
}

namespace OCC {

User::User(AccountStatePtr &account, const bool &isCurrent, QObject *parent)
Expand All @@ -45,6 +49,9 @@ User::User(AccountStatePtr &account, const bool &isCurrent, QObject *parent)
connect(&_notificationCheckTimer, &QTimer::timeout,
this, &User::slotRefresh);

connect(&_expiredActivitiesCheckTimer, &QTimer::timeout,
this, &User::slotCheckExpiredActivities);

connect(_account.data(), &AccountState::stateChanged,
[=]() { if (isConnected()) {slotRefreshImmediately();} });
connect(_account.data(), &AccountState::stateChanged, this, &User::accountStateChanged);
Expand Down Expand Up @@ -147,6 +154,19 @@ void User::slotReceivedPushActivity(Account *account)
}
}

void User::slotCheckExpiredActivities()
{
for (const Activity &activity : _activityModel->errorsList()) {
if (activity._expireAtMsecs > 0 && QDateTime::currentDateTime().toMSecsSinceEpoch() >= activity._expireAtMsecs) {
_activityModel->removeActivityFromActivityList(activity);
}
}

if (_activityModel->errorsList().size() == 0) {
_expiredActivitiesCheckTimer.stop();
}
}

void User::connectPushNotifications() const
{
connect(_account->account().data(), &Account::pushNotificationsDisabled, this, &User::slotDisconnectPushNotifications, Qt::UniqueConnection);
Expand Down Expand Up @@ -330,7 +350,8 @@ void User::slotProgressInfo(const QString &folder, const ProgressInfo &progress)
const auto &engine = f->syncEngine();
const auto style = engine.lastLocalDiscoveryStyle();
foreach (Activity activity, _activityModel->errorsList()) {
if (activity._expireAtMsecs > 0 && QDateTime::currentDateTime().toMSecsSinceEpoch() < activity._expireAtMsecs) {
if (activity._expireAtMsecs > 0) {
// we process expired activities in a different slot
continue;
}
if (activity._folder != folder) {
Expand Down Expand Up @@ -424,27 +445,31 @@ void User::slotAddError(const QString &folderAlias, const QString &message, Erro

void User::slotAddErrorToGui(const QString &folderAlias, SyncFileItem::Status status, const QString &errorMessage)
{
auto folderInstance = FolderMan::instance()->folder(folderAlias);
const auto folderInstance = FolderMan::instance()->folder(folderAlias);
if (!folderInstance)
return;

if (folderInstance->accountState() == _account.data()) {
qCWarning(lcActivity) << "Item " << folderInstance->shortGuiLocalPath() << " retrieved resulted in " << errorMessage;

Activity activity;
activity._type = Activity::SyncResultType;
activity._type = Activity::SyncFileItemType;
activity._status = status;
const auto currentDateTime = QDateTime::currentDateTime();
activity._dateTime = QDateTime::fromString(currentDateTime.toString(), Qt::ISODate);
activity._expireAtMsecs = currentDateTime.addSecs(60 * 1).toMSecsSinceEpoch();
activity._subject = errorMessage;
activity._subject = folderInstance->shortGuiLocalPath();
activity._message = errorMessage;
activity._link = folderInstance->shortGuiLocalPath();
activity._accName = folderInstance->accountState()->account()->displayName();
activity._folder = folderAlias;

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

if (!_expiredActivitiesCheckTimer.isActive()) {
_expiredActivitiesCheckTimer.start(expiredActivitiesCheckIntervalMs);
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/gui/tray/UserModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ public slots:
void slotDisconnectPushNotifications();
void slotReceivedPushNotification(Account *account);
void slotReceivedPushActivity(Account *account);
void slotCheckExpiredActivities();

void connectPushNotifications() const;
bool checkPushNotificationsAreReady() const;
Expand All @@ -110,6 +111,7 @@ public slots:
ActivityListModel *_activityModel;
ActivityList _blacklistedNotifications;

QTimer _expiredActivitiesCheckTimer;
QTimer _notificationCheckTimer;
QHash<AccountState *, QElapsedTimer> _timeSinceLastCheck;

Expand Down

0 comments on commit 6b590be

Please sign in to comment.