Allow saving boosts to lift restrictions.

This commit is contained in:
John Preston
2024-02-06 14:54:15 +04:00
parent f6a8c1e996
commit 180b14ea36
7 changed files with 317 additions and 23 deletions
@@ -198,6 +198,37 @@ void SaveSlowmodeSeconds(
api->registerModifyRequest(key, requestId);
}
void SaveBoostsUnrestrict(
not_null<ChannelData*> channel,
int boostsUnrestrict,
Fn<void()> done) {
const auto api = &channel->session().api();
const auto key = Api::RequestKey("boosts_unrestrict", channel->id);
const auto requestId = api->request(
MTPchannels_SetBoostsToUnblockRestrictions(
channel->inputChannel,
MTP_int(boostsUnrestrict))
).done([=](const MTPUpdates &result) {
api->clearModifyRequest(key);
api->applyUpdates(result);
channel->setBoostsUnrestrict(
channel->boostsApplied(),
boostsUnrestrict);
done();
}).fail([=](const MTP::Error &error) {
api->clearModifyRequest(key);
if (error.type() != u"CHAT_NOT_MODIFIED"_q) {
return;
}
channel->setBoostsUnrestrict(
channel->boostsApplied(),
boostsUnrestrict);
done();
}).send();
api->registerModifyRequest(key, requestId);
}
void ShowEditPermissions(
not_null<Window::SessionNavigation*> navigation,
not_null<PeerData*> peer) {
@@ -215,6 +246,10 @@ void ShowEditPermissions(
close);
if (const auto channel = peer->asChannel()) {
SaveSlowmodeSeconds(channel, result.slowmodeSeconds, close);
SaveBoostsUnrestrict(
channel,
result.boostsUnrestrict,
close);
}
};
auto done = [=](EditPeerPermissionsBoxResult result) {
@@ -225,7 +260,8 @@ void ShowEditPermissions(
const auto saveFor = peer->migrateToOrMe();
const auto chat = saveFor->asChat();
if (!result.slowmodeSeconds || !chat) {
if (!chat
|| (!result.slowmodeSeconds && !result.boostsUnrestrict)) {
save(saveFor, result);
return;
}