From cc2c3678a9073c8b555cbe5c6ed66a5fcb6ec724 Mon Sep 17 00:00:00 2001 From: levlam Date: Sun, 1 Dec 2024 11:46:45 +0300 Subject: [PATCH] Add affiliate info to relevant Star transactions. --- telegram-bot-api/Client.cpp | 35 +++++++++++++++++++++++++++++++++++ telegram-bot-api/Client.h | 1 + 2 files changed, 36 insertions(+) diff --git a/telegram-bot-api/Client.cpp b/telegram-bot-api/Client.cpp index 641578b..ef3942e 100644 --- a/telegram-bot-api/Client.cpp +++ b/telegram-bot-api/Client.cpp @@ -4230,6 +4230,32 @@ class Client::JsonRevenueWithdrawalState final : public td::Jsonable { const td_api::RevenueWithdrawalState *state_; }; +class Client::JsonAffiliateInfo final : public td::Jsonable { + public: + JsonAffiliateInfo(const td_api::affiliateInfo *affiliate_info, const Client *client) + : affiliate_info_(affiliate_info), client_(client) { + } + void store(td::JsonValueScope *scope) const { + auto object = scope->enter_object(); + auto chat_info = client_->get_chat(affiliate_info_->affiliate_chat_id_); + CHECK(chat_info != nullptr); + if (chat_info->type == ChatInfo::Type::Private) { + object("affiliate_user", JsonUser(chat_info->user_id, client_)); + } else { + object("affiliate_chat", JsonChat(affiliate_info_->affiliate_chat_id_, client_)); + } + object("commission_per_mille", affiliate_info_->commission_per_mille_); + object("amount", affiliate_info_->star_amount_->star_count_); + if (affiliate_info_->star_amount_->nanostar_count_ != 0) { + object("nanostar_amount", affiliate_info_->star_amount_->nanostar_count_); + } + } + + private: + const td_api::affiliateInfo *affiliate_info_; + const Client *client_; +}; + class Client::JsonStarTransactionType final : public td::Jsonable { public: JsonStarTransactionType(const td_api::StarTransactionType *type, const Client *client) @@ -4260,6 +4286,9 @@ class Client::JsonStarTransactionType final : public td::Jsonable { if (!type->payload_.empty()) { object("paid_media_payload", type->payload_); } + if (type->affiliate_ != nullptr) { + object("affiliate", JsonAffiliateInfo(type->affiliate_.get(), client_)); + } break; } case td_api::starTransactionTypeBotInvoiceSale::ID: { @@ -4274,6 +4303,9 @@ class Client::JsonStarTransactionType final : public td::Jsonable { object("invoice_payload", type->invoice_payload_); } } + if (type->affiliate_ != nullptr) { + object("affiliate", JsonAffiliateInfo(type->affiliate_.get(), client_)); + } break; } case td_api::starTransactionTypeBotSubscriptionSale::ID: { @@ -4291,6 +4323,9 @@ class Client::JsonStarTransactionType final : public td::Jsonable { if (type->subscription_period_ > 0) { object("subscription_period", type->subscription_period_); } + if (type->affiliate_ != nullptr) { + object("affiliate", JsonAffiliateInfo(type->affiliate_.get(), client_)); + } break; } case td_api::starTransactionTypeTelegramAdsWithdrawal::ID: diff --git a/telegram-bot-api/Client.h b/telegram-bot-api/Client.h index 6b04b19..bb6ed27 100644 --- a/telegram-bot-api/Client.h +++ b/telegram-bot-api/Client.h @@ -204,6 +204,7 @@ class Client final : public WebhookActor::Callback { class JsonGiveawayCompleted; class JsonChatBoostAdded; class JsonRevenueWithdrawalState; + class JsonAffiliateInfo; class JsonStarTransactionType; class JsonStarTransaction; class JsonStarTransactions;