From 571f0b445a6319bc31cba6be00fdab4330391521 Mon Sep 17 00:00:00 2001 From: levlam Date: Tue, 7 May 2024 13:45:35 +0300 Subject: [PATCH] Add new revenue amount to updateChatRevenueAmount. --- td/generate/scheme/td_api.tl | 4 +++- td/telegram/StatisticsManager.cpp | 15 +++++++++++++-- td/telegram/StatisticsManager.h | 3 ++- td/telegram/UpdatesManager.cpp | 3 ++- 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 203373fce..c2bb735b3 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -7237,7 +7237,9 @@ updateDefaultReactionType reaction_type:ReactionType = Update; updateSavedMessagesTags saved_messages_topic_id:int53 tags:savedMessagesTags = Update; //@description The revenue earned from sponsored messages in a chat has changed. If chat revenue screen is opened, then getChatRevenueTransactions may be called to fetch new transactions -updateChatRevenueAmount = Update; +//@chat_id Identifier of the chat +//@revenue_amount New amount of earned revenue +updateChatRevenueAmount chat_id:int53 revenue_amount:chatRevenueAmount = Update; //@description The parameters of speech recognition without Telegram Premium subscription has changed //@max_media_duration The maximum allowed duration of media for speech recognition without Telegram Premium subscription, in seconds diff --git a/td/telegram/StatisticsManager.cpp b/td/telegram/StatisticsManager.cpp index 43dc5de7e..012fb4130 100644 --- a/td/telegram/StatisticsManager.cpp +++ b/td/telegram/StatisticsManager.cpp @@ -698,8 +698,19 @@ void StatisticsManager::get_channel_revenue_statistics( } void StatisticsManager::on_update_dialog_revenue_transactions( - telegram_api::object_ptr balances) { - send_closure(G()->td(), &Td::send_update, td_api::make_object()); + DialogId dialog_id, telegram_api::object_ptr balances) { + if (!dialog_id.is_valid()) { + LOG(ERROR) << "Receive updateBroadcastRevenueTransactions in invalid " << dialog_id; + return; + } + if (!td_->messages_manager_->have_dialog(dialog_id)) { + LOG(INFO) << "Ignore unnneeded updateBroadcastRevenueTransactions in " << dialog_id; + return; + } + send_closure(G()->td(), &Td::send_update, + td_api::make_object( + td_->dialog_manager_->get_chat_id_object(dialog_id, "updateChatRevenueAmount"), + convert_broadcast_revenue_balances(std::move(balances)))); } void StatisticsManager::get_channel_revenue_withdrawal_url(DialogId dialog_id, const string &password, diff --git a/td/telegram/StatisticsManager.h b/td/telegram/StatisticsManager.h index 540896ddf..5f2bc24af 100644 --- a/td/telegram/StatisticsManager.h +++ b/td/telegram/StatisticsManager.h @@ -38,7 +38,8 @@ class StatisticsManager final : public Actor { void get_channel_revenue_transactions(DialogId dialog_id, int32 offset, int32 limit, Promise> &&promise); - void on_update_dialog_revenue_transactions(telegram_api::object_ptr balances); + void on_update_dialog_revenue_transactions(DialogId dialog_id, + telegram_api::object_ptr balances); void get_channel_message_statistics(MessageFullId message_full_id, bool is_dark, Promise> &&promise); diff --git a/td/telegram/UpdatesManager.cpp b/td/telegram/UpdatesManager.cpp index b3c781b12..5b81983f7 100644 --- a/td/telegram/UpdatesManager.cpp +++ b/td/telegram/UpdatesManager.cpp @@ -4554,7 +4554,8 @@ void UpdatesManager::on_update(tl_object_ptr update, Promise &&promise) { - td_->statistics_manager_->on_update_dialog_revenue_transactions(std::move(update->balances_)); + td_->statistics_manager_->on_update_dialog_revenue_transactions(DialogId(update->peer_), + std::move(update->balances_)); promise.set_value(Unit()); }