From b402d832f6a5617f7a76ab85166ffaf0b9d7df67 Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 11 Mar 2016 14:13:28 +0300 Subject: [PATCH] deleting all messages by from on client side --- Telegram/SourceFiles/boxes/confirmbox.cpp | 47 +++++++++++++++-------- 1 file changed, 32 insertions(+), 15 deletions(-) diff --git a/Telegram/SourceFiles/boxes/confirmbox.cpp b/Telegram/SourceFiles/boxes/confirmbox.cpp index 79cb4efca..9c22e5e5d 100644 --- a/Telegram/SourceFiles/boxes/confirmbox.cpp +++ b/Telegram/SourceFiles/boxes/confirmbox.cpp @@ -476,16 +476,11 @@ void RichDeleteMessageBox::onDelete() { QVector toDelete(1, MTP_int(item->id)); History *h = item->history(); - bool wasOnServer = (item->id > 0), wasLast = (h->lastMsg == item); + bool deleteItem = (item->id > 0), lastDeleted = (h->lastMsg == item); bool banUser = _banUser.checked(), reportSpam = _reportSpam.checked(), deleteAll = _deleteAll.checked(); item->destroy(); - if (!wasOnServer && wasLast && !h->lastMsg) { - App::main()->checkPeerHistory(h->peer); - } - - Notify::historyItemsResized(); - if (wasOnServer) { + if (deleteItem) { _deleteRequestId = MTP::send(MTPchannels_DeleteMessages(_channel->inputChannel, MTP_vector(1, MTP_int(item->id))), rpcDone(&RichDeleteMessageBox::deleteDone), rpcFail(&RichDeleteMessageBox::deleteFail)); } if (banUser) { @@ -495,8 +490,30 @@ void RichDeleteMessageBox::onDelete() { _reportRequestId = MTP::send(MTPchannels_ReportSpam(_channel->inputChannel, _from->inputUser, MTP_vector(1, MTP_int(item->id))), rpcDone(&RichDeleteMessageBox::reportDone), rpcFail(&RichDeleteMessageBox::deleteFail)); } if (deleteAll) { + QVector toDestroy; + for (History::Blocks::const_iterator i = h->blocks.cbegin(), e = h->blocks.cend(); i != e; ++i) { + for (HistoryBlock::Items::const_iterator j = (*i)->items.cbegin(), n = (*i)->items.cend(); j != n; ++j) { + if ((*j)->from() == _from && (*j)->type() == HistoryItemMsg) { + toDestroy.push_back((*j)->id); + } + } + } + for (QVector::const_iterator i = toDestroy.cbegin(), e = toDestroy.cend(); i != e; ++i) { + if (HistoryItem *item = App::histItemById(peerToChannel(_channel->id), *i)) { + if (item == h->lastMsg) { + lastDeleted = true; + } + item->destroy(); + } + } _deleteAllRequestId = MTP::send(MTPchannels_DeleteUserHistory(_channel->inputChannel, _from->inputUser), rpcDone(&RichDeleteMessageBox::deleteAllPart), rpcFail(&RichDeleteMessageBox::deleteFail)); } + + if (!deleteItem && !deleteAll && lastDeleted && !h->lastMsg) { + App::main()->checkPeerHistory(h->peer); + } + + Notify::historyItemsResized(); } void RichDeleteMessageBox::showAll() { @@ -574,17 +591,17 @@ void RichDeleteMessageBox::deleteAllPart(const MTPmessages_AffectedHistory &resu } int32 offset = d.voffset.v; - if (offset <= 0) { - if (History *h = App::historyLoaded(_channel->id)) { - if (!h->lastMsg && App::main()) { - App::main()->checkPeerHistory(_channel); - } - } - checkFinished(); + if (offset > 0) { + _deleteAllRequestId = MTP::send(MTPchannels_DeleteUserHistory(_channel->inputChannel, _from->inputUser), rpcDone(&RichDeleteMessageBox::deleteAllPart), rpcFail(&RichDeleteMessageBox::deleteFail)); return; } - _deleteAllRequestId = MTP::send(MTPchannels_DeleteUserHistory(_channel->inputChannel, _from->inputUser), rpcDone(&RichDeleteMessageBox::deleteAllPart), rpcFail(&RichDeleteMessageBox::deleteFail)); + if (History *h = App::historyLoaded(_channel->id)) { + if (!h->lastMsg && App::main()) { + App::main()->checkPeerHistory(_channel); + } + } + checkFinished(); } bool RichDeleteMessageBox::deleteFail(const RPCError &error, mtpRequestId req) {