2015-12-25 02:16:07 +00:00
|
|
|
// Copyright (c) 2015 GitHub, Inc.
|
|
|
|
// Use of this source code is governed by the MIT license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/browser/notifications/notification_presenter.h"
|
2015-12-25 02:16:07 +00:00
|
|
|
|
2018-10-03 12:46:24 +00:00
|
|
|
#include <algorithm>
|
|
|
|
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/browser/notifications/notification.h"
|
2015-12-25 02:16:07 +00:00
|
|
|
|
2019-06-19 21:23:04 +00:00
|
|
|
namespace electron {
|
2015-12-25 02:16:07 +00:00
|
|
|
|
2019-09-16 22:12:00 +00:00
|
|
|
NotificationPresenter::NotificationPresenter() = default;
|
2015-12-25 02:16:07 +00:00
|
|
|
|
|
|
|
NotificationPresenter::~NotificationPresenter() {
|
|
|
|
for (Notification* notification : notifications_)
|
|
|
|
delete notification;
|
|
|
|
}
|
|
|
|
|
|
|
|
base::WeakPtr<Notification> NotificationPresenter::CreateNotification(
|
2018-04-08 19:24:08 +00:00
|
|
|
NotificationDelegate* delegate,
|
|
|
|
const std::string& notification_id) {
|
2017-01-10 15:34:41 +00:00
|
|
|
Notification* notification = CreateNotificationObject(delegate);
|
2018-04-08 19:24:08 +00:00
|
|
|
notification->set_notification_id(notification_id);
|
2015-12-25 02:16:07 +00:00
|
|
|
notifications_.insert(notification);
|
|
|
|
return notification->GetWeakPtr();
|
|
|
|
}
|
|
|
|
|
|
|
|
void NotificationPresenter::RemoveNotification(Notification* notification) {
|
2024-07-26 13:34:40 +00:00
|
|
|
auto it = notifications_.find(notification);
|
|
|
|
if (it == notifications_.end()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-12-25 02:16:07 +00:00
|
|
|
notifications_.erase(notification);
|
|
|
|
delete notification;
|
|
|
|
}
|
|
|
|
|
2018-04-08 19:24:08 +00:00
|
|
|
void NotificationPresenter::CloseNotificationWithId(
|
|
|
|
const std::string& notification_id) {
|
2024-08-26 14:58:32 +00:00
|
|
|
auto it = std::ranges::find_if(
|
|
|
|
notifications_, [¬ification_id](const Notification* n) {
|
|
|
|
return n->notification_id() == notification_id;
|
|
|
|
});
|
2020-07-03 06:04:32 +00:00
|
|
|
if (it != notifications_.end()) {
|
|
|
|
Notification* notification = (*it);
|
|
|
|
notification->Dismiss();
|
|
|
|
notifications_.erase(notification);
|
|
|
|
}
|
2018-04-08 19:24:08 +00:00
|
|
|
}
|
|
|
|
|
2019-06-19 21:23:04 +00:00
|
|
|
} // namespace electron
|