diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index d46ce0727..4106825fc 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -10139,18 +10139,24 @@ reportChatPhoto chat_id:int53 file_id:int32 reason:ReportReason text:string = Ok reportMessageReactions chat_id:int53 message_id:int53 sender_id:MessageSender = Ok; -//@description Returns detailed statistics about a chat. Currently, this method can be used only for supergroups and channels. Can be used only if supergroupFullInfo.can_get_statistics == true @chat_id Chat identifier @is_dark Pass true if a dark theme is used by the application -getChatStatistics chat_id:int53 is_dark:Bool = ChatStatistics; - //@description Returns detailed revenue statistics about a chat. Currently, this method can be used only for channels if supergroupFullInfo.can_get_revenue_statistics == true @chat_id Chat identifier @is_dark Pass true if a dark theme is used by the application getChatRevenueStatistics chat_id:int53 is_dark:Bool = ChatRevenueStatistics; +//@description Returns URL for chat revenue withdrawal; requires owner privileges in the chat. Currently, this method can be used only for channels if supergroupFullInfo.can_get_revenue_statistics == true +//@chat_id Chat identifier +//@password The 2-step verification password of the current user +getChatRevenueWithdrawalUrl chat_id:int53 password:string = HttpUrl; + //@description Returns list of revenue transactions for a chat. Currently, this method can be used only for channels if supergroupFullInfo.can_get_revenue_statistics == true //@chat_id Chat identifier //@offset Number of transactions to skip //@limit The maximum number of transactions to be returned; up to 200 getChatRevenueTransactions chat_id:int53 offset:int32 limit:int32 = ChatRevenueTransactions; + +//@description Returns detailed statistics about a chat. Currently, this method can be used only for supergroups and channels. Can be used only if supergroupFullInfo.can_get_statistics == true @chat_id Chat identifier @is_dark Pass true if a dark theme is used by the application +getChatStatistics chat_id:int53 is_dark:Bool = ChatStatistics; + //@description Returns detailed statistics about a message. Can be used only if message.can_get_statistics == true @chat_id Chat identifier @message_id Message identifier @is_dark Pass true if a dark theme is used by the application getMessageStatistics chat_id:int53 message_id:int53 is_dark:Bool = MessageStatistics; diff --git a/td/telegram/StatisticsManager.cpp b/td/telegram/StatisticsManager.cpp index 730671be4..41827ea8b 100644 --- a/td/telegram/StatisticsManager.cpp +++ b/td/telegram/StatisticsManager.cpp @@ -13,6 +13,7 @@ #include "td/telegram/MessageId.h" #include "td/telegram/MessagesManager.h" #include "td/telegram/misc.h" +#include "td/telegram/PasswordManager.h" #include "td/telegram/ServerMessageId.h" #include "td/telegram/StoryId.h" #include "td/telegram/StoryManager.h" @@ -323,6 +324,41 @@ class GetBroadcastRevenueStatsQuery final : public Td::ResultHandler { } }; +class GetBroadcastRevenueWithdrawalUrlQuery final : public Td::ResultHandler { + Promise promise_; + ChannelId channel_id_; + + public: + explicit GetBroadcastRevenueWithdrawalUrlQuery(Promise &&promise) : promise_(std::move(promise)) { + } + + void send(ChannelId channel_id, telegram_api::object_ptr input_check_password) { + channel_id_ = channel_id; + + auto input_channel = td_->chat_manager_->get_input_channel(channel_id); + if (input_channel == nullptr) { + return on_error(Status::Error(500, "Chat info not found")); + } + + send_query(G()->net_query_creator().create(telegram_api::stats_getBroadcastRevenueWithdrawalUrl( + std::move(input_channel), std::move(input_check_password)))); + } + + void on_result(BufferSlice packet) final { + auto result_ptr = fetch_result(packet); + if (result_ptr.is_error()) { + return on_error(result_ptr.move_as_error()); + } + + promise_.set_value(std::move(result_ptr.ok_ref()->url_)); + } + + void on_error(Status status) final { + td_->chat_manager_->on_get_channel_error(channel_id_, status, "GetBroadcastRevenueWithdrawalUrlQuery"); + promise_.set_error(std::move(status)); + } +}; + class GetBroadcastRevenueTransactionsQuery final : public Td::ResultHandler { Promise> promise_; ChannelId channel_id_; @@ -655,6 +691,42 @@ void StatisticsManager::get_channel_revenue_statistics( td_->create_handler(std::move(promise))->send(dialog_id.get_channel_id(), is_dark); } +void StatisticsManager::get_channel_revenue_withdrawal_url(DialogId dialog_id, const string &password, + Promise &&promise) { + if (!td_->dialog_manager_->have_dialog_force(dialog_id, "get_channel_revenue_withdrawal_url")) { + return promise.set_error(Status::Error(400, "Chat not found")); + } + if (!td_->dialog_manager_->is_broadcast_channel(dialog_id)) { + return promise.set_error(Status::Error(400, "Chat is not a channel")); + } + auto channel_id = dialog_id.get_channel_id(); + if (!td_->chat_manager_->get_channel_permissions(channel_id).is_creator()) { + return promise.set_error(Status::Error(400, "Not enough rights to withdraw revenue")); + } + if (password.empty()) { + return promise.set_error(Status::Error(400, "PASSWORD_HASH_INVALID")); + } + send_closure( + td_->password_manager_, &PasswordManager::get_input_check_password_srp, password, + PromiseCreator::lambda([actor_id = actor_id(this), channel_id, promise = std::move(promise)]( + Result> result) mutable { + if (result.is_error()) { + return promise.set_error(result.move_as_error()); + } + send_closure(actor_id, &StatisticsManager::send_get_channel_revenue_withdrawal_url_query, channel_id, + result.move_as_ok(), std::move(promise)); + })); +} + +void StatisticsManager::send_get_channel_revenue_withdrawal_url_query( + ChannelId channel_id, telegram_api::object_ptr input_check_password, + Promise &&promise) { + TRY_STATUS_PROMISE(promise, G()->close_status()); + + td_->create_handler(std::move(promise)) + ->send(channel_id, std::move(input_check_password)); +} + void StatisticsManager::get_channel_revenue_transactions( DialogId dialog_id, int32 offset, int32 limit, Promise> &&promise) { diff --git a/td/telegram/StatisticsManager.h b/td/telegram/StatisticsManager.h index 6e04f170f..3c2d11962 100644 --- a/td/telegram/StatisticsManager.h +++ b/td/telegram/StatisticsManager.h @@ -33,6 +33,8 @@ class StatisticsManager final : public Actor { void get_channel_revenue_statistics(DialogId dialog_id, bool is_dark, Promise> &&promise); + void get_channel_revenue_withdrawal_url(DialogId dialog_id, const string &password, Promise &&promise); + void get_channel_revenue_transactions(DialogId dialog_id, int32 offset, int32 limit, Promise> &&promise); @@ -79,6 +81,10 @@ class StatisticsManager final : public Actor { void send_get_story_public_forwards_query(DcId dc_id, StoryFullId story_full_id, string offset, int32 limit, Promise> &&promise); + void send_get_channel_revenue_withdrawal_url_query( + ChannelId channel_id, telegram_api::object_ptr input_check_password, + Promise &&promise); + Td *td_; ActorShared<> parent_; }; diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index 330e44fb4..0f41e93a9 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -8548,6 +8548,20 @@ void Td::on_request(uint64 id, const td_api::getChatRevenueStatistics &request) statistics_manager_->get_channel_revenue_statistics(DialogId(request.chat_id_), request.is_dark_, std::move(promise)); } +void Td::on_request(uint64 id, const td_api::getChatRevenueWithdrawalUrl &request) { + CHECK_IS_USER(); + CREATE_REQUEST_PROMISE(); + auto query_promise = PromiseCreator::lambda([promise = std::move(promise)](Result result) mutable { + if (result.is_error()) { + promise.set_error(result.move_as_error()); + } else { + promise.set_value(td_api::make_object(result.move_as_ok())); + } + }); + statistics_manager_->get_channel_revenue_withdrawal_url(DialogId(request.chat_id_), request.password_, + std::move(query_promise)); +} + void Td::on_request(uint64 id, const td_api::getChatRevenueTransactions &request) { CHECK_IS_USER(); CREATE_REQUEST_PROMISE(); diff --git a/td/telegram/Td.h b/td/telegram/Td.h index 8ea187ff3..c60cd5be9 100644 --- a/td/telegram/Td.h +++ b/td/telegram/Td.h @@ -1615,6 +1615,8 @@ class Td final : public Actor { void on_request(uint64 id, const td_api::getChatRevenueStatistics &request); + void on_request(uint64 id, const td_api::getChatRevenueWithdrawalUrl &request); + void on_request(uint64 id, const td_api::getChatRevenueTransactions &request); void on_request(uint64 id, const td_api::getMessageStatistics &request); diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index 076763578..523f9df5c 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -6469,6 +6469,11 @@ class CliClient final : public Actor { bool is_dark; get_args(args, chat_id, is_dark); send_request(td_api::make_object(chat_id, is_dark)); + } else if (op == "gcrwu") { + ChatId chat_id; + string password; + get_args(args, chat_id, password); + send_request(td_api::make_object(chat_id, password)); } else if (op == "gcrt") { ChatId chat_id; int32 offset;