Skip to content

Commit 308bd76

Browse files
committed
fix: correct notification ID handling and validation
1. Fixed BubbleModel to use entity id instead of bubble id for data retrieval 2. Updated BubblePanel to check for InvalidId (0) instead of id > 0 when closing bubbles 3. Modified DataAccessorProxy to return empty entity instead of cascading fetch when primary source fails 4. Changed MemoryAccessor to generate unique negative IDs for in-memory entities to avoid conflicts 5. Updated NotifyEntity to use InvalidId constant (0) instead of -1 for invalid state 6. Added InvalidId constant definition in NotifyEntity header 7. Fixed NotificationManager to properly handle replace operations and return false when replace fails 8. Ensured consistent ID validation across all components using InvalidId constant Log: Fixed notification display issues where incorrect IDs caused mismatched notifications Influence: 1. Test notification display in bubble panel with various notification types 2. Verify bubble closing functionality works correctly 3. Test notification replacement scenarios 4. Check memory-only notification handling 5. Validate notification persistence and retrieval from database 6. Test edge cases with invalid notification IDs 7. Verify notification matching and display consistency fix: 修正通知ID处理和验证逻辑 1. 修复BubbleModel使用实体ID而非气泡ID进行数据检索 2. 更新BubblePanel在关闭气泡时检查InvalidId(0)而非id>0 3. 修改DataAccessorProxy在主数据源失败时返回空实体而非级联查询 4. 更改MemoryAccessor为内存实体生成唯一的负ID以避免冲突 5. 更新NotifyEntity使用InvalidId常量(0)而非-1表示无效状态 6. 在NotifyEntity头文件中添加InvalidId常量定义 7. 修复NotificationManager正确处理替换操作并在替换失败时返回false 8. 确保所有组件使用InvalidId常量进行一致的ID验证 Log: 修复通知显示问题,错误的ID导致通知匹配混乱 Influence: 1. 测试气泡面板中各种通知类型的显示 2. 验证气泡关闭功能正常工作 3. 测试通知替换场景 4. 检查仅内存通知的处理 5. 验证通知持久化和从数据库检索 6. 测试无效通知ID的边缘情况 7. 验证通知匹配和显示一致性 PMS: BUG-349053
1 parent ebed3d8 commit 308bd76

File tree

7 files changed

+13
-10
lines changed

7 files changed

+13
-10
lines changed

panels/notification/bubble/bubblemodel.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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]->bubbleId();
172+
return m_bubbles[row]->id();
173173
case BubbleModel::Body:
174174
return m_bubbles[row]->body();
175175
case BubbleModel::Summary:

panels/notification/bubble/bubblepanel.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ void BubblePanel::addBubble(qint64 id)
138138

139139
void BubblePanel::closeBubble(qint64 id)
140140
{
141-
if (id > 0) {
141+
if (id != NotifyEntity::InvalidId) {
142142
m_bubbles->removeById(id);
143143
} else {
144144
qWarning(notifyLog) << "Failed to close bubble: invalid bubble id for entity id:" << id;

panels/notification/common/dataaccessorproxy.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,7 @@ NotifyEntity DataAccessorProxy::fetchLastEntity(uint notifyId)
112112
auto entity = m_impl->fetchLastEntity(notifyId);
113113
if (entity.isValid())
114114
return entity;
115-
116-
return m_source->fetchLastEntity(notifyId);
115+
return {};
117116
}
118117

119118
QList<NotifyEntity> DataAccessorProxy::fetchEntities(const QString &appName, int processedType, int maxCount)

panels/notification/common/memoryaccessor.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@ MemoryAccessor::~MemoryAccessor()
1515

1616
qint64 MemoryAccessor::addEntity(const NotifyEntity &entity)
1717
{
18+
static qint64 g_Id = NotifyEntity::InvalidId; // use negative id for in-memory entities
1819
QMutexLocker locker(&m_mutex);
1920
m_entities << entity;
20-
return entity.bubbleId();
21+
return --g_Id;
2122
}
2223

2324
qint64 MemoryAccessor::replaceEntity(qint64 id, const NotifyEntity &entity)

panels/notification/common/notifyentity.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class NotifyData : public QSharedData
3737
uint replacesId = NoReplaceId;
3838
int expireTimeout = 0;
3939

40-
qint64 id = -1;
40+
qint64 id = NotifyEntity::InvalidId;
4141
qint64 cTime = 0;
4242
int processedType = NotifyEntity::NotProcessed;
4343
};
@@ -118,7 +118,7 @@ bool NotifyEntity::operator!=(const NotifyEntity &other) const
118118

119119
bool NotifyEntity::isValid() const
120120
{
121-
return d && d->id > 0 && d->cTime > 0;
121+
return d && d->id != NotifyEntity::InvalidId && d->cTime > 0;
122122
}
123123

124124
qint64 NotifyEntity::id() const

panels/notification/common/notifyentity.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ class NotifyEntity
3333
Timeout = 5,
3434
};
3535

36+
static constexpr qint64 InvalidId = 0;
37+
3638
NotifyEntity();
3739
explicit NotifyEntity(qint64 id, const QString &appName);
3840
explicit NotifyEntity(const QString &appName, uint replacesId, const QString &appIcon, const QString &summary,

panels/notification/server/notificationmanager.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ bool NotificationManager::isDoNotDisturb() const
378378

379379
bool NotificationManager::recordNotification(NotifyEntity &entity)
380380
{
381-
qint64 id = -1;
381+
qint64 id = NotifyEntity::InvalidId;
382382
if (entity.isReplace()) {
383383
auto lastEntity = m_persistence->fetchLastEntity(entity.bubbleId());
384384
if (lastEntity.isValid()) {
@@ -393,13 +393,14 @@ bool NotificationManager::recordNotification(NotifyEntity &entity)
393393
}
394394
} else {
395395
qWarning() << "Not exist notification to replace for the replaceId" << entity.replacesId();
396+
return false;
396397
}
397398
}
398-
if (id == -1) {
399+
if (id == NotifyEntity::InvalidId) {
399400
id = m_persistence->addEntity(entity);
400401
}
401402

402-
if (id == -1) {
403+
if (id == NotifyEntity::InvalidId) {
403404
qWarning(notifyLog) << "Failed on saving DB, bubbleId:" << entity.bubbleId() << ", appName" << entity.appName();
404405
return false;
405406
}

0 commit comments

Comments
 (0)