Browse Source

fix: reply notifs sometimes destroyed too early (#25101)

* fix: reply notifs sometimes destroyed too early

* Fix windows build

Co-authored-by: Shelley Vohr <[email protected]>
trop[bot] 4 years ago
parent
commit
cbd91b1fba

+ 4 - 1
shell/browser/notifications/mac/notification_center_delegate.mm

@@ -42,7 +42,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();

+ 4 - 2
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() {

+ 1 - 1
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();
 

+ 1 - 1
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";