Fix clearing session notifications.
This commit is contained in:
		
							parent
							
								
									c3fa300b5c
								
							
						
					
					
						commit
						613a2f358a
					
				
					 3 changed files with 47 additions and 27 deletions
				
			
		| 
						 | 
					@ -582,7 +582,9 @@ void Manager::Private::showNotification(
 | 
				
			||||||
		const QString &msg,
 | 
							const QString &msg,
 | 
				
			||||||
		bool hideNameAndPhoto,
 | 
							bool hideNameAndPhoto,
 | 
				
			||||||
		bool hideReplyButton) {
 | 
							bool hideReplyButton) {
 | 
				
			||||||
	if (!Supported()) return;
 | 
						if (!Supported()) {
 | 
				
			||||||
 | 
							return;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	const auto key = FullPeer{
 | 
						const auto key = FullPeer{
 | 
				
			||||||
		.sessionId = peer->session().uniqueId(),
 | 
							.sessionId = peer->session().uniqueId(),
 | 
				
			||||||
| 
						 | 
					@ -630,7 +632,9 @@ void Manager::Private::showNotification(
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void Manager::Private::clearAll() {
 | 
					void Manager::Private::clearAll() {
 | 
				
			||||||
	if (!Supported()) return;
 | 
						if (!Supported()) {
 | 
				
			||||||
 | 
							return;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	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) {
 | 
				
			||||||
| 
						 | 
					@ -640,7 +644,9 @@ void Manager::Private::clearAll() {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void Manager::Private::clearFromHistory(not_null<History*> history) {
 | 
					void Manager::Private::clearFromHistory(not_null<History*> history) {
 | 
				
			||||||
	if (!Supported()) return;
 | 
						if (!Supported()) {
 | 
				
			||||||
 | 
							return;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	const auto key = FullPeer{
 | 
						const auto key = FullPeer{
 | 
				
			||||||
		.sessionId = history->session().uniqueId(),
 | 
							.sessionId = history->session().uniqueId(),
 | 
				
			||||||
| 
						 | 
					@ -658,11 +664,16 @@ void Manager::Private::clearFromHistory(not_null<History*> history) {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void Manager::Private::clearFromSession(not_null<Main::Session*> session) {
 | 
					void Manager::Private::clearFromSession(not_null<Main::Session*> session) {
 | 
				
			||||||
	if (!Supported()) return;
 | 
						if (!Supported()) {
 | 
				
			||||||
 | 
							return;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	const auto sessionId = session->uniqueId();
 | 
						const auto sessionId = session->uniqueId();
 | 
				
			||||||
	for (auto i = _notifications.begin(); i != _notifications.end();) {
 | 
						for (auto i = _notifications.begin(); i != _notifications.end();) {
 | 
				
			||||||
		if (i->first.sessionId == sessionId) {
 | 
							if (i->first.sessionId != sessionId) {
 | 
				
			||||||
 | 
								++i;
 | 
				
			||||||
 | 
								continue;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
		const auto temp = base::take(i->second);
 | 
							const auto temp = base::take(i->second);
 | 
				
			||||||
		i = _notifications.erase(i);
 | 
							i = _notifications.erase(i);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -671,10 +682,11 @@ void Manager::Private::clearFromSession(not_null<Main::Session*> session) {
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
void Manager::Private::clearNotification(NotificationId id) {
 | 
					void Manager::Private::clearNotification(NotificationId id) {
 | 
				
			||||||
	if (!Supported()) return;
 | 
						if (!Supported()) {
 | 
				
			||||||
 | 
							return;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	auto i = _notifications.find(id.full);
 | 
						auto i = _notifications.find(id.full);
 | 
				
			||||||
	if (i != _notifications.cend()) {
 | 
						if (i != _notifications.cend()) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -415,7 +415,9 @@ Manager::Private::~Private() {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void Manager::Private::clearAll() {
 | 
					void Manager::Private::clearAll() {
 | 
				
			||||||
	if (!_notifier) return;
 | 
						if (!_notifier) {
 | 
				
			||||||
 | 
							return;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	auto temp = base::take(_notifications);
 | 
						auto temp = base::take(_notifications);
 | 
				
			||||||
	for (const auto &[key, notifications] : base::take(_notifications)) {
 | 
						for (const auto &[key, notifications] : base::take(_notifications)) {
 | 
				
			||||||
| 
						 | 
					@ -426,7 +428,9 @@ void Manager::Private::clearAll() {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void Manager::Private::clearFromHistory(not_null<History*> history) {
 | 
					void Manager::Private::clearFromHistory(not_null<History*> history) {
 | 
				
			||||||
	if (!_notifier) return;
 | 
						if (!_notifier) {
 | 
				
			||||||
 | 
							return;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	auto i = _notifications.find(FullPeer{
 | 
						auto i = _notifications.find(FullPeer{
 | 
				
			||||||
		.sessionId = history->session().uniqueId(),
 | 
							.sessionId = history->session().uniqueId(),
 | 
				
			||||||
| 
						 | 
					@ -443,11 +447,16 @@ void Manager::Private::clearFromHistory(not_null<History*> history) {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void Manager::Private::clearFromSession(not_null<Main::Session*> session) {
 | 
					void Manager::Private::clearFromSession(not_null<Main::Session*> session) {
 | 
				
			||||||
	if (!_notifier) return;
 | 
						if (!_notifier) {
 | 
				
			||||||
 | 
							return;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	const auto sessionId = session->uniqueId();
 | 
						const auto sessionId = session->uniqueId();
 | 
				
			||||||
	for (auto i = _notifications.begin(); i != _notifications.end();) {
 | 
						for (auto i = _notifications.begin(); i != _notifications.end();) {
 | 
				
			||||||
		if (i->first.sessionId == sessionId) {
 | 
							if (i->first.sessionId != sessionId) {
 | 
				
			||||||
 | 
								++i;
 | 
				
			||||||
 | 
								continue;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
		const auto temp = base::take(i->second);
 | 
							const auto temp = base::take(i->second);
 | 
				
			||||||
		_notifications.erase(i);
 | 
							_notifications.erase(i);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -456,7 +465,6 @@ void Manager::Private::clearFromSession(not_null<Main::Session*> session) {
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
void Manager::Private::beforeNotificationActivated(NotificationId id) {
 | 
					void Manager::Private::beforeNotificationActivated(NotificationId id) {
 | 
				
			||||||
	clearNotification(id);
 | 
						clearNotification(id);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -207,15 +207,15 @@ void System::clearFromSession(not_null<Main::Session*> session) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for (auto i = _whenMaps.begin(); i != _whenMaps.end();) {
 | 
						for (auto i = _whenMaps.begin(); i != _whenMaps.end();) {
 | 
				
			||||||
		const auto history = i->first;
 | 
							const auto history = i->first;
 | 
				
			||||||
		if (&history->session() == session) {
 | 
							if (&history->session() != session) {
 | 
				
			||||||
 | 
								++i;
 | 
				
			||||||
 | 
								continue;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
		history->clearNotifications();
 | 
							history->clearNotifications();
 | 
				
			||||||
		i = _whenMaps.erase(i);
 | 
							i = _whenMaps.erase(i);
 | 
				
			||||||
		_whenAlerts.remove(history);
 | 
							_whenAlerts.remove(history);
 | 
				
			||||||
		_waiters.remove(history);
 | 
							_waiters.remove(history);
 | 
				
			||||||
		_settingWaiters.remove(history);
 | 
							_settingWaiters.remove(history);
 | 
				
			||||||
		} else {
 | 
					 | 
				
			||||||
			++i;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	const auto clearFrom = [&](auto &map) {
 | 
						const auto clearFrom = [&](auto &map) {
 | 
				
			||||||
		for (auto i = map.begin(); i != map.end();) {
 | 
							for (auto i = map.begin(); i != map.end();) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue