Skip to content

Conversation

@18202781743
Copy link
Contributor

@18202781743 18202781743 commented Jul 10, 2025

  1. Added isValid() method to BubbleItem to check entity validity
  2. Implemented clearInvalidBubbles() in BubbleModel to remove invalid
    notifications
  3. Added entity validation before creating new bubbles in BubblePanel
  4. Enhanced NotifyEntity validation to include timestamp check
  5. Added validation in NotificationManager timeout processing
  6. Added debug logging for invalid notification cases

These changes improve notification system reliability by:

  • Preventing invalid notifications from being displayed
  • Cleaning up stale notifications automatically
  • Adding better error handling and logging
  • Preventing race conditions in timeout processing
  • Ensuring only valid entities are processed

feat: 增强通知验证和清理功能

  1. 在 BubbleItem 中添加 isValid() 方法检查实体有效性
  2. 在 BubbleModel 中实现 clearInvalidBubbles() 清理无效通知
  3. 在 BubblePanel 创建新气泡前添加实体验证
  4. 增强 NotifyEntity 验证包含时间戳检查
  5. 在 NotificationManager 超时处理中添加验证
  6. 为无效通知情况添加调试日志

这些改进通过以下方式提升通知系统可靠性:

  • 防止显示无效通知
  • 自动清理陈旧通知
  • 添加更好的错误处理和日志记录
  • 防止超时处理中的竞态条件
  • 确保只处理有效实体

Issue: https://bbs.deepin.org/post/289141

Summary by Sourcery

Enhance notification validation and cleanup to prevent invalid or stale notifications and improve logging

Enhancements:

  • Extend NotifyEntity and BubbleItem with isValid() incorporating timestamp checks
  • Introduce clearInvalidBubbles() in BubbleModel and BubblePanel to remove invalid notifications
  • Validate entities before creating bubbles and during timeout processing in NotificationManager
  • Add debug and warning logs for invalid notification scenarios

@deepin-ci-robot
Copy link

deepin pr auto review

代码审查意见:

  1. BubbleModel::clearInvalidBubbles函数中,循环条件i >= m_bubbles.count()应该改为i >= 0,以确保从后向前遍历数组时不会越界。

  2. BubblePanel::closeBubble函数中,当id无效时调用clearInvalidBubbles,这是一个好的做法,但应该在else分支中添加注释说明为什么需要清除无效的气泡。

  3. NotifyEntity构造函数中添加了cTime成员变量,这是一个好的做法,可以记录实体创建的时间。但是,应该确保所有使用NotifyEntity的地方都更新以处理新的cTime成员。

  4. NotifyEntity::isValid函数中,增加了对cTime的检查,这是一个合理的改进,可以确保实体的有效性。

  5. NotificationManager::onHandingPendingEntities函数中,增加了对无效实体的检查,这是一个好的做法,可以避免处理无效的实体。

  6. BubblePanel::addBubble函数中,增加了对无效实体的检查,这是一个好的做法,可以避免添加无效的气泡。

  7. BubblePanel::closeBubble函数中,增加了对无效实体的警告日志,这是一个好的做法,可以帮助开发者快速定位问题。

  8. BubblePanel::closeBubble函数中,当id无效时调用clearInvalidBubbles,这是一个好的做法,可以确保清除所有无效的气泡。

总体来说,这些改进提高了代码的健壮性和可维护性。但是,需要确保所有相关的代码都已经更新以处理新的成员变量和函数。

@sourcery-ai
Copy link

sourcery-ai bot commented Jul 10, 2025

Reviewer's Guide

This PR strengthens the notification pipeline by introducing validity checks and cleanup routines: it adds entity validity methods, prevents invalid bubbles from being created or closed, purges stale items automatically, enhances timestamp-based validation in entities, and injects logging to trace invalid cases.

Sequence diagram for adding a bubble with entity validation

sequenceDiagram
    participant User as actor User
    participant BubblePanel
    participant m_accessor as EntityAccessor
    participant BubbleItem
    participant BubbleModel
    User->>BubblePanel: addBubble(id)
    BubblePanel->>m_accessor: fetchEntity(id)
    m_accessor-->>BubblePanel: entity
    alt entity is invalid
        BubblePanel-->>User: Log warning, abort
    else entity is valid
        BubblePanel->>BubbleItem: BubbleItem(entity)
        BubblePanel->>BubbleModel: add BubbleItem
    end
Loading

Sequence diagram for clearing invalid bubbles

sequenceDiagram
    participant BubblePanel
    participant BubbleModel
    participant BubbleItem
    BubblePanel->>BubbleModel: clearInvalidBubbles()
    loop for each BubbleItem in m_bubbles
        BubbleModel->>BubbleItem: isValid()
        alt not valid
            BubbleModel->>BubbleModel: remove(bubble)
        end
    end
Loading

Sequence diagram for notification timeout processing with validation

sequenceDiagram
    participant NotificationManager
    participant NotifyEntity
    participant Logger
    NotificationManager->>NotifyEntity: isValid()
    alt entity is invalid
        NotificationManager->>Logger: Log warning, skip
    else entity is valid
        NotificationManager->>NotificationManager: notificationClosed(...)
    end
Loading

Class diagram for enhanced notification validation and cleanup

classDiagram
    class NotifyEntity {
        +qint64 id
        +QString appName
        +qint64 cTime
        +bool isValid() const
    }
    class BubbleItem {
        +NotifyEntity m_entity
        +bool isValid() const
    }
    class BubbleModel {
        +QList<BubbleItem*> m_bubbles
        +void clearInvalidBubbles()
    }
    class BubblePanel {
        +void addBubble(qint64 id)
        +void closeBubble(qint64 id)
        +void clearInvalidBubbles()
    }
    class NotificationManager {
        +void onHandingPendingEntities()
    }
    BubblePanel --> BubbleModel : uses
    BubbleModel --> BubbleItem : contains
    BubbleItem --> NotifyEntity : has
    NotificationManager --> NotifyEntity : processes
Loading

File-Level Changes

Change Details Files
Add validity check to BubbleItem
  • Declare isValid() in header
  • Implement isValid() returning m_entity.isValid()
panels/notification/bubble/bubbleitem.h
panels/notification/bubble/bubbleitem.cpp
Implement automatic cleanup of invalid bubbles
  • Add clearInvalidBubbles() to BubbleModel to remove invalid items
  • Expose clearInvalidBubbles() in BubbleModel header
  • Add wrapper clearInvalidBubbles() in BubblePanel and invoke after invalid close
panels/notification/bubble/bubblemodel.cpp
panels/notification/bubble/bubblemodel.h
panels/notification/bubble/bubblepanel.cpp
panels/notification/bubble/bubblepanel.h
Prevent creation/closure of invalid bubbles in BubblePanel
  • Guard addBubble() with entity.isValid() and early return
  • Log warnings in addBubble() for invalid entities
  • Log debug/warnings in closeBubble() and fallback to cleanup
panels/notification/bubble/bubblepanel.cpp
Enhance NotifyEntity validity to include timestamp
  • Initialize cTime in NotifyEntity constructor
  • Update isValid() to require cTime>0
panels/notification/common/notifyentity.cpp
Validate entities during timeout processing in NotificationManager
  • Skip invalid timeoutEntities with qWarning log
  • Retain existing expiration handling for valid items
panels/notification/server/notificationmanager.cpp

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @18202781743 - I've reviewed your changes - here's some feedback:

  • NotifyEntity only sets cTime in one constructor—add timestamp initialization to all constructors to avoid unintentionally invalidating new entities.
  • The reverse loop in BubbleModel::clearInvalidBubbles has a redundant boundary check and may skip items after remove; consider simplifying with a filtered removal (e.g. using std::remove_if or a two-pass approach).
  • Entity validity checks are scattered across BubblePanel and NotificationManager—extract and centralize validation logic into a shared helper to avoid duplication.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- NotifyEntity only sets cTime in one constructor—add timestamp initialization to all constructors to avoid unintentionally invalidating new entities.
- The reverse loop in BubbleModel::clearInvalidBubbles has a redundant boundary check and may skip items after remove; consider simplifying with a filtered removal (e.g. using std::remove_if or a two-pass approach).
- Entity validity checks are scattered across BubblePanel and NotificationManager—extract and centralize validation logic into a shared helper to avoid duplication.

## Individual Comments

### Comment 1
<location> `panels/notification/bubble/bubblepanel.cpp:122` </location>
<code_context>
+
+    // Validate entity before creating bubble to prevent invalid notification banners
+    if (!entity.isValid()) {
+        qWarning(notifyLog) << "Failed to add bubble: invalid entity for id" << id << "appName:" << entity.appName() << "cTime:" << entity.cTime();
+        return;
+    }
</code_context>

<issue_to_address>
Logging entity.appName() and entity.cTime() for invalid entities may not always be safe.

Accessing properties of an invalid entity may yield incorrect log data. Consider logging only the id or adding checks before logging other properties.
</issue_to_address>

<suggested_fix>
<<<<<<< SEARCH
    if (!entity.isValid()) {
        qWarning(notifyLog) << "Failed to add bubble: invalid entity for id" << id << "appName:" << entity.appName() << "cTime:" << entity.cTime();
        return;
    }
=======
    if (!entity.isValid()) {
        qWarning(notifyLog) << "Failed to add bubble: invalid entity for id" << id;
        return;
    }
>>>>>>> REPLACE

</suggested_fix>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines +121 to +124
if (!entity.isValid()) {
qWarning(notifyLog) << "Failed to add bubble: invalid entity for id" << id << "appName:" << entity.appName() << "cTime:" << entity.cTime();
return;
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (bug_risk): Logging entity.appName() and entity.cTime() for invalid entities may not always be safe.

Accessing properties of an invalid entity may yield incorrect log data. Consider logging only the id or adding checks before logging other properties.

Suggested change
if (!entity.isValid()) {
qWarning(notifyLog) << "Failed to add bubble: invalid entity for id" << id << "appName:" << entity.appName() << "cTime:" << entity.cTime();
return;
}
if (!entity.isValid()) {
qWarning(notifyLog) << "Failed to add bubble: invalid entity for id" << id;
return;
}

yixinshark
yixinshark previously approved these changes Jul 10, 2025
1. Added isValid() method to BubbleItem to check entity validity
2. Implemented clearInvalidBubbles() in BubbleModel to remove invalid
notifications
3. Added entity validation before creating new bubbles in BubblePanel
4. Enhanced NotifyEntity validation to include timestamp check
5. Added validation in NotificationManager timeout processing
6. Added debug logging for invalid notification cases

These changes improve notification system reliability by:
- Preventing invalid notifications from being displayed
- Cleaning up stale notifications automatically
- Adding better error handling and logging
- Preventing race conditions in timeout processing
- Ensuring only valid entities are processed

feat: 增强通知验证和清理功能

1. 在 BubbleItem 中添加 isValid() 方法检查实体有效性
2. 在 BubbleModel 中实现 clearInvalidBubbles() 清理无效通知
3. 在 BubblePanel 创建新气泡前添加实体验证
4. 增强 NotifyEntity 验证包含时间戳检查
5. 在 NotificationManager 超时处理中添加验证
6. 为无效通知情况添加调试日志

这些改进通过以下方式提升通知系统可靠性:
- 防止显示无效通知
- 自动清理陈旧通知
- 添加更好的错误处理和日志记录
- 防止超时处理中的竞态条件
- 确保只处理有效实体

Issue: https://bbs.deepin.org/post/289141
@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: 18202781743, yixinshark

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@18202781743
Copy link
Contributor Author

/forcemerge

@deepin-bot
Copy link

deepin-bot bot commented Jul 10, 2025

This pr force merged! (status: blocked)

@deepin-bot deepin-bot bot merged commit d40d73b into linuxdeepin:master Jul 10, 2025
7 of 10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants