From 070675b4cd75b53674b1cc6460849be2a2690bad Mon Sep 17 00:00:00 2001 From: levlam <levlam@telegram.org> Date: Thu, 25 Jul 2024 20:06:29 +0300 Subject: [PATCH] Add td_api::starSubscription. --- CMakeLists.txt | 2 ++ SplitSource.php | 1 + td/generate/scheme/td_api.tl | 8 ++++++ td/telegram/StarSubscription.cpp | 35 +++++++++++++++++++++++++ td/telegram/StarSubscription.h | 44 ++++++++++++++++++++++++++++++++ 5 files changed, 90 insertions(+) create mode 100644 td/telegram/StarSubscription.cpp create mode 100644 td/telegram/StarSubscription.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 4e49ff05c..93cd5407f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -553,6 +553,7 @@ set(TDLIB_SOURCE_PART2 td/telegram/SpecialStickerSetType.cpp td/telegram/SponsoredMessageManager.cpp td/telegram/StarManager.cpp + td/telegram/StarSubscription.cpp td/telegram/StarSubscriptionPricing.cpp td/telegram/StateManager.cpp td/telegram/StatisticsManager.cpp @@ -897,6 +898,7 @@ set(TDLIB_SOURCE_PART2 td/telegram/SpecialStickerSetType.h td/telegram/SponsoredMessageManager.h td/telegram/StarManager.h + td/telegram/StarSubscription.h td/telegram/StarSubscriptionPricing.h td/telegram/StateManager.h td/telegram/StatisticsManager.h diff --git a/SplitSource.php b/SplitSource.php index 5316c9dc8..1a1b12152 100644 --- a/SplitSource.php +++ b/SplitSource.php @@ -412,6 +412,7 @@ function split_file($file, $chunks, $undo) { 'SharedDialog' => 'SharedDialog', 'sponsored_message_manager[_(-](?![.]get[(][)])|SponsoredMessageManager' => 'SponsoredMessageManager', 'star_manager[_(-](?![.]get[(][)])|StarManager' => 'StarManager', + 'StarSubscription[^P]' => 'StarSubscription', 'StarSubscriptionPricing' => 'StarSubscriptionPricing', 'state_manager[_(-](?![.]get[(][)])|StateManager' => 'StateManager', 'statistics_manager[_(-](?![.]get[(][)])|StatisticsManager' => 'StatisticsManager', diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 3b8a164c2..c9b462537 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -803,6 +803,14 @@ chatAdministratorRights can_manage_chat:Bool can_change_info:Bool can_post_messa //@star_count The amount of Telegram Stars that must be paid for each period starSubscriptionPricing period:int32 star_count:int53 = StarSubscriptionPricing; +//@description Contains information about subscription to a channel chat paid in Telegram Stars +//@id Unique identifier of the subscription +//@chat_id Identifier of the channel chat that is subscribed +//@expiration_date Point in time (Unix timestamp) when the subscription will expire or expired +//@is_canceled True, if the subscription was canceled +//@pricing The subscription plan +starSubscription id:string chat_id:int53 expiration_date:int32 is_canceled:Bool pricing:starSubscriptionPricing = StarSubscription; + //@description Contains information about a product that can be paid with invoice //@title Product title diff --git a/td/telegram/StarSubscription.cpp b/td/telegram/StarSubscription.cpp new file mode 100644 index 000000000..dd4770798 --- /dev/null +++ b/td/telegram/StarSubscription.cpp @@ -0,0 +1,35 @@ +// +// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2024 +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// +#include "td/telegram/StarSubscription.h" + +#include "td/telegram/DialogManager.h" +#include "td/telegram/Td.h" + +namespace td { + +StarSubscription::StarSubscription(telegram_api::object_ptr<telegram_api::starsSubscription> &&subscription) + : id_(std::move(subscription->id_)) + , dialog_id_(subscription->peer_) + , until_date_(subscription->until_date_) + , is_canceled_(subscription->canceled_) + , pricing_(std::move(subscription->pricing_)) { +} + +td_api::object_ptr<td_api::starSubscription> StarSubscription::get_star_subscription_object(Td *td) const { + td->dialog_manager_->force_create_dialog(dialog_id_, "starSubscription", true); + return td_api::make_object<td_api::starSubscription>( + id_, td->dialog_manager_->get_chat_id_object(dialog_id_, "starSubscription"), until_date_, is_canceled_, + pricing_.get_star_subscription_pricing_object()); +} + +StringBuilder &operator<<(StringBuilder &string_builder, const StarSubscription &subscription) { + return string_builder << (subscription.is_canceled_ ? "canceled " : "") << "subscription " << subscription.id_ + << " to " << subscription.dialog_id_ << " until " << subscription.until_date_ << " for " + << subscription.pricing_; +} + +} // namespace td diff --git a/td/telegram/StarSubscription.h b/td/telegram/StarSubscription.h new file mode 100644 index 000000000..1632e5afe --- /dev/null +++ b/td/telegram/StarSubscription.h @@ -0,0 +1,44 @@ +// +// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2024 +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// +#pragma once + +#include "td/telegram/DialogId.h" +#include "td/telegram/StarSubscriptionPricing.h" +#include "td/telegram/td_api.h" +#include "td/telegram/telegram_api.h" + +#include "td/utils/common.h" +#include "td/utils/StringBuilder.h" + +namespace td { + +class Td; + +class StarSubscription { + string id_; + DialogId dialog_id_; + int32 until_date_ = 0; + bool is_canceled_ = false; + StarSubscriptionPricing pricing_; + + friend StringBuilder &operator<<(StringBuilder &string_builder, const StarSubscription &subscription); + + public: + StarSubscription() = default; + + explicit StarSubscription(telegram_api::object_ptr<telegram_api::starsSubscription> &&subscription); + + bool is_valid() const { + return !id_.empty() && dialog_id_.is_valid() && until_date_ >= 0 && !pricing_.is_empty(); + } + + td_api::object_ptr<td_api::starSubscription> get_star_subscription_object(Td *td) const; +}; + +StringBuilder &operator<<(StringBuilder &string_builder, const StarSubscription &subscription); + +} // namespace td