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)); QVector<MTPint> toDelete(1, MTP_int(item->id));
History *h = item->history(); 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(); bool banUser = _banUser.checked(), reportSpam = _reportSpam.checked(), deleteAll = _deleteAll.checked();
item->destroy(); item->destroy();
if (!wasOnServer && wasLast && !h->lastMsg) { if (deleteItem) {
App::main()->checkPeerHistory(h->peer);
}
Notify::historyItemsResized();
if (wasOnServer) {
_deleteRequestId = MTP::send(MTPchannels_DeleteMessages(_channel->inputChannel, MTP_vector<MTPint>(1, MTP_int(item->id))), rpcDone(&RichDeleteMessageBox::deleteDone), rpcFail(&RichDeleteMessageBox::deleteFail)); _deleteRequestId = MTP::send(MTPchannels_DeleteMessages(_channel->inputChannel, MTP_vector<MTPint>(1, MTP_int(item->id))), rpcDone(&RichDeleteMessageBox::deleteDone), rpcFail(&RichDeleteMessageBox::deleteFail));
} }
if (banUser) { 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)); _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) { 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)); _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() { void RichDeleteMessageBox::showAll() {
@ -574,17 +591,17 @@ void RichDeleteMessageBox::deleteAllPart(const MTPmessages_AffectedHistory &resu
} }
int32 offset = d.voffset.v; 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 (History *h = App::historyLoaded(_channel->id)) {
if (!h->lastMsg && App::main()) { if (!h->lastMsg && App::main()) {
App::main()->checkPeerHistory(_channel); App::main()->checkPeerHistory(_channel);
} }
} }
checkFinished(); 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) { bool RichDeleteMessageBox::deleteFail(const RPCError &error, mtpRequestId req) {