From 222cd3d9b53df54c1183588143086e7a02eae843 Mon Sep 17 00:00:00 2001 From: zyz Date: Tue, 18 Feb 2025 20:23:41 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20Notifications=20not=20displayed=20in=20t?= =?UTF-8?q?he=20center=20cannot=20disappear=20after=E2=80=A6=20(#1034)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: Notifications not displayed in the center cannot disappear after timeout as title Log: as title Pms: BUG-303295 * fix: Staging notifications cannot disappear after timeout as title Log: as title Pms: BUG-303331 --- panels/notification/bubble/bubblemodel.cpp | 11 +++++++++++ panels/notification/bubble/bubblemodel.h | 1 + panels/notification/bubble/bubblepanel.cpp | 12 ++++++++---- panels/notification/server/notificationmanager.cpp | 13 ++++++------- 4 files changed, 26 insertions(+), 11 deletions(-) diff --git a/panels/notification/bubble/bubblemodel.cpp b/panels/notification/bubble/bubblemodel.cpp index a6e03b688..60f32cf2c 100644 --- a/panels/notification/bubble/bubblemodel.cpp +++ b/panels/notification/bubble/bubblemodel.cpp @@ -145,6 +145,17 @@ BubbleItem *BubbleModel::removeById(qint64 id) return nullptr; } +uint BubbleModel::getBubbleIdByStorageId(qint64 id) const +{ + for (const auto &item : m_bubbles) { + if (item->id() == id) { + return item->bubbleId(); + } + } + + return 0; +} + BubbleItem *BubbleModel::bubbleItem(int bubbleIndex) const { if (bubbleIndex < 0 || bubbleIndex >= items().count()) diff --git a/panels/notification/bubble/bubblemodel.h b/panels/notification/bubble/bubblemodel.h index 5427e8b19..e28307c58 100644 --- a/panels/notification/bubble/bubblemodel.h +++ b/panels/notification/bubble/bubblemodel.h @@ -49,6 +49,7 @@ class BubbleModel : public QAbstractListModel Q_INVOKABLE void remove(int index); void remove(const BubbleItem *bubble); BubbleItem *removeById(qint64 id); + uint getBubbleIdByStorageId(qint64 id) const; void clear(); BubbleItem *bubbleItem(int bubbleIndex) const; diff --git a/panels/notification/bubble/bubblepanel.cpp b/panels/notification/bubble/bubblepanel.cpp index 87f300d40..8b32ca91e 100644 --- a/panels/notification/bubble/bubblepanel.cpp +++ b/panels/notification/bubble/bubblepanel.cpp @@ -132,11 +132,15 @@ void BubblePanel::addBubble(qint64 id) void BubblePanel::closeBubble(qint64 id) { const auto entity = m_accessor->fetchEntity(id); - if (!entity.isValid()) - return; + if (entity.isValid()) { + id = entity.bubbleId(); + } else { + id = m_bubbles->getBubbleIdByStorageId(id); + } - id = entity.bubbleId(); - m_bubbles->removeById(id); + if (id > 0) { + m_bubbles->removeById(id); + } } void BubblePanel::onActionInvoked(qint64 id, uint bubbleId, const QString &actionId) diff --git a/panels/notification/server/notificationmanager.cpp b/panels/notification/server/notificationmanager.cpp index 857513ac2..b3e8ca244 100644 --- a/panels/notification/server/notificationmanager.cpp +++ b/panels/notification/server/notificationmanager.cpp @@ -471,18 +471,17 @@ void NotificationManager::updateEntityProcessed(const NotifyEntity &entity) } // "cancel"表示正在发送蓝牙文件,不需要发送到通知中心 const auto bluetooth = entity.body().contains("%") && entity.actions().contains("cancel"); - const bool removeEntity = removed || !showInCenter || bluetooth; - if (!removeEntity) { + if (removed || !showInCenter || bluetooth) { + // remove it from memory + m_persistence->removeEntity(id); + } else { + // add to db and remove it form memory m_persistence->updateEntityProcessedType(id, entity.processedType()); } - // notify state changed, and then remove entity Q_EMIT NotificationStateChanged(entity.id(), entity.processedType()); - if (removeEntity) { - m_persistence->removeEntity(id); - removePendingEntity(entity); - } + removePendingEntity(entity); emitRecordCountChanged(); }