mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-07 23:53:58 +02:00
Allow deleting small groups for everyone.
This commit is contained in:
parent
58733ba6ea
commit
417428b21d
4 changed files with 54 additions and 11 deletions
|
@ -2350,14 +2350,14 @@ void ApiWrap::deleteHistory(
|
||||||
deleteTillId = history->lastMessage()->id;
|
deleteTillId = history->lastMessage()->id;
|
||||||
}
|
}
|
||||||
if (const auto channel = peer->asChannel()) {
|
if (const auto channel = peer->asChannel()) {
|
||||||
if (!justClear) {
|
if (!justClear && !revoke) {
|
||||||
channel->ptsWaitingForShortPoll(-1);
|
channel->ptsWaitingForShortPoll(-1);
|
||||||
leaveChannel(channel);
|
leaveChannel(channel);
|
||||||
} else {
|
} else {
|
||||||
if (const auto migrated = peer->migrateFrom()) {
|
if (const auto migrated = peer->migrateFrom()) {
|
||||||
deleteHistory(migrated, justClear, revoke);
|
deleteHistory(migrated, justClear, revoke);
|
||||||
}
|
}
|
||||||
if (IsServerMsgId(deleteTillId)) {
|
if (IsServerMsgId(deleteTillId) || (!justClear && revoke)) {
|
||||||
history->owner().histories().deleteAllMessages(
|
history->owner().histories().deleteAllMessages(
|
||||||
history,
|
history,
|
||||||
deleteTillId,
|
deleteTillId,
|
||||||
|
|
|
@ -578,7 +578,8 @@ void DeleteMessagesBox::prepare() {
|
||||||
const auto appendDetails = [&](TextWithEntities &&text) {
|
const auto appendDetails = [&](TextWithEntities &&text) {
|
||||||
details.append(qstr("\n\n")).append(std::move(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;
|
auto deleteStyle = &st::defaultBoxButton;
|
||||||
if (const auto peer = _wipeHistoryPeer) {
|
if (const auto peer = _wipeHistoryPeer) {
|
||||||
if (_wipeHistoryJustClear) {
|
if (_wipeHistoryJustClear) {
|
||||||
|
@ -598,14 +599,22 @@ void DeleteMessagesBox::prepare() {
|
||||||
: peer->isMegagroup()
|
: peer->isMegagroup()
|
||||||
? tr::lng_sure_leave_group(tr::now)
|
? tr::lng_sure_leave_group(tr::now)
|
||||||
: tr::lng_sure_leave_channel(tr::now);
|
: tr::lng_sure_leave_channel(tr::now);
|
||||||
deleteText = _wipeHistoryPeer->isUser()
|
if (!peer->isUser()) {
|
||||||
? tr::lng_box_delete()
|
*deleteText = tr::lng_box_leave();
|
||||||
: tr::lng_box_leave();
|
}
|
||||||
deleteStyle = &st::attentionBoxButton;
|
deleteStyle = &st::attentionBoxButton;
|
||||||
}
|
}
|
||||||
if (auto revoke = revokeText(peer)) {
|
if (auto revoke = revokeText(peer)) {
|
||||||
_revoke.create(this, revoke->checkbox, false, st::defaultBoxCheckbox);
|
_revoke.create(this, revoke->checkbox, false, st::defaultBoxCheckbox);
|
||||||
appendDetails(std::move(revoke->description));
|
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) {
|
} else if (_moderateFrom) {
|
||||||
Assert(_moderateInChannel != nullptr);
|
Assert(_moderateInChannel != nullptr);
|
||||||
|
@ -642,7 +651,7 @@ void DeleteMessagesBox::prepare() {
|
||||||
_text.create(this, rpl::single(std::move(details)), st::boxLabel);
|
_text.create(this, rpl::single(std::move(details)), st::boxLabel);
|
||||||
|
|
||||||
addButton(
|
addButton(
|
||||||
std::move(deleteText),
|
deleteText->value(),
|
||||||
[=] { deleteAndClear(); },
|
[=] { deleteAndClear(); },
|
||||||
*deleteStyle);
|
*deleteStyle);
|
||||||
addButton(tr::lng_cancel(), [=] { closeBox(); });
|
addButton(tr::lng_cancel(), [=] { closeBox(); });
|
||||||
|
|
|
@ -593,19 +593,49 @@ void Histories::deleteAllMessages(
|
||||||
const auto fail = [=](const RPCError &error) {
|
const auto fail = [=](const RPCError &error) {
|
||||||
finish();
|
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(
|
return session().api().request(MTPchannels_DeleteHistory(
|
||||||
channel->inputChannel,
|
channel->inputChannel,
|
||||||
MTP_int(deleteTillId)
|
MTP_int(deleteTillId)
|
||||||
)).done([=](const MTPBool &result) {
|
)).done([=](const MTPBool &result) {
|
||||||
finish();
|
finish();
|
||||||
}).fail(fail).send();
|
}).fail(fail).send();
|
||||||
} else if (revoke && peer->isChat() && peer->asChat()->amCreator()) {
|
} else if (revoke && chat && chat->amCreator()) {
|
||||||
return session().api().request(MTPmessages_DeleteChat(
|
return session().api().request(MTPmessages_DeleteChat(
|
||||||
peer->asChat()->inputChat
|
chat->inputChat
|
||||||
)).done([=](const MTPBool &result) {
|
)).done([=](const MTPBool &result) {
|
||||||
finish();
|
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 {
|
} else {
|
||||||
using Flag = MTPmessages_DeleteHistory::Flag;
|
using Flag = MTPmessages_DeleteHistory::Flag;
|
||||||
const auto flags = Flag(0)
|
const auto flags = Flag(0)
|
||||||
|
|
|
@ -836,6 +836,10 @@ bool PeerData::canRevokeFullHistory() const {
|
||||||
&& (session().serverConfig().revokePrivateTimeLimit == 0x7FFFFFFF);
|
&& (session().serverConfig().revokePrivateTimeLimit == 0x7FFFFFFF);
|
||||||
} else if (const auto chat = asChat()) {
|
} else if (const auto chat = asChat()) {
|
||||||
return chat->amCreator();
|
return chat->amCreator();
|
||||||
|
} else if (const auto megagroup = asMegagroup()) {
|
||||||
|
return megagroup->amCreator()
|
||||||
|
&& megagroup->membersCountKnown()
|
||||||
|
&& megagroup->canDelete();
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue