Add td_api::getAvailableChatBoostSlots.

This commit is contained in:
levlam 2023-10-21 01:24:25 +03:00
parent de3aebd011
commit 4f4537ba33
6 changed files with 97 additions and 4 deletions

View File

@ -3523,16 +3523,27 @@ prepaidPremiumGiveaway id:int64 user_count:int32 month_count:int32 payment_date:
//@prepaid_giveaways The list of prepaid giveaways available for the chat; only for chat administrators
chatBoostStatus boost_url:string applied_slot_ids:vector<int32> level:int32 gift_code_boost_count:int32 boost_count:int32 current_level_boost_count:int32 next_level_boost_count:int32 premium_member_count:int32 premium_member_percentage:double prepaid_giveaways:vector<prepaidPremiumGiveaway> = ChatBoostStatus;
//@description Describes a boost of a chat
//@count The number of boosts applied
//@description Describes a boost applied to a chat
//@count The number of identical boosts applied
//@source Source of the boost
//@start_date Point in time (Unix timestamp) when the boost was added
//@start_date Point in time (Unix timestamp) when the chat was boosted
//@expiration_date Point in time (Unix timestamp) when the boost will expire
chatBoost count:int32 source:ChatBoostSource start_date:int32 expiration_date:int32 = ChatBoost;
//@description Contains a list of boosts applied to a chat @total_count Total number of boosts applied to the chat @boosts List of boosts @next_offset The offset for the next request. If empty, there are no more results
foundChatBoosts total_count:int32 boosts:vector<chatBoost> next_offset:string = FoundChatBoosts;
//@description Describes a slot for chat boost
//@slot_id Unique identifier of the slot
//@currently_boosted_chat_id Identifier of the currently boosted chat; 0 if none
//@start_date Point in time (Unix timestamp) when the chat was boosted; 0 if none
//@expiration_date Point in time (Unix timestamp) when the boost will expire
//@cooldown_until_date Point in time (Unix timestamp) after which the boost can be used for another chat
chatBoostSlot slot_id:int32 currently_boosted_chat_id:int53 start_date:int32 expiration_date:int32 cooldown_until_date:int32 = ChatBoostSlot;
//@description Contains a list of chat boost slots @slots List of boost slots
chatBoostSlots slots:vector<chatBoostSlot> = ChatBoostSlots;
//@class CallDiscardReason @description Describes the reason why a call was discarded
@ -7920,6 +7931,9 @@ reportStory story_sender_chat_id:int53 story_id:int32 reason:ReportReason text:s
activateStoryStealthMode = Ok;
//@description Returns the list of available chat boost slots for the current user
getAvailableChatBoostSlots = ChatBoostSlots;
//@description Returns the current boost status for a channel chat @chat_id Identifier of the channel chat
getChatBoostStatus chat_id:int53 = ChatBoostStatus;

View File

@ -19,6 +19,69 @@
namespace td {
static td_api::object_ptr<td_api::chatBoostSlots> get_chat_boost_slots_object(
Td *td, telegram_api::object_ptr<telegram_api::premium_myBoosts> &&my_boosts) {
td->contacts_manager_->on_get_users(std::move(my_boosts->users_), "GetMyBoostsQuery");
td->contacts_manager_->on_get_chats(std::move(my_boosts->chats_), "GetMyBoostsQuery");
vector<td_api::object_ptr<td_api::chatBoostSlot>> slots;
for (auto &my_boost : my_boosts->my_boosts_) {
auto expiration_date = my_boost->expires_;
if (expiration_date <= G()->unix_time()) {
continue;
}
auto start_date = max(0, my_boost->date_);
auto cooldown_until_date = max(0, my_boost->cooldown_until_date_);
DialogId dialog_id;
if (my_boost->peer_ != nullptr) {
dialog_id = DialogId(my_boost->peer_);
if (!dialog_id.is_valid()) {
LOG(ERROR) << "Receive " << to_string(my_boost);
continue;
}
}
if (dialog_id.is_valid()) {
td->messages_manager_->force_create_dialog(dialog_id, "GetMyBoostsQuery", true);
} else {
start_date = 0;
cooldown_until_date = 0;
}
slots.push_back(td_api::make_object<td_api::chatBoostSlot>(
my_boost->slot_, td->messages_manager_->get_chat_id_object(dialog_id, "GetMyBoostsQuery"), start_date,
expiration_date, cooldown_until_date));
}
return td_api::make_object<td_api::chatBoostSlots>(std::move(slots));
}
class GetMyBoostsQuery final : public Td::ResultHandler {
Promise<td_api::object_ptr<td_api::chatBoostSlots>> promise_;
DialogId dialog_id_;
public:
explicit GetMyBoostsQuery(Promise<td_api::object_ptr<td_api::chatBoostSlots>> &&promise)
: promise_(std::move(promise)) {
}
void send() {
send_query(G()->net_query_creator().create(telegram_api::premium_getMyBoosts(), {{"me"}}));
}
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::premium_getMyBoosts>(packet);
if (result_ptr.is_error()) {
return on_error(result_ptr.move_as_error());
}
auto result = result_ptr.move_as_ok();
LOG(DEBUG) << "Receive result for GetMyBoostsQuery: " << to_string(result);
promise_.set_value(get_chat_boost_slots_object(td_, std::move(result)));
}
void on_error(Status status) final {
promise_.set_error(std::move(status));
}
};
class GetBoostsStatusQuery final : public Td::ResultHandler {
Promise<td_api::object_ptr<td_api::chatBoostStatus>> promise_;
DialogId dialog_id_;
@ -106,7 +169,7 @@ class ApplyBoostQuery final : public Td::ResultHandler {
send_query(
G()->net_query_creator().create(telegram_api::premium_applyBoost(telegram_api::premium_applyBoost::SLOTS_MASK,
std::move(slot_ids), std::move(input_peer)),
{{dialog_id}}));
{{dialog_id}, {"me"}}));
}
void on_result(BufferSlice packet) final {
@ -216,6 +279,10 @@ void BoostManager::tear_down() {
parent_.reset();
}
void BoostManager::get_boost_slots(Promise<td_api::object_ptr<td_api::chatBoostSlots>> &&promise) {
td_->create_handler<GetMyBoostsQuery>(std::move(promise))->send();
}
void BoostManager::get_dialog_boost_status(DialogId dialog_id,
Promise<td_api::object_ptr<td_api::chatBoostStatus>> &&promise) {
if (!td_->messages_manager_->have_dialog_force(dialog_id, "get_dialog_boost_status")) {

View File

@ -24,6 +24,8 @@ class BoostManager final : public Actor {
public:
BoostManager(Td *td, ActorShared<> parent);
void get_boost_slots(Promise<td_api::object_ptr<td_api::chatBoostSlots>> &&promise);
void get_dialog_boost_status(DialogId dialog_id, Promise<td_api::object_ptr<td_api::chatBoostStatus>> &&promise);
void boost_dialog(DialogId dialog_id, vector<int32> slot_ids, Promise<Unit> &&promise);

View File

@ -6637,6 +6637,12 @@ void Td::on_request(uint64 id, const td_api::activateStoryStealthMode &request)
story_manager_->activate_stealth_mode(std::move(promise));
}
void Td::on_request(uint64 id, const td_api::getAvailableChatBoostSlots &request) {
CHECK_IS_USER();
CREATE_REQUEST_PROMISE();
boost_manager_->get_boost_slots(std::move(promise));
}
void Td::on_request(uint64 id, const td_api::getChatBoostStatus &request) {
CHECK_IS_USER();
CREATE_REQUEST_PROMISE();

View File

@ -1048,6 +1048,8 @@ class Td final : public Actor {
void on_request(uint64 id, const td_api::activateStoryStealthMode &request);
void on_request(uint64 id, const td_api::getAvailableChatBoostSlots &request);
void on_request(uint64 id, const td_api::getChatBoostStatus &request);
void on_request(uint64 id, const td_api::boostChat &request);

View File

@ -4367,6 +4367,8 @@ class CliClient final : public Actor {
send_request(td_api::make_object<td_api::reportStory>(story_sender_chat_id, story_id, reason, text));
} else if (op == "assm") {
send_request(td_api::make_object<td_api::activateStoryStealthMode>());
} else if (op == "gacbs") {
send_request(td_api::make_object<td_api::getAvailableChatBoostSlots>());
} else if (op == "gcbs") {
ChatId chat_id;
get_args(args, chat_id);