Skip to content

Commit 07542c4

Browse files
committed
fix: stage notify doesn't remove when exit for notification
add cache to stage Bubble, and save it to DB only when processed. pms: BUG-290145
1 parent 8de5c6a commit 07542c4

15 files changed

+493
-23
lines changed

panels/notification/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ target_link_libraries(ds-notification PRIVATE
1414
add_library(ds-notification-shared SHARED
1515
${CMAKE_SOURCE_DIR}/panels/notification/common/notifyentity.h
1616
${CMAKE_SOURCE_DIR}/panels/notification/common/notifyentity.cpp
17+
${CMAKE_SOURCE_DIR}/panels/notification/common/dataaccessorproxy.h
18+
${CMAKE_SOURCE_DIR}/panels/notification/common/dataaccessorproxy.cpp
19+
${CMAKE_SOURCE_DIR}/panels/notification/common/memoryaccessor.h
20+
${CMAKE_SOURCE_DIR}/panels/notification/common/memoryaccessor.cpp
1721
${CMAKE_SOURCE_DIR}/panels/notification/common/dbaccessor.h
1822
${CMAKE_SOURCE_DIR}/panels/notification/common/dbaccessor.cpp
1923
${CMAKE_SOURCE_DIR}/panels/notification/common/notifysetting.h

panels/notification/bubble/bubblemodel.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ BubbleItem *BubbleModel::removeById(qint64 id)
135135
return nullptr;
136136
}
137137
for (const auto &item : m_bubbles) {
138-
if (item->id() == id) {
138+
if (item->bubbleId() == id) {
139139
m_delayBubbles.removeAll(id);
140140
remove(m_bubbles.indexOf(item));
141141
return item;
@@ -169,7 +169,7 @@ QVariant BubbleModel::data(const QModelIndex &index, int role) const
169169
case BubbleModel::AppName:
170170
return m_bubbles[row]->appName();
171171
case BubbleModel::Id:
172-
return m_bubbles[row]->id();
172+
return m_bubbles[row]->bubbleId();
173173
case BubbleModel::Body:
174174
return m_bubbles[row]->body();
175175
case BubbleModel::Summary:
@@ -281,7 +281,7 @@ int BubbleModel::replaceBubbleIndex(const BubbleItem *bubble) const
281281
if (item->appName() != bubble->appName())
282282
continue;
283283

284-
if (item->id() == bubble->id()) {
284+
if (item->bubbleId() == bubble->bubbleId()) {
285285
return i;
286286
}
287287
}

panels/notification/bubble/bubblepanel.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
// SPDX-License-Identifier: GPL-3.0-or-later
44

55
#include "bubblepanel.h"
6+
#include "bubbleitem.h"
67
#include "bubblemodel.h"
8+
#include "dataaccessorproxy.h"
79
#include "pluginfactory.h"
8-
#include "bubbleitem.h"
9-
#include "dbaccessor.h"
1010

1111
#include <QLoggingCategory>
1212
#include <QQueue>
@@ -46,7 +46,7 @@ bool BubblePanel::init()
4646
return false;
4747
}
4848

49-
m_accessor = DBAccessor::instance();
49+
m_accessor = DataAccessorProxy::instance();
5050

5151
connect(m_notificationServer, SIGNAL(notificationStateChanged(qint64, int)), this, SLOT(onNotificationStateChanged(qint64, int)));
5252

@@ -131,6 +131,11 @@ void BubblePanel::addBubble(qint64 id)
131131

132132
void BubblePanel::closeBubble(qint64 id)
133133
{
134+
const auto entity = m_accessor->fetchEntity(id);
135+
if (!entity.isValid())
136+
return;
137+
138+
id = entity.bubbleId();
134139
m_bubbles->removeById(id);
135140
}
136141

panels/notification/center/notificationcenterpanel.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44

55
#include "notificationcenterpanel.h"
66

7-
#include "notificationcenterproxy.h"
7+
#include "dataaccessorproxy.h"
88
#include "notificationcenterdbusadaptor.h"
9+
#include "notificationcenterproxy.h"
910
#include "notifyaccessor.h"
10-
#include "dbaccessor.h"
1111

1212
#include <pluginfactory.h>
1313
#include <pluginloader.h>
@@ -75,7 +75,7 @@ bool NotificationCenterPanel::init()
7575

7676
DPanel::init();
7777

78-
auto accessor = notification::DBAccessor::instance();
78+
auto accessor = notification::DataAccessorProxy::instance();
7979
notifycenter::NotifyAccessor::instance()->setDataAccessor(accessor);
8080

8181
bool valid = false;

panels/notification/center/notifyitem.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,4 +233,15 @@ NotifyEntity AppGroupNotifyItem::lastEntity() const
233233
{
234234
return m_lastEntity;
235235
}
236+
237+
BubbleNotifyItem::BubbleNotifyItem(const NotifyEntity &entity)
238+
: AppNotifyItem(entity)
239+
{
240+
}
241+
242+
qint64 BubbleNotifyItem::id() const
243+
{
244+
Q_ASSERT(m_entity.isValid());
245+
return m_entity.bubbleId();
246+
}
236247
}

panels/notification/center/notifyitem.h

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ class AppNotifyItem : public QObject
2222
{
2323
Q_OBJECT
2424
public:
25-
AppNotifyItem(const NotifyEntity &entity);
25+
explicit AppNotifyItem(const NotifyEntity &entity);
2626

2727
void setEntity(const NotifyEntity &entity);
2828
NotifyEntity entity() const;
2929

3030
virtual NotifyType type() const;
3131
QString appName() const;
3232
QString appId() const;
33-
qint64 id() const;
33+
virtual qint64 id() const;
3434
QString time() const;
3535
void updateTime();
3636
bool strongInteractive() const;
@@ -56,10 +56,17 @@ class AppNotifyItem : public QObject
5656
bool m_strongInteractive = false;
5757
};
5858

59+
class BubbleNotifyItem : public AppNotifyItem
60+
{
61+
public:
62+
explicit BubbleNotifyItem(const NotifyEntity &entity);
63+
qint64 id() const override;
64+
};
65+
5966
class OverlapAppNotifyItem : public AppNotifyItem
6067
{
6168
public:
62-
OverlapAppNotifyItem(const NotifyEntity &entity);
69+
explicit OverlapAppNotifyItem(const NotifyEntity &entity);
6370
virtual NotifyType type()const override;
6471
// source 3 -> overlap 2, 2 -> overlap 1, 1-> 0.
6572
void updateCount(int source);
@@ -78,7 +85,7 @@ class OverlapAppNotifyItem : public AppNotifyItem
7885
class AppGroupNotifyItem : public AppNotifyItem
7986
{
8087
public:
81-
AppGroupNotifyItem(const QString &appName);
88+
explicit AppGroupNotifyItem(const QString &appName);
8289
virtual NotifyType type() const override;
8390

8491
void updateLastEntity(const NotifyEntity& entity);

panels/notification/center/notifystagingmodel.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
#include <QTimerEvent>
88
#include <QLoggingCategory>
99

10+
#include "dataaccessorproxy.h"
11+
#include "notifyaccessor.h"
1012
#include "notifyentity.h"
1113
#include "notifyitem.h"
12-
#include "notifyaccessor.h"
13-
#include "dbaccessor.h"
1414
#include "notifysetting.h"
1515

1616
namespace notification {
@@ -20,7 +20,7 @@ namespace notifycenter {
2020

2121
NotifyStagingModel::NotifyStagingModel(QObject *parent)
2222
: QAbstractListModel(parent)
23-
, m_accessor(DBAccessor::instance())
23+
, m_accessor(DataAccessorProxy::instance())
2424
{
2525
connect(NotifyAccessor::instance(), &NotifyAccessor::stagingEntityReceived, this, &NotifyStagingModel::doEntityReceived);
2626
connect(NotifyAccessor::instance(), &NotifyAccessor::stagingEntityClosed, this, &NotifyStagingModel::onEntityClosed);
@@ -142,9 +142,9 @@ void NotifyStagingModel::remove(qint64 id)
142142
newEntity = newEntities.first();
143143
}
144144

145-
qDebug(notifyLog) << "Insert notify" << newEntity.id();
145+
qDebug(notifyLog) << "Insert notify" << newEntity.bubbleId();
146146
beginInsertRows(QModelIndex(), insertedIndex, insertedIndex);
147-
auto notify = new AppNotifyItem(newEntity);
147+
auto notify = new BubbleNotifyItem(newEntity);
148148
m_appNotifies.insert(insertedIndex, notify);
149149
endInsertRows();
150150
}
@@ -166,7 +166,7 @@ void NotifyStagingModel::open()
166166

167167
const auto count = std::min(static_cast<int>(entities.size()), BubbleMaxCount);
168168
for (int i = 0; i < count; i++) {
169-
auto notify = new AppNotifyItem(entities.at(i));
169+
auto notify = new BubbleNotifyItem(entities.at(i));
170170
m_appNotifies << notify;
171171
}
172172
updateOverlapCount(entities.size());
@@ -246,7 +246,7 @@ void NotifyStagingModel::replace(const NotifyEntity &entity)
246246
{
247247
for (int i = 0; i < m_appNotifies.size(); i++) {
248248
auto item = m_appNotifies[i];
249-
if (item->entity().id() == entity.id()) {
249+
if (item->id() == entity.bubbleId()) {
250250
item->setEntity(entity);
251251
const auto index = this->index(i, 0, {});
252252
dataChanged(index, index);
@@ -309,6 +309,10 @@ void NotifyStagingModel::doEntityReceived(qint64 id)
309309

310310
void NotifyStagingModel::onEntityClosed(qint64 id)
311311
{
312+
auto entity = m_accessor->fetchEntity(id);
313+
if (!entity.isValid())
314+
return;
315+
id = entity.bubbleId();
312316
remove(id);
313317
}
314318

panels/notification/common/dataaccessor.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ class DataAccessor
1717
virtual ~DataAccessor()
1818
{
1919
}
20+
virtual bool isValid() const
21+
{
22+
return true;
23+
}
2024
virtual qint64 addEntity(const NotifyEntity &entity) { Q_UNUSED(entity); return 0; }
2125
virtual qint64 replaceEntity(qint64 id, const NotifyEntity &entity)
2226
{

0 commit comments

Comments
 (0)