Use flat_map::remove in clearFrom{Topic,Item}

Now that notification closing happens in destructor, the iterator is no more needed
This commit is contained in:
Ilya Fedin 2025-03-06 13:17:05 +00:00 committed by John Preston
parent 4ac48d0e4a
commit 700e10d32c

View file

@ -789,35 +789,24 @@ void Manager::Private::clearAll() {
} }
void Manager::Private::clearFromItem(not_null<HistoryItem*> item) { void Manager::Private::clearFromItem(not_null<HistoryItem*> item) {
const auto key = ContextId{ const auto i = _notifications.find(ContextId{
.sessionId = item->history()->session().uniqueId(), .sessionId = item->history()->session().uniqueId(),
.peerId = item->history()->peer->id, .peerId = item->history()->peer->id,
.topicRootId = item->topicRootId(), .topicRootId = item->topicRootId(),
}; });
const auto i = _notifications.find(key); if (i != _notifications.cend()
if (i == _notifications.cend()) { && i->second.remove(item->id)
return; && i->second.empty()) {
}
const auto j = i->second.find(item->id);
if (j == i->second.end()) {
return;
}
i->second.erase(j);
if (i->second.empty()) {
_notifications.erase(i); _notifications.erase(i);
} }
} }
void Manager::Private::clearFromTopic(not_null<Data::ForumTopic*> topic) { void Manager::Private::clearFromTopic(not_null<Data::ForumTopic*> topic) {
const auto key = ContextId{ _notifications.remove(ContextId{
.sessionId = topic->session().uniqueId(), .sessionId = topic->session().uniqueId(),
.peerId = topic->history()->peer->id, .peerId = topic->history()->peer->id,
.topicRootId = topic->rootId(), .topicRootId = topic->rootId(),
}; });
const auto i = _notifications.find(key);
if (i != _notifications.cend()) {
_notifications.erase(i);
}
} }
void Manager::Private::clearFromHistory(not_null<History*> history) { void Manager::Private::clearFromHistory(not_null<History*> history) {
@ -846,10 +835,10 @@ void Manager::Private::clearFromSession(not_null<Main::Session*> session) {
void Manager::Private::clearNotification(NotificationId id) { void Manager::Private::clearNotification(NotificationId id) {
auto i = _notifications.find(id.contextId); auto i = _notifications.find(id.contextId);
if (i != _notifications.cend()) { if (i != _notifications.cend()
if (i->second.remove(id.msgId) && i->second.empty()) { && i->second.remove(id.msgId)
_notifications.erase(i); && i->second.empty()) {
} _notifications.erase(i);
} }
} }