Add td_api::toggleSupergroupCanHaveSponsoredMessages.

This commit is contained in:
levlam 2024-04-02 15:17:31 +03:00
parent 2bec18d95d
commit 25574476a3
6 changed files with 106 additions and 0 deletions

View File

@ -9834,6 +9834,11 @@ toggleSupergroupJoinByRequest supergroup_id:int53 join_by_request:Bool = Ok;
//@description Toggles whether the message history of a supergroup is available to new members; requires can_change_info member right @supergroup_id The identifier of the supergroup @is_all_history_available The new value of is_all_history_available
toggleSupergroupIsAllHistoryAvailable supergroup_id:int53 is_all_history_available:Bool = Ok;
//@description Toggles whether sponsored messages are shown in the channel chat; requires owner privileges in the channel. The chat must have at least chatBoostFeatures.min_sponsored_message_disable_boost_level boost level to disable sponsored messages
//@supergroup_id The identifier of the channel
//@can_have_sponsored_messages The new value of can_have_sponsored_messages
toggleSupergroupCanHaveSponsoredMessages supergroup_id:int53 can_have_sponsored_messages:Bool = Ok;
//@description Toggles whether non-administrators can receive only administrators and bots using getSupergroupMembers or searchChatMembers. Can be called only if supergroupFullInfo.can_hide_members == true
//@supergroup_id Identifier of the supergroup
//@has_hidden_members New value of has_hidden_members

View File

@ -728,6 +728,57 @@ class TogglePrehistoryHiddenQuery final : public Td::ResultHandler {
}
};
class RestrictSponsoredMessagesQuery final : public Td::ResultHandler {
Promise<Unit> promise_;
ChannelId channel_id_;
bool can_have_sponsored_messages_;
public:
explicit RestrictSponsoredMessagesQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
}
void send(ChannelId channel_id, bool can_have_sponsored_messages) {
channel_id_ = channel_id;
can_have_sponsored_messages_ = can_have_sponsored_messages;
auto input_channel = td_->chat_manager_->get_input_channel(channel_id);
CHECK(input_channel != nullptr);
send_query(G()->net_query_creator().create(
telegram_api::channels_restrictSponsoredMessages(std::move(input_channel), !can_have_sponsored_messages),
{{channel_id}}));
}
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::channels_restrictSponsoredMessages>(packet);
if (result_ptr.is_error()) {
return on_error(result_ptr.move_as_error());
}
auto ptr = result_ptr.move_as_ok();
LOG(INFO) << "Receive result for RestrictSponsoredMessagesQuery: " << to_string(ptr);
td_->updates_manager_->on_get_updates(
std::move(ptr),
PromiseCreator::lambda([actor_id = G()->chat_manager(), promise = std::move(promise_), channel_id = channel_id_,
can_have_sponsored_messages = can_have_sponsored_messages_](Unit result) mutable {
send_closure(actor_id, &ChatManager::on_update_channel_can_have_sponsored_messages, channel_id,
can_have_sponsored_messages, std::move(promise));
}));
}
void on_error(Status status) final {
if (status.message() == "CHAT_NOT_MODIFIED") {
if (!td_->auth_manager_->is_bot()) {
promise_.set_value(Unit());
return;
}
} else {
td_->chat_manager_->on_get_channel_error(channel_id_, status, "RestrictSponsoredMessagesQuery");
}
promise_.set_error(std::move(status));
}
};
class ToggleParticipantsHiddenQuery final : public Td::ResultHandler {
Promise<Unit> promise_;
ChannelId channel_id_;
@ -3093,6 +3144,23 @@ void ChatManager::toggle_channel_is_all_history_available(ChannelId channel_id,
td_->create_handler<TogglePrehistoryHiddenQuery>(std::move(promise))->send(channel_id, is_all_history_available);
}
void ChatManager::toggle_channel_can_have_sponsored_messages(ChannelId channel_id, bool can_have_sponsored_messages,
Promise<Unit> &&promise) {
auto c = get_channel(channel_id);
if (c == nullptr) {
return promise.set_error(Status::Error(400, "Supergroup not found"));
}
if (!get_channel_status(c).is_creator()) {
return promise.set_error(Status::Error(400, "Not enough rights to disable sponsored messages"));
}
if (get_channel_type(c) != ChannelType::Broadcast) {
return promise.set_error(Status::Error(400, "Sponsored messages can be disabled only in channels"));
}
td_->create_handler<RestrictSponsoredMessagesQuery>(std::move(promise))
->send(channel_id, can_have_sponsored_messages);
}
Status ChatManager::can_hide_chat_participants(ChatId chat_id) const {
auto c = get_chat(chat_id);
if (c == nullptr) {
@ -7271,6 +7339,19 @@ void ChatManager::on_update_channel_is_all_history_available(ChannelId channel_i
promise.set_value(Unit());
}
void ChatManager::on_update_channel_can_have_sponsored_messages(ChannelId channel_id, bool can_have_sponsored_messages,
Promise<Unit> &&promise) {
TRY_STATUS_PROMISE(promise, G()->close_status());
CHECK(channel_id.is_valid());
auto channel_full = get_channel_full_force(channel_id, true, "on_update_channel_can_have_sponsored_messages");
if (channel_full != nullptr && channel_full->can_have_sponsored_messages != can_have_sponsored_messages) {
channel_full->can_have_sponsored_messages = can_have_sponsored_messages;
channel_full->is_changed = true;
update_channel_full(channel_full, channel_id, "on_update_channel_can_have_sponsored_messages");
}
promise.set_value(Unit());
}
void ChatManager::on_update_channel_has_hidden_participants(ChannelId channel_id, bool has_hidden_participants,
Promise<Unit> &&promise) {
TRY_STATUS_PROMISE(promise, G()->close_status());

View File

@ -167,6 +167,8 @@ class ChatManager final : public Actor {
void on_update_channel_slow_mode_next_send_date(ChannelId channel_id, int32 slow_mode_next_send_date);
void on_update_channel_is_all_history_available(ChannelId channel_id, bool is_all_history_available,
Promise<Unit> &&promise);
void on_update_channel_can_have_sponsored_messages(ChannelId channel_id, bool can_have_sponsored_messages,
Promise<Unit> &&promise);
void on_update_channel_has_hidden_participants(ChannelId channel_id, bool has_hidden_participants,
Promise<Unit> &&promise);
void on_update_channel_has_aggressive_anti_spam_enabled(ChannelId channel_id, bool has_aggressive_anti_spam_enabled,
@ -246,6 +248,9 @@ class ChatManager final : public Actor {
void toggle_channel_is_all_history_available(ChannelId channel_id, bool is_all_history_available,
Promise<Unit> &&promise);
void toggle_channel_can_have_sponsored_messages(ChannelId channel_id, bool can_have_sponsored_messages,
Promise<Unit> &&promise);
void toggle_channel_has_hidden_participants(ChannelId channel_id, bool has_hidden_participants,
Promise<Unit> &&promise);

View File

@ -8047,6 +8047,13 @@ void Td::on_request(uint64 id, const td_api::toggleSupergroupIsAllHistoryAvailab
request.is_all_history_available_, std::move(promise));
}
void Td::on_request(uint64 id, const td_api::toggleSupergroupCanHaveSponsoredMessages &request) {
CHECK_IS_USER();
CREATE_OK_REQUEST_PROMISE();
chat_manager_->toggle_channel_can_have_sponsored_messages(ChannelId(request.supergroup_id_),
request.can_have_sponsored_messages_, std::move(promise));
}
void Td::on_request(uint64 id, const td_api::toggleSupergroupHasHiddenMembers &request) {
CHECK_IS_USER();
CREATE_OK_REQUEST_PROMISE();

View File

@ -1461,6 +1461,8 @@ class Td final : public Actor {
void on_request(uint64 id, const td_api::toggleSupergroupIsAllHistoryAvailable &request);
void on_request(uint64 id, const td_api::toggleSupergroupCanHaveSponsoredMessages &request);
void on_request(uint64 id, const td_api::toggleSupergroupHasHiddenMembers &request);
void on_request(uint64 id, const td_api::toggleSupergroupHasAggressiveAntiSpamEnabled &request);

View File

@ -5919,6 +5919,12 @@ class CliClient final : public Actor {
get_args(args, supergroup_id, is_all_history_available);
send_request(td_api::make_object<td_api::toggleSupergroupIsAllHistoryAvailable>(as_supergroup_id(supergroup_id),
is_all_history_available));
} else if (op == "tsgchsm") {
string supergroup_id;
bool can_have_sponsored_messages;
get_args(args, supergroup_id, can_have_sponsored_messages);
send_request(td_api::make_object<td_api::toggleSupergroupCanHaveSponsoredMessages>(
as_supergroup_id(supergroup_id), can_have_sponsored_messages));
} else if (op == "tsghhm") {
string supergroup_id;
bool has_hidden_members;