Skip to content
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

fix: reply notifs sometimes destroyed too early #25102

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -42,7 +42,10 @@ - (void)userNotificationCenter:(NSUserNotificationCenter*)center
// https://developer.apple.com/documentation/foundation/nsusernotificationactivationtype?language=objc
if (notif.activationType ==
NSUserNotificationActivationTypeContentsClicked) {
notification->NotificationClicked();
// If a notification with a reply button is clicked and the user has not
// yet replied, we do not want to destroy the notification.
bool should_destroy = ![notif hasReplyButton];
notification->NotificationClicked(should_destroy);
} else if (notif.activationType ==
NSUserNotificationActivationTypeActionButtonClicked) {
notification->NotificationActivated();
Expand Down
6 changes: 4 additions & 2 deletions shell/browser/notifications/notification.cc
Expand Up @@ -21,10 +21,12 @@ Notification::~Notification() {
delegate()->NotificationDestroyed();
}

void Notification::NotificationClicked() {
void Notification::NotificationClicked(bool should_destroy) {
if (delegate())
delegate()->NotificationClick();
Destroy();

if (should_destroy)
Destroy();
}

void Notification::NotificationDismissed() {
Expand Down
2 changes: 1 addition & 1 deletion shell/browser/notifications/notification.h
Expand Up @@ -54,7 +54,7 @@ class Notification {
virtual void Dismiss() = 0;

// Should be called by derived classes.
void NotificationClicked();
void NotificationClicked(bool should_destroy = true);
void NotificationDismissed();
void NotificationFailed();

Expand Down
Expand Up @@ -476,7 +476,7 @@ IFACEMETHODIMP ToastEventHandler::Invoke(
IInspectable* args) {
base::PostTask(
FROM_HERE, {content::BrowserThread::UI},
base::BindOnce(&Notification::NotificationClicked, notification_));
base::BindOnce(&Notification::NotificationClicked, notification_, true));
if (IsDebuggingNotifications())
LOG(INFO) << "Notification clicked";

Expand Down