From a27a80351a249e10906f1cf10c6a55e599bd956b Mon Sep 17 00:00:00 2001 From: John Preston Date: Wed, 5 Jun 2019 18:15:49 +0300 Subject: [PATCH] Fix clearing history with local messages. --- Telegram/SourceFiles/apiwrap.cpp | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/Telegram/SourceFiles/apiwrap.cpp b/Telegram/SourceFiles/apiwrap.cpp index a9ee13bc1..eb62dd8f4 100644 --- a/Telegram/SourceFiles/apiwrap.cpp +++ b/Telegram/SourceFiles/apiwrap.cpp @@ -2439,9 +2439,27 @@ int ApiWrap::OnlineTillFromStatus( void ApiWrap::clearHistory(not_null peer, bool revoke) { auto deleteTillId = MsgId(0); if (const auto history = _session->data().historyLoaded(peer)) { - if (const auto last = history->lastMessage()) { - deleteTillId = last->id; + while (history->lastMessageKnown()) { + const auto last = history->lastMessage(); + if (!last) { + // History is empty. + return; + } else if (!IsServerMsgId(last->id)) { + // Destroy client-side message locally. + last->destroy(); + } else { + break; + } } + if (!history->lastMessageKnown()) { + requestDialogEntry(history, [=] { + Expects(history->lastMessageKnown()); + + clearHistory(peer, revoke); + }); + return; + } + deleteTillId = history->lastMessage()->id; history->clear(History::ClearType::ClearHistory); } if (const auto channel = peer->asChannel()) {