3838#include " libsync/graphapi/spacesmanager.h"
3939#include " libsync/syncresult.h"
4040#include " libsync/theme.h"
41+ #include " networkjobs/jsonjob.h"
4142#include " scheduling/syncscheduler.h"
4243#include " settingsdialog.h"
4344
4647#include < QSortFilterProxyModel>
4748#include < QtQuickWidgets/QtQuickWidgets>
4849
50+ using namespace std ::chrono_literals;
51+
4952namespace {
5053constexpr auto modalWidgetStretchedMarginC = 50 ;
5154}
@@ -91,6 +94,11 @@ AccountSettings::AccountSettings(const AccountStatePtr &accountState, QWidget *p
9194 }
9295 });
9396 ui->stackedWidget ->setCurrentWidget (ui->quickWidget );
97+
98+ auto *notificationsPollTimer = new QTimer (this );
99+ notificationsPollTimer->setInterval (1min);
100+ notificationsPollTimer->start ();
101+ connect (notificationsPollTimer, &QTimer::timeout, this , &AccountSettings::updateNotifications);
94102}
95103
96104void AccountSettings::slotToggleSignInState ()
@@ -102,6 +110,20 @@ void AccountSettings::slotToggleSignInState()
102110 }
103111}
104112
113+ void AccountSettings::markNotificationsRead ()
114+ {
115+ if (!_notifications.isEmpty ()) {
116+ auto *job = Notification::dismissAllNotifications (_accountState->account (), _notifications, this );
117+ connect (job, &JsonApiJob::finishedSignal, this , [job, this ] {
118+ if (job->httpStatusCode () == 200 ) {
119+ _notifications.clear ();
120+ Q_EMIT notificationsChanged ();
121+ }
122+ });
123+ job->start ();
124+ }
125+ }
126+
105127void AccountSettings::showSelectiveSyncDialog (Folder *folder)
106128{
107129 auto *selectiveSync = new SelectiveSyncWidget (_accountState->account (), this );
@@ -318,6 +340,17 @@ void AccountSettings::doForceSyncCurrentFolder(Folder *selectedFolder)
318340 // Restart scheduler
319341 FolderMan::instance ()->scheduler ()->start ();
320342}
343+ void AccountSettings::updateNotifications ()
344+ {
345+ if (_accountState->isConnected ()) {
346+ auto *job = Notification::createNotificationsJob (_accountState->account (), this );
347+ connect (job, &JsonApiJob::finishedSignal, this , [job, this ] {
348+ _notifications = Notification::getNotifications (job);
349+ Q_EMIT notificationsChanged ();
350+ });
351+ job->start ();
352+ }
353+ }
321354
322355void AccountSettings::slotAccountStateChanged ()
323356{
@@ -342,6 +375,7 @@ void AccountSettings::slotAccountStateChanged()
342375 connect (
343376 accountsState ()->account ()->spacesManager (), &GraphApi::SpacesManager::updated, this , &AccountSettings::slotSpacesUpdated, Qt::UniqueConnection);
344377 slotSpacesUpdated ();
378+ updateNotifications ();
345379 break ;
346380 }
347381 case AccountState::ServiceUnavailable:
@@ -487,6 +521,11 @@ QString AccountSettings::accountStateIconName()
487521 return _accountStateIconName;
488522}
489523
524+ const QList<Notification> &AccountSettings::notifications () const
525+ {
526+ return _notifications;
527+ }
528+
490529void AccountSettings::slotDeleteAccount ()
491530{
492531 // Deleting the account potentially deletes 'this', so
0 commit comments