2
0
mirror of https://github.com/kotatogram/kotatogram-desktop synced 2025-08-31 06:35:14 +00:00

Prepare code for revoking of full history.

This commit is contained in:
John Preston
2019-03-21 16:07:32 +04:00
parent 2701e63406
commit dd8c526fb7
9 changed files with 111 additions and 162 deletions

View File

@@ -2335,7 +2335,7 @@ int ApiWrap::OnlineTillFromStatus(
Unexpected("Bad UserStatus type.");
}
void ApiWrap::clearHistory(not_null<PeerData*> peer) {
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()) {
@@ -2349,7 +2349,7 @@ void ApiWrap::clearHistory(not_null<PeerData*> peer) {
}
if (const auto channel = peer->asChannel()) {
if (const auto migrated = peer->migrateFrom()) {
clearHistory(migrated);
clearHistory(migrated, revoke);
}
if (IsServerMsgId(deleteTillId)) {
request(MTPchannels_DeleteHistory(
@@ -2358,19 +2358,65 @@ void ApiWrap::clearHistory(not_null<PeerData*> peer) {
)).send();
}
} else {
request(MTPmessages_DeleteHistory(
MTP_flags(MTPmessages_DeleteHistory::Flag::f_just_clear),
peer->input,
MTP_int(0)
)).done([=](const MTPmessages_AffectedHistory &result) {
const auto offset = applyAffectedHistory(peer, result);
if (offset > 0) {
clearHistory(peer);
}
}).send();
deleteHistory(peer, true, revoke);
}
}
void ApiWrap::deleteConversation(not_null<PeerData*> peer, bool revoke) {
if (const auto history = _session->data().historyLoaded(peer->id)) {
_session->data().setPinnedDialog(history, false);
App::main()->removeDialog(history);
history->clear();
if (const auto channel = peer->asMegagroup()) {
channel->addFlags(MTPDchannel::Flag::f_left);
if (const auto from = channel->getMigrateFromChat()) {
if (const auto migrated = _session->data().historyLoaded(from)) {
migrated->updateChatListExistence();
}
}
} else {
history->markFullyLoaded();
}
}
if (const auto chat = peer->asChat()) {
request(MTPmessages_DeleteChatUser(
chat->inputChat,
_session->user()->inputUser
)).done([=](const MTPUpdates &updates) {
applyUpdates(updates);
deleteHistory(peer, false, revoke);
}).fail([=](const RPCError &error) {
deleteHistory(peer, false, revoke);
}).send();
return;
} else if (const auto channel = peer->asChannel()) {
channel->ptsWaitingForShortPoll(-1);
leaveChannel(channel);
} else {
deleteHistory(peer, false, revoke);
}
}
void ApiWrap::deleteHistory(not_null<PeerData*> peer, bool justClear, bool revoke) {
using Flag = MTPmessages_DeleteHistory::Flag;
const auto flags = Flag(0)
| (justClear ? Flag::f_just_clear : Flag(0))
| ((peer->isUser() && revoke) ? Flag::f_revoke : Flag(0));
request(MTPmessages_DeleteHistory(
MTP_flags(flags),
peer->input,
MTP_int(0)
)).done([=](const MTPmessages_AffectedHistory &result) {
const auto offset = applyAffectedHistory(peer, result);
if (offset > 0) {
deleteHistory(peer, justClear, revoke);
} else if (!justClear && cReportSpamStatuses().contains(peer->id)) {
cRefReportSpamStatuses().remove(peer->id);
Local::writeReportSpamStatuses();
}
}).send();
}
int ApiWrap::applyAffectedHistory(
not_null<PeerData*> peer,
const MTPmessages_AffectedHistory &result) {