Add td_api::getChatRevenueWithdrawalUrl.

This commit is contained in:
levlam 2024-04-05 16:41:35 +03:00
parent baa7fe8598
commit 701011ab86
6 changed files with 108 additions and 3 deletions

View File

@ -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;

View File

@ -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<string> promise_;
ChannelId channel_id_;
public:
explicit GetBroadcastRevenueWithdrawalUrlQuery(Promise<string> &&promise) : promise_(std::move(promise)) {
}
void send(ChannelId channel_id, telegram_api::object_ptr<telegram_api::InputCheckPasswordSRP> 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<telegram_api::stats_getBroadcastRevenueWithdrawalUrl>(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<td_api::object_ptr<td_api::chatRevenueTransactions>> promise_;
ChannelId channel_id_;
@ -655,6 +691,42 @@ void StatisticsManager::get_channel_revenue_statistics(
td_->create_handler<GetBroadcastRevenueStatsQuery>(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<string> &&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<telegram_api::object_ptr<telegram_api::InputCheckPasswordSRP>> 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<telegram_api::InputCheckPasswordSRP> input_check_password,
Promise<string> &&promise) {
TRY_STATUS_PROMISE(promise, G()->close_status());
td_->create_handler<GetBroadcastRevenueWithdrawalUrlQuery>(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<td_api::object_ptr<td_api::chatRevenueTransactions>> &&promise) {

View File

@ -33,6 +33,8 @@ class StatisticsManager final : public Actor {
void get_channel_revenue_statistics(DialogId dialog_id, bool is_dark,
Promise<td_api::object_ptr<td_api::chatRevenueStatistics>> &&promise);
void get_channel_revenue_withdrawal_url(DialogId dialog_id, const string &password, Promise<string> &&promise);
void get_channel_revenue_transactions(DialogId dialog_id, int32 offset, int32 limit,
Promise<td_api::object_ptr<td_api::chatRevenueTransactions>> &&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<td_api::object_ptr<td_api::publicForwards>> &&promise);
void send_get_channel_revenue_withdrawal_url_query(
ChannelId channel_id, telegram_api::object_ptr<telegram_api::InputCheckPasswordSRP> input_check_password,
Promise<string> &&promise);
Td *td_;
ActorShared<> parent_;
};

View File

@ -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<string> result) mutable {
if (result.is_error()) {
promise.set_error(result.move_as_error());
} else {
promise.set_value(td_api::make_object<td_api::httpUrl>(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();

View File

@ -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);

View File

@ -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<td_api::getChatRevenueStatistics>(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<td_api::getChatRevenueWithdrawalUrl>(chat_id, password));
} else if (op == "gcrt") {
ChatId chat_id;
int32 offset;