Skip to content

Commit a2f464c

Browse files
committed
refactor: update notification handling and data access logic
1. Changed BubbleNotifyItem to AppNotifyItem in NotifyStagingModel for better naming consistency 2. Simplified DataAccessorProxy by removing redundant source validity checks 3. Improved entity routing logic with clearer conditions 4. Added proper source initialization in DataAccessorProxy constructor 5. Enhanced removeEntity() to check entity validity before removal 6. Streamlined clear() and removeEntityByApp() to only operate on source The changes improve code maintainability and reduce redundant checks while maintaining the same functionality. The naming change from BubbleNotifyItem to AppNotifyItem better reflects the item's purpose, and the data access logic simplification makes the code more straightforward and less error-prone. refactor: 更新通知处理和数据访问逻辑 1. 在 NotifyStagingModel 中将 BubbleNotifyItem 改为 AppNotifyItem 以提高 命名一致性 2. 通过移除冗余的源有效性检查简化了 DataAccessorProxy 3. 使用更清晰的条件改进了实体路由逻辑 4. 在 DataAccessorProxy 构造函数中添加了适当的源初始化 5. 增强了 removeEntity() 在删除前检查实体有效性 6. 简化了 clear() 和 removeEntityByApp() 使其仅操作源数据 这些变更提高了代码可维护性,在保持相同功能的同时减少了冗余检查。从 BubbleNotifyItem 到 AppNotifyItem 的命名更改更好地反映了项目的用途,数据 访问逻辑的简化使代码更加直接且不易出错。
1 parent 92f8ba3 commit a2f464c

File tree

2 files changed

+34
-58
lines changed

2 files changed

+34
-58
lines changed

panels/notification/center/notifystagingmodel.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ void NotifyStagingModel::remove(qint64 id)
144144

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

171171
const auto count = std::min(static_cast<int>(entities.size()), BubbleMaxCount);
172172
for (int i = 0; i < count; i++) {
173-
auto notify = new BubbleNotifyItem(entities.at(i));
173+
auto notify = new AppNotifyItem(entities.at(i));
174174
m_appNotifies << notify;
175175
}
176176
updateOverlapCount(entities.size());

panels/notification/common/dataaccessorproxy.cpp

Lines changed: 32 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ DataAccessorProxy *DataAccessorProxy::instance()
1616
if (!gInstance) {
1717
gInstance = new DataAccessorProxy();
1818
gInstance->m_impl = new MemoryAccessor();
19+
gInstance->m_source = new MemoryAccessor();
1920
}
2021
return gInstance;
2122
}
@@ -30,6 +31,12 @@ DataAccessorProxy::~DataAccessorProxy()
3031

3132
void DataAccessorProxy::setSource(DataAccessor *source)
3233
{
34+
if (!source)
35+
return;
36+
37+
if (m_source) {
38+
delete m_source;
39+
}
3340
m_source = source;
3441
}
3542

@@ -38,139 +45,108 @@ qint64 DataAccessorProxy::addEntity(const NotifyEntity &entity)
3845
if (entity.processedType() == NotifyEntity::NotProcessed) {
3946
return m_impl->addEntity(entity);
4047
} else {
41-
if (m_source && m_source->isValid() && !filterToSource(entity)) {
48+
if (!filterToSource(entity)) {
4249
return m_source->addEntity(entity);
4350
}
4451
}
45-
return m_impl->addEntity(entity);
52+
return -1;
4653
}
4754

4855
qint64 DataAccessorProxy::replaceEntity(qint64 id, const NotifyEntity &entity)
4956
{
5057
if (entity.processedType() == NotifyEntity::NotProcessed) {
5158
return m_impl->replaceEntity(id, entity);
5259
} else {
53-
if (m_source && m_source->isValid()) {
54-
return m_source->replaceEntity(id, entity);
55-
}
60+
return m_source->replaceEntity(id, entity);
5661
}
57-
return m_impl->replaceEntity(id, entity);
5862
}
5963

6064
void DataAccessorProxy::updateEntityProcessedType(qint64 id, int processedType)
6165
{
6266
if (routerToSource(id, processedType)) {
6367
m_impl->updateEntityProcessedType(id, processedType);
64-
if (m_source && m_source->isValid()) {
65-
auto entity = m_impl->fetchEntity(id);
66-
if (!filterToSource(entity)) {
67-
const auto sId = m_source->addEntity(entity);
68-
if (sId > 0) {
69-
m_impl->removeEntity(id);
70-
entity.setId(sId);
71-
}
72-
} else {
68+
auto entity = m_impl->fetchEntity(id);
69+
if (!filterToSource(entity)) {
70+
const auto sId = m_source->addEntity(entity);
71+
if (sId > 0) {
7372
m_impl->removeEntity(id);
73+
entity.setId(sId);
7474
}
75+
} else {
76+
m_impl->removeEntity(id);
7577
}
76-
return;
77-
}
78-
if (m_source && m_source->isValid()) {
78+
} else {
7979
return m_source->updateEntityProcessedType(id, processedType);
8080
}
81-
return m_impl->updateEntityProcessedType(id, processedType);
8281
}
8382

8483
NotifyEntity DataAccessorProxy::fetchEntity(qint64 id)
8584
{
8685
auto entity = m_impl->fetchEntity(id);
8786
if (entity.isValid())
8887
return entity;
89-
if (m_source && m_source->isValid()) {
90-
return m_source->fetchEntity(id);
91-
}
92-
return {};
88+
89+
return m_source->fetchEntity(id);
9390
}
9491

9592
int DataAccessorProxy::fetchEntityCount(const QString &appName, int processedType) const
9693
{
9794
if (processedType == NotifyEntity::NotProcessed) {
9895
return m_impl->fetchEntityCount(appName, processedType);
9996
} else {
100-
if (m_source && m_source->isValid()) {
101-
return m_source->fetchEntityCount(appName, processedType);
102-
}
97+
return m_source->fetchEntityCount(appName, processedType);
10398
}
104-
return m_impl->fetchEntityCount(appName, processedType);
10599
}
106100

107101
NotifyEntity DataAccessorProxy::fetchLastEntity(const QString &appName, int processedType)
108102
{
109103
if (processedType == NotifyEntity::NotProcessed) {
110104
return m_impl->fetchLastEntity(appName, processedType);
111105
} else {
112-
if (m_source && m_source->isValid()) {
113-
return m_source->fetchLastEntity(appName, processedType);
114-
}
106+
return m_source->fetchLastEntity(appName, processedType);
115107
}
116-
return m_impl->fetchLastEntity(appName, processedType);
117108
}
118109

119110
NotifyEntity DataAccessorProxy::fetchLastEntity(uint notifyId)
120111
{
121112
auto entity = m_impl->fetchLastEntity(notifyId);
122113
if (entity.isValid())
123114
return entity;
124-
if (m_source && m_source->isValid()) {
125-
return m_source->fetchLastEntity(notifyId);
126-
}
127-
return {};
115+
116+
return m_source->fetchLastEntity(notifyId);
128117
}
129118

130119
QList<NotifyEntity> DataAccessorProxy::fetchEntities(const QString &appName, int processedType, int maxCount)
131120
{
132121
if (processedType == NotifyEntity::NotProcessed) {
133122
return m_impl->fetchEntities(appName, processedType, maxCount);
134123
}
135-
if (m_source && m_source->isValid()) {
136-
return m_source->fetchEntities(appName, processedType, maxCount);
137-
}
138-
return m_impl->fetchEntities(appName, processedType, maxCount);
124+
125+
return m_source->fetchEntities(appName, processedType, maxCount);
139126
}
140127

141128
QList<QString> DataAccessorProxy::fetchApps(int maxCount) const
142129
{
143-
if (m_source && m_source->isValid()) {
144-
return m_source->fetchApps(maxCount);
145-
}
146-
return m_impl->fetchApps(maxCount);
130+
return m_source->fetchApps(maxCount);
147131
}
148132

149133
void DataAccessorProxy::removeEntity(qint64 id)
150134
{
151-
m_impl->removeEntity(id);
152-
153-
if (m_source && m_source->isValid()) {
135+
if (m_impl->fetchEntity(id).isValid()) {
136+
m_impl->removeEntity(id);
137+
} else {
154138
m_source->removeEntity(id);
155139
}
156140
}
157141

158142
void DataAccessorProxy::removeEntityByApp(const QString &appName)
159143
{
160-
m_impl->removeEntityByApp(appName);
161-
162-
if (m_source && m_source->isValid()) {
163-
m_source->removeEntityByApp(appName);
164-
}
144+
m_source->removeEntityByApp(appName);
165145
}
166146

167147
void DataAccessorProxy::clear()
168148
{
169-
m_impl->clear();
170-
171-
if (m_source && m_source->isValid()) {
172-
m_source->clear();
173-
}
149+
m_source->clear();
174150
}
175151

176152
bool DataAccessorProxy::routerToSource(qint64 id, int processedType) const

0 commit comments

Comments
 (0)