diff --git a/Telegram/SourceFiles/apiwrap.cpp b/Telegram/SourceFiles/apiwrap.cpp index a9ee13bc17..eb62dd8f45 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()) {