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(); }