Add td_api::setSupergroupUnrestrictBoostCount.

This commit is contained in:
levlam 2024-02-12 17:42:35 +03:00
parent 9d0ca2670e
commit 46f076f47c
6 changed files with 103 additions and 2 deletions

View File

@ -9391,9 +9391,14 @@ setSupergroupStickerSet supergroup_id:int53 sticker_set_id:int64 = Ok;
//@description Changes the custom emoji sticker set of a supergroup; requires can_change_info administrator right. The chat must have at least chatBoostFeatures.min_custom_emoji_sticker_set_boost_level boost level to pass the corresponding color
//@supergroup_id Identifier of the supergroup
//@custom_emoji_sticker_set_id New value of the custom emoji sticker set identifier for the supergroup. Use 0 to remove the custom emoji sticker set in the supergroup
//@custom_emoji_sticker_set_id New value of the custom emoji sticker set identifier for the supergroup; requires can_change_info administrator right. Use 0 to remove the custom emoji sticker set in the supergroup
setSupergroupCustomEmojiStickerSet supergroup_id:int53 custom_emoji_sticker_set_id:int64 = Ok;
//@description Changes the number of times the supergroup must be boosted by a user to ignore slow mode and chat permission restrictions; requires can_restrict_members administrator right
//@supergroup_id Identifier of the supergroup
//@unrestrict_boost_count New value of the unrestrict_boost_count supergroup setting; 0-8. Use 0 to remove the setting
setSupergroupUnrestrictBoostCount supergroup_id:int53 unrestrict_boost_count:int32 = Ok;
//@description Toggles whether sender signature is added to sent messages in a channel; requires can_change_info administrator right @supergroup_id Identifier of the channel @sign_messages New value of sign_messages
toggleSupergroupSignMessages supergroup_id:int53 sign_messages:Bool = Ok;

View File

@ -1533,6 +1533,51 @@ class SetChannelEmojiStickerSetQuery final : public Td::ResultHandler {
}
};
class SetChannelBoostsToUnblockRestrictionsQuery final : public Td::ResultHandler {
Promise<Unit> promise_;
ChannelId channel_id_;
int32 unrestrict_boost_count_;
public:
explicit SetChannelBoostsToUnblockRestrictionsQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
}
void send(ChannelId channel_id, int32 unrestrict_boost_count) {
channel_id_ = channel_id;
unrestrict_boost_count_ = unrestrict_boost_count;
auto input_channel = td_->contacts_manager_->get_input_channel(channel_id);
CHECK(input_channel != nullptr);
send_query(G()->net_query_creator().create(
telegram_api::channels_setBoostsToUnblockRestrictions(std::move(input_channel), unrestrict_boost_count),
{{channel_id}}));
}
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::channels_setBoostsToUnblockRestrictions>(packet);
if (result_ptr.is_error()) {
return on_error(result_ptr.move_as_error());
}
auto ptr = result_ptr.move_as_ok();
LOG(DEBUG) << "Receive result for SetChannelBoostsToUnblockRestrictionsQuery: " << to_string(ptr);
td_->contacts_manager_->on_update_channel_unrestrict_boost_count(channel_id_, unrestrict_boost_count_);
td_->updates_manager_->on_get_updates(std::move(ptr), std::move(promise_));
}
void on_error(Status status) final {
if (status.message() == "CHAT_NOT_MODIFIED") {
td_->contacts_manager_->on_update_channel_unrestrict_boost_count(channel_id_, unrestrict_boost_count_);
if (!td_->auth_manager_->is_bot()) {
promise_.set_value(Unit());
return;
}
} else {
td_->contacts_manager_->on_get_channel_error(channel_id_, status, "SetChannelBoostsToUnblockRestrictionsQuery");
}
promise_.set_error(std::move(status));
}
};
class ToggleChannelSignaturesQuery final : public Td::ResultHandler {
Promise<Unit> promise_;
ChannelId channel_id_;
@ -7353,7 +7398,7 @@ void ContactsManager::set_channel_emoji_sticker_set(ChannelId channel_id, Sticke
if (!c->is_megagroup) {
return promise.set_error(Status::Error(400, "Cuctom emoji sticker set can be set only for supergroups"));
}
if (!get_channel_permissions(channel_id, c).can_change_info_and_settings()) {
if (!get_channel_status(c).can_change_info_and_settings()) {
return promise.set_error(
Status::Error(400, "Not enough rights to change custom emoji sticker set in the supergroup"));
}
@ -7372,6 +7417,27 @@ void ContactsManager::set_channel_emoji_sticker_set(ChannelId channel_id, Sticke
->send(channel_id, sticker_set_id, std::move(input_sticker_set));
}
void ContactsManager::set_channel_unrestrict_boost_count(ChannelId channel_id, int32 unrestrict_boost_count,
Promise<Unit> &&promise) {
auto c = get_channel(channel_id);
if (c == nullptr) {
return promise.set_error(Status::Error(400, "Supergroup not found"));
}
if (!c->is_megagroup) {
return promise.set_error(Status::Error(400, "Unrestrict boost count can be set only for supergroups"));
}
if (!get_channel_status(c).can_restrict_members()) {
return promise.set_error(
Status::Error(400, "Not enough rights to change unrestrict boost count set in the supergroup"));
}
if (unrestrict_boost_count < 0 || unrestrict_boost_count > 8) {
return promise.set_error(Status::Error(400, "Invalid new value for the unrestrict boost count specified"));
}
td_->create_handler<SetChannelBoostsToUnblockRestrictionsQuery>(std::move(promise))
->send(channel_id, unrestrict_boost_count);
}
void ContactsManager::toggle_channel_sign_messages(ChannelId channel_id, bool sign_messages, Promise<Unit> &&promise) {
auto c = get_channel(channel_id);
if (c == nullptr) {
@ -15600,6 +15666,19 @@ void ContactsManager::on_update_channel_emoji_sticker_set(ChannelId channel_id,
}
}
void ContactsManager::on_update_channel_unrestrict_boost_count(ChannelId channel_id, int32 unrestrict_boost_count) {
CHECK(channel_id.is_valid());
auto channel_full = get_channel_full_force(channel_id, true, "on_update_channel_unrestrict_boost_count");
if (channel_full == nullptr) {
return;
}
if (channel_full->unrestrict_boost_count != unrestrict_boost_count) {
channel_full->unrestrict_boost_count = unrestrict_boost_count;
channel_full->is_changed = true;
update_channel_full(channel_full, channel_id, "on_update_channel_unrestrict_boost_count");
}
}
void ContactsManager::on_update_channel_linked_channel_id(ChannelId channel_id, ChannelId group_channel_id) {
if (channel_id.is_valid()) {
auto channel_full = get_channel_full_force(channel_id, true, "on_update_channel_linked_channel_id 1");

View File

@ -268,6 +268,7 @@ class ContactsManager final : public Actor {
void on_update_channel_description(ChannelId channel_id, string &&description);
void on_update_channel_sticker_set(ChannelId channel_id, StickerSetId sticker_set_id);
void on_update_channel_emoji_sticker_set(ChannelId channel_id, StickerSetId sticker_set_id);
void on_update_channel_unrestrict_boost_count(ChannelId channel_id, int32 unrestrict_boost_count);
void on_update_channel_linked_channel_id(ChannelId channel_id, ChannelId group_channel_id);
void on_update_channel_location(ChannelId channel_id, const DialogLocation &location);
void on_update_channel_slow_mode_delay(ChannelId channel_id, int32 slow_mode_delay, Promise<Unit> &&promise);
@ -471,6 +472,8 @@ class ContactsManager final : public Actor {
void set_channel_emoji_sticker_set(ChannelId channel_id, StickerSetId sticker_set_id, Promise<Unit> &&promise);
void set_channel_unrestrict_boost_count(ChannelId channel_id, int32 unrestrict_boost_count, Promise<Unit> &&promise);
void toggle_channel_sign_messages(ChannelId channel_id, bool sign_messages, Promise<Unit> &&promise);
void toggle_channel_join_to_send(ChannelId channel_id, bool joint_to_send, Promise<Unit> &&promise);

View File

@ -7802,6 +7802,12 @@ void Td::on_request(uint64 id, const td_api::setSupergroupCustomEmojiStickerSet
ChannelId(request.supergroup_id_), StickerSetId(request.custom_emoji_sticker_set_id_), std::move(promise));
}
void Td::on_request(uint64 id, const td_api::setSupergroupUnrestrictBoostCount &request) {
CREATE_OK_REQUEST_PROMISE();
contacts_manager_->set_channel_unrestrict_boost_count(ChannelId(request.supergroup_id_),
request.unrestrict_boost_count_, std::move(promise));
}
void Td::on_request(uint64 id, const td_api::toggleSupergroupSignMessages &request) {
CHECK_IS_USER();
CREATE_OK_REQUEST_PROMISE();

View File

@ -1384,6 +1384,8 @@ class Td final : public Actor {
void on_request(uint64 id, const td_api::setSupergroupCustomEmojiStickerSet &request);
void on_request(uint64 id, const td_api::setSupergroupUnrestrictBoostCount &request);
void on_request(uint64 id, const td_api::toggleSupergroupSignMessages &request);
void on_request(uint64 id, const td_api::toggleSupergroupJoinToSendMessages &request);

View File

@ -5771,6 +5771,12 @@ class CliClient final : public Actor {
get_args(args, supergroup_id, sticker_set_id);
send_request(td_api::make_object<td_api::setSupergroupCustomEmojiStickerSet>(as_supergroup_id(supergroup_id),
sticker_set_id));
} else if (op == "ssgubc") {
string supergroup_id;
int32 unrestrict_boost_count;
get_args(args, supergroup_id, unrestrict_boost_count);
send_request(td_api::make_object<td_api::setSupergroupUnrestrictBoostCount>(as_supergroup_id(supergroup_id),
unrestrict_boost_count));
} else if (op == "tsgp") {
string supergroup_id;
bool is_all_history_available;