-
Notifications
You must be signed in to change notification settings - Fork 58
feat(notification): Adjust the activation logic for the notification button #1419
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Reviewer's guide (collapsed on small PRs)Reviewer's GuideAdjusts notification action enablement so that action buttons are only interactive when there is a matching extension hint or when the notification is not in the notification center, and wires this enabled state through to the QML button. Sequence diagram for computing and applying notification action enabled statesequenceDiagram
actor User
participant NotificationSystem
participant AppNotifyItem
participant NotifyEntity
participant QmlEngine
participant NotifyActionQml
participant ActionButtonQml
NotificationSystem->>AppNotifyItem: create or update notification
AppNotifyItem->>NotifyEntity: hints()
NotifyEntity-->>AppNotifyItem: hints
AppNotifyItem->>NotifyEntity: processedType()
NotifyEntity-->>AppNotifyItem: type
AppNotifyItem->>AppNotifyItem: updateActions()
AppNotifyItem->>AppNotifyItem: compute enabled =
AppNotifyItem->>AppNotifyItem: hints contains x-deepin-action-id
AppNotifyItem->>AppNotifyItem: or type != Processed
AppNotifyItem-->>QmlEngine: actionData list with id, text, enabled
QmlEngine-->>NotifyActionQml: set actionData
NotifyActionQml->>ActionButtonQml: bind text = actionData.text
NotifyActionQml->>ActionButtonQml: bind enabled = actionData.enabled
User->>ActionButtonQml: click
ActionButtonQml->>QmlEngine: trigger action only if enabled == true
Class diagram for updated notification action enablement logicclassDiagram
class AppNotifyItem {
- NotifyEntity m_entity
+ void updateActions()
}
class NotifyEntity {
+ QMap~QString, QVariant~ hints()
+ ProcessedType processedType()
}
class ProcessedType {
<<enumeration>>
Processed
OtherStates
}
class NotifyActionQml {
+ var actionData
+ void bindText()
+ void bindEnabled()
}
AppNotifyItem --> NotifyEntity : uses
NotifyEntity --> ProcessedType : returns
AppNotifyItem --> NotifyActionQml : provides actionData
%% Key logic inside AppNotifyItem.updateActions
class AppNotifyItemUpdateActionsLogic {
+ void buildActionItem(QString id, QString text, QMap~QString, QVariant~ hints, ProcessedType type)
+ bool isActionEnabled(QString id, QMap~QString, QVariant~ hints, ProcessedType type)
}
AppNotifyItem ..> AppNotifyItemUpdateActionsLogic : contains logic
class ActionButtonQml {
+ var actionData
+ string text
+ bool enabled
}
NotifyActionQml --> ActionButtonQml : configures
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey - I've left some high level feedback:
- The C++ comment
// we only allow to invoke the action if we have the extension hint and it's not in the notify center.doesn't match the implemented||logic (enabled when hint exists OR not in notify center); consider updating the comment to reflect the actual condition.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The C++ comment `// we only allow to invoke the action if we have the extension hint and it's not in the notify center.` doesn't match the implemented `||` logic (enabled when hint exists OR not in notify center); consider updating the comment to reflect the actual condition.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
…button Only enable action buttons when extension hint exists or it's not in the notification center Pms: BUG-333027 Log: Adjust the activation logic for the notification button Signed-off-by: ComixHe <heyuming@deepin.org>
deepin pr auto review这段代码的修改主要是为了增强通知中心中操作按钮的控制逻辑,使其能够根据通知的状态和提示信息来决定按钮是否可用。以下是对这段代码的详细审查和改进建议: 1. 代码逻辑与功能审查功能概述: 逻辑分析:
潜在问题:
2. 代码质量与可读性优点:
改进建议:
3. 代码性能
改进建议:
4. 代码安全
改进建议:
5. 综合改进后的代码示例void AppNotifyItem::updateActions()
{
const QStringList actions = m_entity.actions();
if (actions.isEmpty()) {
return;
}
// 定义常量前缀
static const QLatin1String ACTION_HINT_PREFIX = QLatin1String("x-deepin-action-");
// 提前获取 hints 和 processed 状态
const auto hints = m_entity.hints();
const bool isProcessed = m_entity.processed();
QVariantList actionList;
for (int i = 0; i < actions.size(); i += 2) {
const auto id = actions[i];
const auto text = actions[i + 1];
// 类型安全检查
if (!id.canConvert<QString>() || !text.canConvert<QString>()) {
continue;
}
QVariantMap item;
item["id"] = id.toString();
item["text"] = text.toString();
// 按钮启用逻辑:有扩展提示 或 通知未被处理
item["enabled"] = hints.contains(ACTION_HINT_PREFIX + id.toString()) || !isProcessed;
actionList.append(item);
}
// 更新 UI
// ...
}6. QML 部分审查QML 代码的修改很直接,正确地将 enabled: actionData ? (actionData.enabled !== undefined ? actionData.enabled : false) : false这样可以更明确地处理 总结这段代码的修改在逻辑上是合理的,但可以通过以下方式改进:
这些改进将使代码更健壮、更易维护,同时保持原有功能不变。 |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: 18202781743, ComixHe 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 |
Only enable action buttons when extension hint exists or it's not in the notification center
Pms: BUG-333027
Log: Adjust the activation logic for the notification button
Summary by Sourcery
Bug Fixes: