deleting all messages by from on client side

This commit is contained in:
John Preston 2016-03-11 14:13:28 +03:00
parent 98e2700764
commit b402d832f6
1 changed files with 32 additions and 15 deletions

View File

@ -476,16 +476,11 @@ void RichDeleteMessageBox::onDelete() {
QVector<MTPint> 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<MTPint>(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<MTPint>(1, MTP_int(item->id))), rpcDone(&RichDeleteMessageBox::reportDone), rpcFail(&RichDeleteMessageBox::deleteFail));
}
if (deleteAll) {
QVector<MsgId> 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<MsgId>::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 (offset > 0) {
_deleteAllRequestId = MTP::send(MTPchannels_DeleteUserHistory(_channel->inputChannel, _from->inputUser), rpcDone(&RichDeleteMessageBox::deleteAllPart), rpcFail(&RichDeleteMessageBox::deleteFail));
return;
}
if (History *h = App::historyLoaded(_channel->id)) {
if (!h->lastMsg && App::main()) {
App::main()->checkPeerHistory(_channel);
}
}
checkFinished();
return;
}
_deleteAllRequestId = MTP::send(MTPchannels_DeleteUserHistory(_channel->inputChannel, _from->inputUser), rpcDone(&RichDeleteMessageBox::deleteAllPart), rpcFail(&RichDeleteMessageBox::deleteFail));
}
bool RichDeleteMessageBox::deleteFail(const RPCError &error, mtpRequestId req) {