fix: optimize bubble replacement logic with silent replace support#1660
fix: optimize bubble replacement logic with silent replace support#166052cyb wants to merge 1 commit into
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: 52cyb The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
Hi @52cyb. Thanks for your PR. I'm waiting for a linuxdeepin member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
Reviewer's GuideRefactors the bubble replacement flow to compute replacement targets from NotifyEntity before BubbleItem creation, adds a silent in-place update path controlled by the x-deepin-SilentReplace hint, and centralizes index- and lifetime-safe replacement operations inside BubbleModel. Sequence diagram for addBubble with silent and normal replacementsequenceDiagram
actor NotificationSource
participant BubblePanel
participant BubbleModel
NotificationSource->>BubblePanel: addBubble(id)
BubblePanel->>BubblePanel: getNotifyEntity(id)
BubblePanel->>BubbleModel: replaceBubbleIndex(entity)
BubbleModel-->>BubblePanel: replaceIndex
alt replaceIndex >= 0 and entity.hints().value(x-deepin-SilentReplace).toBool()
BubblePanel->>BubbleModel: updateBubbleInPlace(replaceIndex, entity)
BubbleModel->>BubbleModel: oldBubble.setEntity(entity)
BubbleModel-->>BubbleModel: dataChanged(index, index)
else replaceIndex >= 0
BubblePanel->>BubblePanel: bubble = new BubbleItem(entity)
BubblePanel->>BubblePanel: bubble.setEnablePreview(enablePreview)
BubblePanel->>BubbleModel: replaceBubble(replaceIndex, bubble)
BubbleModel->>BubbleModel: oldBubble.deleteLater()
else no replacement
BubblePanel->>BubblePanel: bubble = new BubbleItem(entity)
BubblePanel->>BubblePanel: bubble.setEnablePreview(enablePreview)
BubblePanel->>BubbleModel: push(bubble)
end
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- Consider extracting the "x-deepin-SilentReplace" hint key into a shared constant to avoid typos and make future changes to the hint name easier.
- In updateBubbleInPlace, silently returning on an invalid replaceIndex or non-replace entity may hide logic errors; adding a warning log for these early returns would make issues easier to diagnose.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider extracting the "x-deepin-SilentReplace" hint key into a shared constant to avoid typos and make future changes to the hint name easier.
- In updateBubbleInPlace, silently returning on an invalid replaceIndex or non-replace entity may hide logic errors; adding a warning log for these early returns would make issues easier to diagnose.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
1. Refactored BubbleModel API: replaced `isReplaceBubble()` and `replaceBubble(BubbleItem*)` with cleaner `replaceBubbleIndex(NotifyEntity)`, `updateBubbleInPlace()`, and `replaceBubble(int, BubbleItem*)` methods 2. Added support for "silent replace" via `x-deepin-SilentReplace` hint: when two bubbles match and the hint is true, the existing bubble is updated in-place using `dataChanged` rather than full remove+insert 3. Changed `replaceBubbleIndex` to accept `NotifyEntity` instead of `BubbleItem*`, enabling replacement logic before creating a new `BubbleItem` 4. `replaceBubble` now handles resource cleanup by calling `deleteLater()` on both old and new bubbles as needed 5. Removed the no longer needed `isReplaceBubble()` method, simplifying the public interface Log: Refactored bubble replacement mechanism; added silent in-place update for performance Influence: 1. Test notification replacement with and without `x-deepin- SilentReplace` hint 2. Verify that in-place update works for silent replacements (no visual artifacts) 3. Test replacement with different app names and bubble IDs to confirm no false matches 4. Verify memory management: old bubbles are properly deleted via `deleteLater()` 5. Test boundary cases: invalid replaceIndex, null bubble, concurrent notifications 6. Verify that `dataChanged` signal correctly triggers view updates for non-silent replacements refactor: 优化气泡替换逻辑,支持静默替换 1. 重构 BubbleModel API:将 `isReplaceBubble()` 和 `replaceBubble(BubbleItem*)` 替换为更清晰的 `replaceBubbleIndex(NotifyEntity)`、`updateBubbleInPlace()` 和 `replaceBubble(int, BubbleItem*)` 2. 通过 `x-deepin-SilentReplace` 提示增加"静默替换"支持:当气泡匹配且提 示为 true 时,使用 `dataChanged` 原地更新现有气泡,避免完整的移除-插入 操作 3. 将 `replaceBubbleIndex` 改为接受 `NotifyEntity` 而非 `BubbleItem*`, 允许在创建 `BubbleItem` 之前执行替换逻辑 4. `replaceBubble` 现在通过调用新旧气泡的 `deleteLater()` 来处理资源清理 5. 移除不再需要的 `isReplaceBubble()` 方法,简化公开接口 Log: 重构气泡替换机制;增加静默原地更新以提升性能 Influence: 1. 测试带或不带 `x-deepin-SilentReplace` 提示的通知替换 2. 验证静默替换时原地更新正常工作(无视觉异常) 3. 测试不同应用名和气泡 ID 的替换,确认无错误匹配 4. 验证内存管理:旧气泡通过 `deleteLater()` 正确释放 5. 测试边界情况:无效的 replaceIndex、空指针、并发通知 6. 验证对于非静默替换,`dataChanged` 信号正确触发视图更新 PMS: BUG-367205
| return; | ||
|
|
||
| // dataChanged 通知视图刷新 | ||
| // 前提:内容变更不会引起气泡高度变化,否则布局不刷新(应改用 replaceBubble)。 |
isReplaceBubble()andreplaceBubble(BubbleItem*)with cleanerreplaceBubbleIndex(NotifyEntity),updateBubbleInPlace(), andreplaceBubble(int, BubbleItem*)methodsx-deepin-SilentReplacehint: when two bubbles match and the hint is true, the existing bubble is updated in-place usingdataChangedrather than full remove+insertreplaceBubbleIndexto acceptNotifyEntityinstead ofBubbleItem*, enabling replacement logic before creating a newBubbleItemreplaceBubblenow handles resource cleanup by callingdeleteLater()on both old and new bubbles as neededisReplaceBubble()method, simplifying the public interfaceLog: Refactored bubble replacement mechanism; added silent in-place update for performance
Influence:
x-deepin- SilentReplacehintdeleteLater()dataChangedsignal correctly triggers view updates for non-silent replacementsrefactor: 优化气泡替换逻辑,支持静默替换
isReplaceBubble()和replaceBubble(BubbleItem*)替换为更清晰的replaceBubbleIndex(NotifyEntity)、updateBubbleInPlace()和replaceBubble(int, BubbleItem*)x-deepin-SilentReplace提示增加"静默替换"支持:当气泡匹配且提 示为 true 时,使用dataChanged原地更新现有气泡,避免完整的移除-插入操作
replaceBubbleIndex改为接受NotifyEntity而非BubbleItem*, 允许在创建BubbleItem之前执行替换逻辑replaceBubble现在通过调用新旧气泡的deleteLater()来处理资源清理isReplaceBubble()方法,简化公开接口Log: 重构气泡替换机制;增加静默原地更新以提升性能
Influence:
x-deepin-SilentReplace提示的通知替换deleteLater()正确释放dataChanged信号正确触发视图更新PMS: BUG-367205
Summary by Sourcery
Refactor notification bubble replacement to support index-based replacement and silent in-place updates driven by NotifyEntity metadata.
New Features:
Enhancements: