Allow deleting small groups for everyone.

This commit is contained in:
John Preston 2021-01-21 17:31:27 +04:00
parent 58733ba6ea
commit 417428b21d
4 changed files with 54 additions and 11 deletions

View File

@ -2350,14 +2350,14 @@ void ApiWrap::deleteHistory(
deleteTillId = history->lastMessage()->id;
}
if (const auto channel = peer->asChannel()) {
if (!justClear) {
if (!justClear && !revoke) {
channel->ptsWaitingForShortPoll(-1);
leaveChannel(channel);
} else {
if (const auto migrated = peer->migrateFrom()) {
deleteHistory(migrated, justClear, revoke);
}
if (IsServerMsgId(deleteTillId)) {
if (IsServerMsgId(deleteTillId) || (!justClear && revoke)) {
history->owner().histories().deleteAllMessages(
history,
deleteTillId,

View File

@ -578,7 +578,8 @@ void DeleteMessagesBox::prepare() {
const auto appendDetails = [&](TextWithEntities &&text) {
details.append(qstr("\n\n")).append(std::move(text));
};
auto deleteText = tr::lng_box_delete();
auto deleteText = lifetime().make_state<rpl::variable<QString>>();
*deleteText = tr::lng_box_delete();
auto deleteStyle = &st::defaultBoxButton;
if (const auto peer = _wipeHistoryPeer) {
if (_wipeHistoryJustClear) {
@ -598,14 +599,22 @@ void DeleteMessagesBox::prepare() {
: peer->isMegagroup()
? tr::lng_sure_leave_group(tr::now)
: tr::lng_sure_leave_channel(tr::now);
deleteText = _wipeHistoryPeer->isUser()
? tr::lng_box_delete()
: tr::lng_box_leave();
if (!peer->isUser()) {
*deleteText = tr::lng_box_leave();
}
deleteStyle = &st::attentionBoxButton;
}
if (auto revoke = revokeText(peer)) {
_revoke.create(this, revoke->checkbox, false, st::defaultBoxCheckbox);
appendDetails(std::move(revoke->description));
if (!peer->isUser() && !_wipeHistoryJustClear) {
_revoke->checkedValue(
) | rpl::start_with_next([=](bool revokeForAll) {
*deleteText = revokeForAll
? tr::lng_box_delete()
: tr::lng_box_leave();
}, _revoke->lifetime());
}
}
} else if (_moderateFrom) {
Assert(_moderateInChannel != nullptr);
@ -642,7 +651,7 @@ void DeleteMessagesBox::prepare() {
_text.create(this, rpl::single(std::move(details)), st::boxLabel);
addButton(
std::move(deleteText),
deleteText->value(),
[=] { deleteAndClear(); },
*deleteStyle);
addButton(tr::lng_cancel(), [=] { closeBox(); });

View File

@ -593,19 +593,49 @@ void Histories::deleteAllMessages(
const auto fail = [=](const RPCError &error) {
finish();
};
if (const auto channel = peer->asChannel()) {
const auto chat = peer->asChat();
const auto channel = peer->asChannel();
if (revoke && channel && channel->canDelete()) {
return session().api().request(MTPchannels_DeleteChannel(
channel->inputChannel
)).done([=](const MTPUpdates &result) {
session().api().applyUpdates(result);
//}).fail([=](const RPCError &error) {
// if (error.type() == qstr("CHANNEL_TOO_LARGE")) {
// Ui::show(Box<InformBox>(tr::lng_cant_delete_channel(tr::now)));
// }
}).send();
} else if (channel) {
return session().api().request(MTPchannels_DeleteHistory(
channel->inputChannel,
MTP_int(deleteTillId)
)).done([=](const MTPBool &result) {
finish();
}).fail(fail).send();
} else if (revoke && peer->isChat() && peer->asChat()->amCreator()) {
} else if (revoke && chat && chat->amCreator()) {
return session().api().request(MTPmessages_DeleteChat(
peer->asChat()->inputChat
chat->inputChat
)).done([=](const MTPBool &result) {
finish();
}).fail(fail).send();
}).fail([=](const RPCError &error) {
if (error.type() == "PEER_ID_INVALID") {
// Try to join and delete,
// while delete fails for non-joined.
session().api().request(MTPmessages_AddChatUser(
chat->inputChat,
MTP_inputUserSelf(),
MTP_int(0)
)).done([=](const MTPUpdates &updates) {
session().api().applyUpdates(updates);
deleteAllMessages(
history,
deleteTillId,
justClear,
revoke);
}).send();
}
finish();
}).send();
} else {
using Flag = MTPmessages_DeleteHistory::Flag;
const auto flags = Flag(0)

View File

@ -836,6 +836,10 @@ bool PeerData::canRevokeFullHistory() const {
&& (session().serverConfig().revokePrivateTimeLimit == 0x7FFFFFFF);
} else if (const auto chat = asChat()) {
return chat->amCreator();
} else if (const auto megagroup = asMegagroup()) {
return megagroup->amCreator()
&& megagroup->membersCountKnown()
&& megagroup->canDelete();
}
return false;
}