From bea6c9e4e17d94d6d9a8d8938acb18a1634e024e Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Sun, 23 Aug 2020 21:27:46 -0700 Subject: [PATCH] fix: reply notifs sometimes destroyed too early (#25086) * fix: reply notifs sometimes destroyed too early * Fix windows build --- .../notifications/mac/notification_center_delegate.mm | 5 ++++- shell/browser/notifications/notification.cc | 6 ++++-- shell/browser/notifications/notification.h | 2 +- .../browser/notifications/win/windows_toast_notification.cc | 2 +- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/shell/browser/notifications/mac/notification_center_delegate.mm b/shell/browser/notifications/mac/notification_center_delegate.mm index 3d8c0073eab0..91a48b35af54 100644 --- a/shell/browser/notifications/mac/notification_center_delegate.mm +++ b/shell/browser/notifications/mac/notification_center_delegate.mm @@ -43,7 +43,10 @@ // 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(); diff --git a/shell/browser/notifications/notification.cc b/shell/browser/notifications/notification.cc index 62c4441b0a43..7c894dc8e014 100644 --- a/shell/browser/notifications/notification.cc +++ b/shell/browser/notifications/notification.cc @@ -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() { diff --git a/shell/browser/notifications/notification.h b/shell/browser/notifications/notification.h index 1a465bdbef88..ac95e575b12f 100644 --- a/shell/browser/notifications/notification.h +++ b/shell/browser/notifications/notification.h @@ -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(); diff --git a/shell/browser/notifications/win/windows_toast_notification.cc b/shell/browser/notifications/win/windows_toast_notification.cc index b5ca4dc62853..30070d0b9cd0 100644 --- a/shell/browser/notifications/win/windows_toast_notification.cc +++ b/shell/browser/notifications/win/windows_toast_notification.cc @@ -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";