Skip to content

Commit

Permalink
fix: reply notifs sometimes destroyed too early (#25102)
Browse files Browse the repository at this point in the history
* fix: reply notifs sometimes destroyed too early

* Fix windows build

Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
  • Loading branch information
trop[bot] and codebytere committed Aug 24, 2020
1 parent ad66542 commit 75b9ab7
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
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

0 comments on commit 75b9ab7

Please sign in to comment.