Update window_peer_menu.cpp

This commit is contained in:
Neurotoxin001 2025-06-26 20:46:53 +03:00 committed by GitHub
parent abb8f921fb
commit 941103de3e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -748,28 +748,28 @@ void Filler::addClearHistory() {
} }
void Filler::addDeleteMyMessages() { void Filler::addDeleteMyMessages() {
if (_topic) { if (_topic) {
return; return;
} }
const auto isGroup = _peer->isChat() || _peer->isMegagroup(); const auto isGroup = _peer - > isChat() || _peer - > isMegagroup();
if (!isGroup) { if (!isGroup) {
return; return;
} }
if (const auto chat = _peer->asChat()) { if (const auto chat = _peer - > asChat()) {
if (!chat->amIn() || chat->amCreator() || chat->hasAdminRights()) { if (!chat - > amIn() || chat - > amCreator() || chat - > hasAdminRights()) {
return; return;
} }
} else if (const auto channel = _peer->asChannel()) { } else if (const auto channel = _peer - > asChannel()) {
if (!channel->isMegagroup() || !channel->amIn() || channel->amCreator() || channel->hasAdminRights()) { if (!channel - > isMegagroup() || !channel - > amIn() || channel - > amCreator() || channel - > hasAdminRights()) {
return; return;
} }
} else { } else {
return; return;
} }
_addAction( _addAction(
tr::lng_profile_delete_my_messages(tr::now), tr::lng_profile_delete_my_messages(tr::now),
DeleteMyMessagesHandler(_controller, _peer), DeleteMyMessagesHandler(_controller, _peer), &
&st::menuIconDelete); st::menuIconDelete);
} }
void Filler::addDeleteChat() { void Filler::addDeleteChat() {
@ -3208,107 +3208,113 @@ Fn<void()> ClearHistoryHandler(
}; };
} }
void DeleteMyMessagesAfterConfirm(not_null<PeerData*> peer) { void DeleteMyMessagesAfterConfirm(not_null < PeerData * > peer) {
const auto session = &peer->session(); const auto session = & peer - > session();
auto collected = std::make_shared<std::vector<MsgId>>(); auto collected = std::make_shared < std::vector < MsgId >> ();
const auto removeNext = std::make_shared<Fn<void(int)>>(); const auto removeNext = std::make_shared < Fn < void(int) >> ();
const auto requestNext = std::make_shared<Fn<void(MsgId)>>(); const auto requestNext = std::make_shared < Fn < void(MsgId) >> ();
*removeNext = [=](int index) { * removeNext = [ = ](int index) {
if (index >= int(collected->size())) { if (index >= int(collected - > size())) {
DEBUG_LOG(("Deleted all %1 my messages in this chat").arg(collected->size())); DEBUG_LOG(("Deleted all %1 my messages in this chat").arg(collected - > size()));
return; return;
} }
QVector<MTPint> ids; QVector < MTPint > ids;
ids.reserve(std::min<int>(100, collected->size() - index)); ids.reserve(std::min < int > (100, collected - > size() - index));
for (auto i = 0; i < 100 && (index + i) < int(collected->size()); ++i) { for (auto i = 0; i < 100 && (index + i) < int(collected - > size()); ++i) {
ids.push_back(MTP_int((*collected)[index + i].bare)); ids.push_back(MTP_int(( * collected)[index + i].bare));
} }
const auto batch = index / 100 + 1; const auto batch = index / 100 + 1;
const auto done = [=](const MTPmessages_AffectedMessages &result) { const auto done = [ = ](const MTPmessages_AffectedMessages & result) {
session->api().applyAffectedMessages(peer, result); session - > api().applyAffectedMessages(peer, result);
if (peer->isChannel()) { if (peer - > isChannel()) {
session->data().processMessagesDeleted(peer->id, ids); session - > data().processMessagesDeleted(peer - > id, ids);
} else { } else {
session->data().processNonChannelMessagesDeleted(ids); session - > data().processNonChannelMessagesDeleted(ids);
} }
const auto deleted = index + ids.size(); const auto deleted = index + ids.size();
DEBUG_LOG(("Deleted batch %1, total deleted %2/%3").arg(batch).arg(deleted).arg(collected->size())); DEBUG_LOG(("Deleted batch %1, total deleted %2/%3").arg(batch).arg(deleted).arg(collected - > size()));
const auto delay = crl::time(500 + base::RandomValue<int>() % 500); const auto delay = crl::time(500 + base::RandomValue < int > () % 500);
base::call_delayed(delay, [=] { (*removeNext)(deleted); }); base::call_delayed(delay, [ = ] {
}; ( * removeNext)(deleted);
const auto fail = [=](const MTP::Error &error) { });
DEBUG_LOG(("Delete batch failed: %1").arg(error.type())); };
const auto delay = crl::time(1000); const auto fail = [ = ](const MTP::Error & error) {
base::call_delayed(delay, [=] { (*removeNext)(index); }); DEBUG_LOG(("Delete batch failed: %1").arg(error.type()));
}; const auto delay = crl::time(1000);
base::call_delayed(delay, [ = ] {
( * removeNext)(index);
});
};
if (const auto channel = peer->asChannel()) { if (const auto channel = peer - > asChannel()) {
session->api() session - > api()
.request(MTPchannels_DeleteMessages(channel->inputChannel, MTP_vector<MTPint>(ids))) .request(MTPchannels_DeleteMessages(channel - > inputChannel, MTP_vector < MTPint > (ids)))
.done(done) .done(done)
.fail(fail) .fail(fail)
.handleFloodErrors() .handleFloodErrors()
.send(); .send();
} else { } else {
using Flag = MTPmessages_DeleteMessages::Flag; using Flag = MTPmessages_DeleteMessages::Flag;
session->api() session - > api()
.request(MTPmessages_DeleteMessages(MTP_flags(Flag::f_revoke), MTP_vector<MTPint>(ids))) .request(MTPmessages_DeleteMessages(MTP_flags(Flag::f_revoke), MTP_vector < MTPint > (ids)))
.done(done) .done(done)
.fail(fail) .fail(fail)
.handleFloodErrors() .handleFloodErrors()
.send(); .send();
} }
}; };
*requestNext = [=](MsgId from) { * requestNext = [ = ](MsgId from) {
using Flag = MTPmessages_Search::Flag; using Flag = MTPmessages_Search::Flag;
auto request = MTPmessages_Search( auto request = MTPmessages_Search(
MTP_flags(Flag::f_from_id), MTP_flags(Flag::f_from_id),
peer->input, peer - > input,
MTP_string(), MTP_string(),
MTP_inputPeerSelf(), MTP_inputPeerSelf(),
MTPInputPeer(), MTPInputPeer(),
MTPVector<MTPReaction>(), MTPVector < MTPReaction > (),
MTP_int(0), // top_msg_id MTP_int(0), // top_msg_id
MTP_inputMessagesFilterEmpty(), MTP_inputMessagesFilterEmpty(),
MTP_int(0), // min_date MTP_int(0), // min_date
MTP_int(0), // max_date MTP_int(0), // max_date
MTP_int(from.bare), MTP_int(from.bare),
MTP_int(0), // add_offset MTP_int(0), // add_offset
MTP_int(100), MTP_int(100),
MTP_int(0), // max_id MTP_int(0), // max_id
MTP_int(0), // min_id MTP_int(0), // min_id
MTP_long(0)); // hash MTP_long(0)); // hash
session->api() session - > api()
.request(std::move(request)) .request(std::move(request))
.done([=](const Api::HistoryRequestResult &result) { .done([ = ](const Api::HistoryRequestResult & result) {
auto parsed = Api::ParseHistoryResult(peer, from, Data::LoadDirection::Before, result); auto parsed = Api::ParseHistoryResult(peer, from, Data::LoadDirection::Before, result);
MsgId minId; MsgId minId;
int batchCount = 0; int batchCount = 0;
for (const auto &id : parsed.messageIds) { for (const auto & id: parsed.messageIds) {
if (!minId || id < minId) minId = id; if (!minId || id < minId) minId = id;
collected->push_back(id); collected - > push_back(id);
++batchCount; ++batchCount;
} }
DEBUG_LOG(("Batch found %1 my messages, total %2").arg(batchCount).arg(collected->size())); DEBUG_LOG(("Batch found %1 my messages, total %2").arg(batchCount).arg(collected - > size()));
if (parsed.messageIds.size() == 100 && minId) { if (parsed.messageIds.size() == 100 && minId) {
(*requestNext)(minId - MsgId(1)); ( * requestNext)(minId - MsgId(1));
} else { } else {
DEBUG_LOG(("Found %1 my messages in this chat (SEARCH)").arg(collected->size())); DEBUG_LOG(("Found %1 my messages in this chat (SEARCH)").arg(collected - > size()));
(*removeNext)(0); ( * removeNext)(0);
} }
}) })
.fail([=](const MTP::Error &error) { DEBUG_LOG(("History fetch failed: %1").arg(error.type())); }) .fail([ = ](const MTP::Error & error) {
.send(); DEBUG_LOG(("History fetch failed: %1").arg(error.type()));
}; })
.send();
};
(*requestNext)(MsgId(0)); ( * requestNext)(MsgId(0));
} }
Fn<void()> DeleteMyMessagesHandler(not_null<Window::SessionController *> controller, not_null<PeerData *> peer) { Fn<void()> DeleteMyMessagesHandler(not_null<Window::SessionController *> controller, not_null<PeerData *> peer) {