Clean up unnecessary calls to Manager::Private::clearNotification

It was added to replicate NotificationData::close but lots of places call it after the notification is already cleared
This commit is contained in:
Ilya Fedin 2025-03-02 11:29:02 +00:00 committed by John Preston
parent 66fc9b38df
commit 9e12e18f90

View file

@ -720,11 +720,8 @@ void Manager::Private::showNotification(
oldNotification->id, oldNotification->id,
nullptr); nullptr);
}); });
clearNotification(notificationId);
i = _notifications.find(key);
} }
} } else {
if (i == end(_notifications)) {
i = _notifications.emplace(key).first; i = _notifications.emplace(key).first;
} }
v::match(notification, [&](Gio::Notification &notification) { v::match(notification, [&](Gio::Notification &notification) {
@ -814,16 +811,11 @@ void Manager::Private::showNotification(
void Manager::Private::clearAll() { void Manager::Private::clearAll() {
for (const auto &[key, notifications] : base::take(_notifications)) { for (const auto &[key, notifications] : base::take(_notifications)) {
for (const auto &[msgId, notification] : notifications) { for (const auto &[msgId, notification] : notifications) {
const auto notificationId = NotificationId{
.contextId = key,
.msgId = msgId,
};
v::match(notification, [&](const std::string &notification) { v::match(notification, [&](const std::string &notification) {
_application.withdraw_notification(notification); _application.withdraw_notification(notification);
}, [&](const Notification &notification) { }, [&](const Notification &notification) {
_interface.call_close_notification(notification->id, nullptr); _interface.call_close_notification(notification->id, nullptr);
}); });
clearNotification(notificationId);
} }
} }
} }
@ -834,10 +826,6 @@ void Manager::Private::clearFromItem(not_null<HistoryItem*> item) {
.peerId = item->history()->peer->id, .peerId = item->history()->peer->id,
.topicRootId = item->topicRootId(), .topicRootId = item->topicRootId(),
}; };
const auto notificationId = NotificationId{
.contextId = key,
.msgId = item->id,
};
const auto i = _notifications.find(key); const auto i = _notifications.find(key);
if (i == _notifications.cend()) { if (i == _notifications.cend()) {
return; return;
@ -856,7 +844,6 @@ void Manager::Private::clearFromItem(not_null<HistoryItem*> item) {
}, [&](const Notification &taken) { }, [&](const Notification &taken) {
_interface.call_close_notification(taken->id, nullptr); _interface.call_close_notification(taken->id, nullptr);
}); });
clearNotification(notificationId);
} }
void Manager::Private::clearFromTopic(not_null<Data::ForumTopic*> topic) { void Manager::Private::clearFromTopic(not_null<Data::ForumTopic*> topic) {
@ -870,16 +857,11 @@ void Manager::Private::clearFromTopic(not_null<Data::ForumTopic*> topic) {
_notifications.erase(i); _notifications.erase(i);
for (const auto &[msgId, notification] : temp) { for (const auto &[msgId, notification] : temp) {
const auto notificationId = NotificationId{
.contextId = key,
.msgId = msgId,
};
v::match(notification, [&](const std::string &notification) { v::match(notification, [&](const std::string &notification) {
_application.withdraw_notification(notification); _application.withdraw_notification(notification);
}, [&](const Notification &notification) { }, [&](const Notification &notification) {
_interface.call_close_notification(notification->id, nullptr); _interface.call_close_notification(notification->id, nullptr);
}); });
clearNotification(notificationId);
} }
} }
} }
@ -887,11 +869,10 @@ void Manager::Private::clearFromTopic(not_null<Data::ForumTopic*> topic) {
void Manager::Private::clearFromHistory(not_null<History*> history) { void Manager::Private::clearFromHistory(not_null<History*> history) {
const auto sessionId = history->session().uniqueId(); const auto sessionId = history->session().uniqueId();
const auto peerId = history->peer->id; const auto peerId = history->peer->id;
const auto key = ContextId{ auto i = _notifications.lower_bound(ContextId{
.sessionId = sessionId, .sessionId = sessionId,
.peerId = peerId, .peerId = peerId,
}; });
auto i = _notifications.lower_bound(key);
while (i != _notifications.cend() while (i != _notifications.cend()
&& i->first.sessionId == sessionId && i->first.sessionId == sessionId
&& i->first.peerId == peerId) { && i->first.peerId == peerId) {
@ -899,41 +880,30 @@ void Manager::Private::clearFromHistory(not_null<History*> history) {
i = _notifications.erase(i); i = _notifications.erase(i);
for (const auto &[msgId, notification] : temp) { for (const auto &[msgId, notification] : temp) {
const auto notificationId = NotificationId{
.contextId = key,
.msgId = msgId,
};
v::match(notification, [&](const std::string &notification) { v::match(notification, [&](const std::string &notification) {
_application.withdraw_notification(notification); _application.withdraw_notification(notification);
}, [&](const Notification &notification) { }, [&](const Notification &notification) {
_interface.call_close_notification(notification->id, nullptr); _interface.call_close_notification(notification->id, nullptr);
}); });
clearNotification(notificationId);
} }
} }
} }
void Manager::Private::clearFromSession(not_null<Main::Session*> session) { void Manager::Private::clearFromSession(not_null<Main::Session*> session) {
const auto sessionId = session->uniqueId(); const auto sessionId = session->uniqueId();
const auto key = ContextId{ auto i = _notifications.lower_bound(ContextId{
.sessionId = sessionId, .sessionId = sessionId,
}; });
auto i = _notifications.lower_bound(key);
while (i != _notifications.cend() && i->first.sessionId == sessionId) { while (i != _notifications.cend() && i->first.sessionId == sessionId) {
const auto temp = base::take(i->second); const auto temp = base::take(i->second);
i = _notifications.erase(i); i = _notifications.erase(i);
for (const auto &[msgId, notification] : temp) { for (const auto &[msgId, notification] : temp) {
const auto notificationId = NotificationId{
.contextId = key,
.msgId = msgId,
};
v::match(notification, [&](const std::string &notification) { v::match(notification, [&](const std::string &notification) {
_application.withdraw_notification(notification); _application.withdraw_notification(notification);
}, [&](const Notification &notification) { }, [&](const Notification &notification) {
_interface.call_close_notification(notification->id, nullptr); _interface.call_close_notification(notification->id, nullptr);
}); });
clearNotification(notificationId);
} }
} }
} }