diff --git a/libnotificationmanager/abstractnotificationsmodel.cpp b/libnotificationmanager/abstractnotificationsmodel.cpp index a30799096..c24abe24f 100644 --- a/libnotificationmanager/abstractnotificationsmodel.cpp +++ b/libnotificationmanager/abstractnotificationsmodel.cpp @@ -26,6 +26,7 @@ using namespace NotificationManager; AbstractNotificationsModel::Private::Private(AbstractNotificationsModel *q) : q(q) + , inhibited(false) , lastRead(QDateTime::currentDateTimeUtc()) { pendingRemovalTimer.setSingleShot(true); @@ -67,10 +68,10 @@ void AbstractNotificationsModel::Private::onNotificationAdded(const Notification q->endRemoveRows(); } - setupNotificationTimeout(notification); - q->beginInsertRows(QModelIndex(), notifications.count(), notifications.count()); notifications.append(std::move(notification)); + // Timeout must be set after the item appends to the vector + setupNotificationTimeout(notification); q->endInsertRows(); } @@ -159,6 +160,12 @@ void AbstractNotificationsModel::Private::setupNotificationTimeout(const Notific return; } + // Don't show the notification popup after switching DND mode off. + if (inhibited) { + q->expire(notification.id()); + return; + } + QTimer *timer = notificationTimeouts.value(notification.id()); if (!timer) { timer = new QTimer(); @@ -426,6 +433,11 @@ void AbstractNotificationsModel::stopTimeout(uint notificationId) delete d->notificationTimeouts.take(notificationId); } +void AbstractNotificationsModel::setInhibited(bool inhibited) +{ + d->inhibited = inhibited; +} + void AbstractNotificationsModel::clear(Notifications::ClearFlags flags) { if (d->notifications.isEmpty()) { diff --git a/libnotificationmanager/abstractnotificationsmodel.h b/libnotificationmanager/abstractnotificationsmodel.h index 3734eb377..d76795020 100644 --- a/libnotificationmanager/abstractnotificationsmodel.h +++ b/libnotificationmanager/abstractnotificationsmodel.h @@ -44,6 +44,7 @@ public: void startTimeout(uint notificationId); void stopTimeout(uint notificationId); + void setInhibited(bool inhibited); void clear(Notifications::ClearFlags flags); diff --git a/libnotificationmanager/abstractnotificationsmodel_p.h b/libnotificationmanager/abstractnotificationsmodel_p.h index cef78c7fe..8c0fe55fe 100644 --- a/libnotificationmanager/abstractnotificationsmodel_p.h +++ b/libnotificationmanager/abstractnotificationsmodel_p.h @@ -41,6 +41,7 @@ public: QVector pendingRemovals; QTimer pendingRemovalTimer; + bool inhibited; // "Do not disturb" mode QDateTime lastRead; }; diff --git a/libnotificationmanager/notificationsmodel.cpp b/libnotificationmanager/notificationsmodel.cpp index b9ac41f28..bbcea7839 100644 --- a/libnotificationmanager/notificationsmodel.cpp +++ b/libnotificationmanager/notificationsmodel.cpp @@ -50,6 +50,9 @@ NotificationsModel::NotificationsModel() } }); Server::self().init(); + + setInhibited(Server::self().inhibited()); + connect(&Server::self(), &Server::inhibitedChanged, this, std::bind(&NotificationsModel::setInhibited, this, std::placeholders::_1)); } void NotificationsModel::expire(uint notificationId)