Fix delete+leave from a legacy group.
We first need to leave and receive a new message update about us leaving the group and only after that remove the conversation locally from the chats list, otherwise it reappears in the list.
This commit is contained in:
		
							parent
							
								
									7cffb0ef9d
								
							
						
					
					
						commit
						388173f0ad
					
				
					 1 changed files with 56 additions and 49 deletions
				
			
		|  | @ -2423,9 +2423,33 @@ int ApiWrap::OnlineTillFromStatus( | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void ApiWrap::clearHistory(not_null<PeerData*> peer, bool revoke) { | void ApiWrap::clearHistory(not_null<PeerData*> peer, bool revoke) { | ||||||
|  | 	deleteHistory(peer, true, revoke); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | void ApiWrap::deleteConversation(not_null<PeerData*> peer, bool revoke) { | ||||||
|  | 	if (const auto chat = peer->asChat()) { | ||||||
|  | 		request(MTPmessages_DeleteChatUser( | ||||||
|  | 			chat->inputChat, | ||||||
|  | 			_session->user()->inputUser | ||||||
|  | 		)).done([=](const MTPUpdates &updates) { | ||||||
|  | 			applyUpdates(updates); | ||||||
|  | 			deleteHistory(peer, false, revoke); | ||||||
|  | 		}).fail([=](const RPCError &error) { | ||||||
|  | 			deleteHistory(peer, false, revoke); | ||||||
|  | 		}).send(); | ||||||
|  | 	} else { | ||||||
|  | 		deleteHistory(peer, false, revoke); | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | void ApiWrap::deleteHistory( | ||||||
|  | 		not_null<PeerData*> peer, | ||||||
|  | 		bool justClear, | ||||||
|  | 		bool revoke) { | ||||||
| 	auto deleteTillId = MsgId(0); | 	auto deleteTillId = MsgId(0); | ||||||
| 	const auto history = _session->data().historyLoaded(peer); | 	const auto history = _session->data().historyLoaded(peer); | ||||||
| 	if (history) { | 	if (history && justClear) { | ||||||
|  | 		// In case of clear history we need to know the last server message.
 | ||||||
| 		while (history->lastMessageKnown()) { | 		while (history->lastMessageKnown()) { | ||||||
| 			const auto last = history->lastMessage(); | 			const auto last = history->lastMessage(); | ||||||
| 			if (!last) { | 			if (!last) { | ||||||
|  | @ -2442,13 +2466,17 @@ void ApiWrap::clearHistory(not_null<PeerData*> peer, bool revoke) { | ||||||
| 			requestDialogEntry(history, [=] { | 			requestDialogEntry(history, [=] { | ||||||
| 				Expects(history->lastMessageKnown()); | 				Expects(history->lastMessageKnown()); | ||||||
| 
 | 
 | ||||||
| 				clearHistory(peer, revoke); | 				deleteHistory(peer, justClear, revoke); | ||||||
| 			}); | 			}); | ||||||
| 			return; | 			return; | ||||||
| 		} | 		} | ||||||
| 		deleteTillId = history->lastMessage()->id; | 		deleteTillId = history->lastMessage()->id; | ||||||
| 	} | 	} | ||||||
| 	if (const auto channel = peer->asChannel()) { | 	if (const auto channel = peer->asChannel()) { | ||||||
|  | 		if (!justClear) { | ||||||
|  | 			channel->ptsWaitingForShortPoll(-1); | ||||||
|  | 			leaveChannel(channel); | ||||||
|  | 		} else { | ||||||
| 			if (const auto migrated = peer->migrateFrom()) { | 			if (const auto migrated = peer->migrateFrom()) { | ||||||
| 				clearHistory(migrated, revoke); | 				clearHistory(migrated, revoke); | ||||||
| 			} | 			} | ||||||
|  | @ -2458,35 +2486,8 @@ void ApiWrap::clearHistory(not_null<PeerData*> peer, bool revoke) { | ||||||
| 					MTP_int(deleteTillId) | 					MTP_int(deleteTillId) | ||||||
| 				)).send(); | 				)).send(); | ||||||
| 			} | 			} | ||||||
|  | 		} | ||||||
| 	} else { | 	} else { | ||||||
| 		deleteHistory(peer, true, revoke); |  | ||||||
| 	} |  | ||||||
| 	if (history) { |  | ||||||
| 		history->clear(History::ClearType::ClearHistory); |  | ||||||
| 	} |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| void ApiWrap::deleteConversation(not_null<PeerData*> peer, bool revoke) { |  | ||||||
| 	if (const auto chat = peer->asChat()) { |  | ||||||
| 		request(MTPmessages_DeleteChatUser( |  | ||||||
| 			chat->inputChat, |  | ||||||
| 			_session->user()->inputUser |  | ||||||
| 		)).done([=](const MTPUpdates &updates) { |  | ||||||
| 			applyUpdates(updates); |  | ||||||
| 			deleteHistory(peer, false, revoke); |  | ||||||
| 		}).fail([=](const RPCError &error) { |  | ||||||
| 			deleteHistory(peer, false, revoke); |  | ||||||
| 		}).send(); |  | ||||||
| 	} else if (const auto channel = peer->asChannel()) { |  | ||||||
| 		channel->ptsWaitingForShortPoll(-1); |  | ||||||
| 		leaveChannel(channel); |  | ||||||
| 	} else { |  | ||||||
| 		deleteHistory(peer, false, revoke); |  | ||||||
| 	} |  | ||||||
| 	_session->data().deleteConversationLocally(peer); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| void ApiWrap::deleteHistory(not_null<PeerData*> peer, bool justClear, bool revoke) { |  | ||||||
| 		using Flag = MTPmessages_DeleteHistory::Flag; | 		using Flag = MTPmessages_DeleteHistory::Flag; | ||||||
| 		const auto flags = Flag(0) | 		const auto flags = Flag(0) | ||||||
| 			| (justClear ? Flag::f_just_clear : Flag(0)) | 			| (justClear ? Flag::f_just_clear : Flag(0)) | ||||||
|  | @ -2501,6 +2502,12 @@ void ApiWrap::deleteHistory(not_null<PeerData*> peer, bool justClear, bool revok | ||||||
| 				deleteHistory(peer, justClear, revoke); | 				deleteHistory(peer, justClear, revoke); | ||||||
| 			} | 			} | ||||||
| 		}).send(); | 		}).send(); | ||||||
|  | 	} | ||||||
|  | 	if (!justClear) { | ||||||
|  | 		_session->data().deleteConversationLocally(peer); | ||||||
|  | 	} else if (history) { | ||||||
|  | 		history->clear(History::ClearType::ClearHistory); | ||||||
|  | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| int ApiWrap::applyAffectedHistory( | int ApiWrap::applyAffectedHistory( | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 John Preston
						John Preston