diff options
| -rw-r--r-- | CMakeLists.txt | 3 | ||||
| -rw-r--r-- | SplitSource.php | 1 | ||||
| -rw-r--r-- | td/telegram/SuggestedPostPrice.cpp | 81 | ||||
| -rw-r--r-- | td/telegram/SuggestedPostPrice.h | 46 | ||||
| -rw-r--r-- | td/telegram/SuggestedPostPrice.hpp | 39 |
5 files changed, 170 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index b93f34358..87821a1c5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -625,6 +625,7 @@ set(TDLIB_SOURCE_PART2 td/telegram/StoryViewer.cpp td/telegram/SuggestedAction.cpp td/telegram/SuggestedActionManager.cpp + td/telegram/SuggestedPostPrice.cpp td/telegram/Support.cpp td/telegram/SynchronousRequests.cpp td/telegram/TargetDialogTypes.cpp @@ -1013,6 +1014,7 @@ set(TDLIB_SOURCE_PART2 td/telegram/StoryViewer.h td/telegram/SuggestedAction.h td/telegram/SuggestedActionManager.h + td/telegram/SuggestedPostPrice.h td/telegram/Support.h td/telegram/SynchronousRequests.h td/telegram/TargetDialogTypes.h @@ -1144,6 +1146,7 @@ set(TDLIB_SOURCE_PART2 td/telegram/StoryInteractionInfo.hpp td/telegram/StoryStealthMode.hpp td/telegram/SuggestedAction.hpp + td/telegram/SuggestedPostPrice.hpp td/telegram/TermsOfService.hpp td/telegram/ThemeSettings.hpp td/telegram/ToDoCompletion.hpp diff --git a/SplitSource.php b/SplitSource.php index 2d01ff04f..35d076e02 100644 --- a/SplitSource.php +++ b/SplitSource.php @@ -446,6 +446,7 @@ function split_file($file, $chunks, $undo) { 'story_manager[_(-](?![.]get[(][)])|StoryManager' => 'StoryManager', 'SuggestedAction|[a-z_]*_suggested_action' => 'SuggestedAction', 'suggested_action_manager[_(-](?![.]get[(][)])|SuggestedActionManager' => 'SuggestedActionManager', + 'SuggestedPostPrice' => 'SuggestedPostPrice', 'SynchronousRequests' => 'SynchronousRequests', 'TargetDialogTypes' => 'TargetDialogTypes', 'td_api' => 'td_api', diff --git a/td/telegram/SuggestedPostPrice.cpp b/td/telegram/SuggestedPostPrice.cpp new file mode 100644 index 000000000..89d911351 --- /dev/null +++ b/td/telegram/SuggestedPostPrice.cpp @@ -0,0 +1,81 @@ +// +// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2025 +// +// 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/SuggestedPostPrice.h" + +#include "td/telegram/StarAmount.h" +#include "td/telegram/TonAmount.h" + +#include "td/utils/logging.h" + +namespace td { + +SuggestedPostPrice::SuggestedPostPrice(telegram_api::object_ptr<telegram_api::StarsAmount> &&amount_ptr) { + if (amount_ptr == nullptr) { + return; + } + switch (amount_ptr->get_id()) { + case telegram_api::starsAmount::ID: { + auto star_amount = StarAmount(telegram_api::move_object_as<telegram_api::starsAmount>(amount_ptr), false); + if (star_amount.get_nanostar_count() != 0) { + LOG(ERROR) << "Receive suggested post price of " << star_amount << " Telegram Stars"; + } + type_ = Type::Star; + amount_ = star_amount.get_star_count(); + break; + } + case telegram_api::starsTonAmount::ID: { + auto ton_amount = + TonAmount(telegram_api::move_object_as<telegram_api::starsTonAmount>(amount_ptr), false).get_ton_amount(); + if (ton_amount % TON_MULTIPLIER != 0) { + LOG(ERROR) << "Receive suggested post price of " << ton_amount << " TONs"; + } + type_ = Type::Ton; + amount_ = ton_amount / TON_MULTIPLIER; + break; + } + default: + UNREACHABLE(); + } +} + +telegram_api::object_ptr<telegram_api::StarsAmount> SuggestedPostPrice::get_input_stars_amount() const { + switch (type_) { + case Type::None: + return nullptr; + case Type::Star: + return telegram_api::make_object<telegram_api::starsAmount>(amount_, 0); + case Type::Ton: + return telegram_api::make_object<telegram_api::starsTonAmount>(amount_ * TON_MULTIPLIER); + default: + UNREACHABLE(); + return nullptr; + } +} + +bool operator==(const SuggestedPostPrice &lhs, const SuggestedPostPrice &rhs) { + return lhs.type_ == rhs.type_ && lhs.amount_ == rhs.amount_; +} + +bool operator!=(const SuggestedPostPrice &lhs, const SuggestedPostPrice &rhs) { + return !(lhs == rhs); +} + +StringBuilder &operator<<(StringBuilder &string_builder, const SuggestedPostPrice &amount) { + switch (amount.type_) { + case SuggestedPostPrice::Type::None: + return string_builder << "[Free]"; + case SuggestedPostPrice::Type::Star: + return string_builder << '[' << amount.amount_ << " Stars]"; + case SuggestedPostPrice::Type::Ton: + return string_builder << '[' << amount.amount_ << " toncoin cents]"; + default: + UNREACHABLE(); + return string_builder; + } +} + +} // namespace td diff --git a/td/telegram/SuggestedPostPrice.h b/td/telegram/SuggestedPostPrice.h new file mode 100644 index 000000000..1abefe08b --- /dev/null +++ b/td/telegram/SuggestedPostPrice.h @@ -0,0 +1,46 @@ +// +// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2025 +// +// 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/telegram_api.h" + +#include "td/utils/common.h" +#include "td/utils/StringBuilder.h" + +namespace td { + +class SuggestedPostPrice { + enum class Type : int32 { None, Star, Ton }; + Type type_ = Type::None; + int64 amount_ = 0; + + static constexpr int64 TON_MULTIPLIER = 10000000; + + friend bool operator==(const SuggestedPostPrice &lhs, const SuggestedPostPrice &rhs); + + friend StringBuilder &operator<<(StringBuilder &string_builder, const SuggestedPostPrice &amount); + + public: + SuggestedPostPrice() = default; + + explicit SuggestedPostPrice(telegram_api::object_ptr<telegram_api::StarsAmount> &&amount_ptr); + + telegram_api::object_ptr<telegram_api::StarsAmount> get_input_stars_amount() const; + + template <class StorerT> + void store(StorerT &storer) const; + + template <class ParserT> + void parse(ParserT &parser); +}; + +bool operator==(const SuggestedPostPrice &lhs, const SuggestedPostPrice &rhs); +bool operator!=(const SuggestedPostPrice &lhs, const SuggestedPostPrice &rhs); + +StringBuilder &operator<<(StringBuilder &string_builder, const SuggestedPostPrice &amount); + +} // namespace td diff --git a/td/telegram/SuggestedPostPrice.hpp b/td/telegram/SuggestedPostPrice.hpp new file mode 100644 index 000000000..cba403912 --- /dev/null +++ b/td/telegram/SuggestedPostPrice.hpp @@ -0,0 +1,39 @@ +// +// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2025 +// +// 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/SuggestedPostPrice.h" + +#include "td/utils/tl_helpers.h" + +namespace td { + +template <class StorerT> +void SuggestedPostPrice::store(StorerT &storer) const { + bool has_amount = amount_ != 0; + BEGIN_STORE_FLAGS(); + STORE_FLAG(has_amount); + END_STORE_FLAGS(); + store(type_, storer); + if (has_amount) { + store(amount_, storer); + } +} + +template <class ParserT> +void SuggestedPostPrice::parse(ParserT &parser) { + bool has_amount; + BEGIN_PARSE_FLAGS(); + PARSE_FLAG(has_amount); + END_PARSE_FLAGS(); + parse(type_, parser); + if (has_amount) { + parse(amount_, parser); + } +} + +} // namespace td |
