Fix clearing history with local messages.

This commit is contained in:
John Preston 2019-06-05 18:15:49 +03:00
parent e53f4a5450
commit a27a80351a
1 changed files with 20 additions and 2 deletions

View File

@ -2439,9 +2439,27 @@ int ApiWrap::OnlineTillFromStatus(
void ApiWrap::clearHistory(not_null<PeerData*> 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()) {