aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorlevlam <levlam@telegram.org>2025-11-28 18:04:54 +0300
committerlevlam <levlam@telegram.org>2025-11-28 18:04:54 +0300
commitf9d0b63e067782a21b71520bb154f6e5208de2ab (patch)
tree55ce02e7f1e8fc1a30e2406080af455d64712438
parentd58b043a5fb5eccd6756c7cab6ce94273ea8ecf4 (diff)
Add td_api::AuctionState.
-rw-r--r--CMakeLists.txt2
-rw-r--r--SplitSource.php1
-rw-r--r--td/generate/scheme/td_api.tl21
-rw-r--r--td/telegram/AuctionBidLevel.cpp9
-rw-r--r--td/telegram/AuctionBidLevel.h5
-rw-r--r--td/telegram/StarGiftAuctionState.cpp94
-rw-r--r--td/telegram/StarGiftAuctionState.h50
7 files changed, 180 insertions, 2 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index e8c9386e1..4c903461f 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -611,6 +611,7 @@ set(TDLIB_SOURCE_PART2
td/telegram/StarGift.cpp
td/telegram/StarGiftAttribute.cpp
td/telegram/StarGiftAttributeId.cpp
+ td/telegram/StarGiftAuctionState.cpp
td/telegram/StarGiftCollection.cpp
td/telegram/StarGiftId.cpp
td/telegram/StarGiftManager.cpp
@@ -1014,6 +1015,7 @@ set(TDLIB_SOURCE_PART2
td/telegram/StarGift.h
td/telegram/StarGiftAttribute.h
td/telegram/StarGiftAttributeId.h
+ td/telegram/StarGiftAuctionState.h
td/telegram/StarGiftCollection.h
td/telegram/StarGiftCollectionId.h
td/telegram/StarGiftId.h
diff --git a/SplitSource.php b/SplitSource.php
index 601d7d8bd..e291a8509 100644
--- a/SplitSource.php
+++ b/SplitSource.php
@@ -430,6 +430,7 @@ function split_file($file, $chunks, $undo) {
'StarGift[^A-Z]' => 'StarGift',
'StarGiftAttribute[^I]' => 'StarGiftAttribute',
'StarGiftAttributeId' => 'StarGiftAttributeId',
+ 'StarGiftAuctionState' => 'StarGiftAuctionState',
'StarGiftCollectionId' => 'StarGiftCollectionId',
'StarGiftId' => 'StarGiftId',
'star_gift_manager[_(-](?![.]get[(][)])|StarGiftManager' => 'StarGiftManager',
diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl
index dca38cd9f..22b14773a 100644
--- a/td/generate/scheme/td_api.tl
+++ b/td/generate/scheme/td_api.tl
@@ -1503,6 +1503,27 @@ giftUpgradePreview models:vector<upgradedGiftModel> symbols:vector<upgradedGiftS
auctionBid star_count:int53 bid_date:int32 position:int32 = AuctionBid;
+//@class AuctionState @description Describes state of an auction
+
+//@description Contains information about an ongoing auction
+//@start_date Point in time (Unix timestamp) when the auction started
+//@end_date Point in time (Unix timestamp) when the auction will be ended
+//@min_bid The minimum possible bid in the auction in Telegram Stars
+//@bid_levels A sparse list of bids that were made in the auction
+//@top_bidder_user_ids User identifiers of at most 3 users with the biggest bids
+//@current_round_end_date Point in time (Unix timestamp) when the current round will end
+//@current_round_number 1-based number of the current round
+//@total_round_count The total number of rounds
+//@left_item_count The number of items that have to be distributed on the auciton
+auctionStateActive start_date:int32 end_date:int32 min_bid:int53 bid_levels:vector<auctionBid> top_bidder_user_ids:vector<int53> current_round_end_date:int32 current_round_number:int32 total_round_count:int32 left_item_count:int32 = AuctionState;
+
+//@description Contains information about a finished auction
+//@start_date Point in time (Unix timestamp) when the auction started
+//@end_date Point in time (Unix timestamp) when the auction will be ended
+//@average_price Average price of bought items in Telegram Stars
+auctionStateFinished start_date:int32 end_date:int32 average_price:int53 = AuctionState;
+
+
//@class TransactionDirection @description Describes direction of transactions in a transaction list
//@description The transaction is incoming and increases the amount of owned currency
diff --git a/td/telegram/AuctionBidLevel.cpp b/td/telegram/AuctionBidLevel.cpp
index 3d5065c97..80414b234 100644
--- a/td/telegram/AuctionBidLevel.cpp
+++ b/td/telegram/AuctionBidLevel.cpp
@@ -8,6 +8,8 @@
#include "td/telegram/StarManager.h"
+#include "td/utils/logging.h"
+
namespace td {
AuctionBidLevel::AuctionBidLevel(const telegram_api::object_ptr<telegram_api::auctionBidLevel> &bid_level)
@@ -39,7 +41,12 @@ td_api::object_ptr<td_api::auctionBid> AuctionBidLevel::get_auction_bid_object()
}
bool operator<(const AuctionBidLevel &lhs, const AuctionBidLevel &rhs) {
- return lhs.star_count_ > rhs.star_count_ || (lhs.star_count_ == rhs.star_count_ && lhs.date_ < rhs.date_);
+ return lhs.position_ < rhs.position_ &&
+ (lhs.star_count_ > rhs.star_count_ || (lhs.star_count_ == rhs.star_count_ && lhs.date_ <= rhs.date_));
+}
+
+bool operator==(const AuctionBidLevel &lhs, const AuctionBidLevel &rhs) {
+ return lhs.position_ == rhs.position_ && lhs.star_count_ == rhs.star_count_ && lhs.date_ == rhs.date_;
}
StringBuilder &operator<<(StringBuilder &string_builder, const AuctionBidLevel &bid_level) {
diff --git a/td/telegram/AuctionBidLevel.h b/td/telegram/AuctionBidLevel.h
index e16e18ff5..f9b3c11c2 100644
--- a/td/telegram/AuctionBidLevel.h
+++ b/td/telegram/AuctionBidLevel.h
@@ -10,7 +10,6 @@
#include "td/telegram/telegram_api.h"
#include "td/utils/common.h"
-#include "td/utils/Status.h"
#include "td/utils/StringBuilder.h"
namespace td {
@@ -22,6 +21,8 @@ class AuctionBidLevel {
friend bool operator<(const AuctionBidLevel &lhs, const AuctionBidLevel &rhs);
+ friend bool operator==(const AuctionBidLevel &lhs, const AuctionBidLevel &rhs);
+
friend StringBuilder &operator<<(StringBuilder &string_builder, const AuctionBidLevel &bid_level);
public:
@@ -35,6 +36,8 @@ class AuctionBidLevel {
bool operator<(const AuctionBidLevel &lhs, const AuctionBidLevel &rhs);
+bool operator==(const AuctionBidLevel &lhs, const AuctionBidLevel &rhs);
+
StringBuilder &operator<<(StringBuilder &string_builder, const AuctionBidLevel &bid_level);
} // namespace td
diff --git a/td/telegram/StarGiftAuctionState.cpp b/td/telegram/StarGiftAuctionState.cpp
new file mode 100644
index 000000000..5d240cd72
--- /dev/null
+++ b/td/telegram/StarGiftAuctionState.cpp
@@ -0,0 +1,94 @@
+//
+// 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/StarGiftAuctionState.h"
+
+#include "td/telegram/StarManager.h"
+#include "td/telegram/Td.h"
+#include "td/telegram/UserManager.h"
+
+#include "td/utils/algorithm.h"
+#include "td/utils/logging.h"
+
+namespace td {
+
+StarGiftAuctionState::StarGiftAuctionState(telegram_api::object_ptr<telegram_api::StarGiftAuctionState> &state_ptr) {
+ CHECK(state_ptr != nullptr);
+ switch (state_ptr->get_id()) {
+ case telegram_api::starGiftAuctionState::ID: {
+ auto state = telegram_api::move_object_as<telegram_api::starGiftAuctionState>(state_ptr);
+ is_active_ = true;
+ start_date_ = state->start_date_;
+ end_date_ = state->end_date_;
+ version_ = state->version_;
+ min_bid_amount_ = StarManager::get_star_count(state->min_bid_amount_);
+ bid_levels_ = AuctionBidLevel::get_auction_bid_levels(state->bid_levels_);
+ for (auto &top_bidder : state->top_bidders_) {
+ UserId top_bidder_user_id(top_bidder);
+ if (!top_bidder_user_id.is_valid()) {
+ LOG(ERROR) << "Receive " << top_bidder_user_id;
+ } else {
+ top_bidder_user_ids_.push_back(top_bidder_user_id);
+ }
+ }
+ const size_t MAX_BIDDER_COUNT = 3u;
+ if (top_bidder_user_ids_.size() > MAX_BIDDER_COUNT) {
+ LOG(ERROR) << "Receive " << top_bidder_user_ids_;
+ top_bidder_user_ids_.resize(MAX_BIDDER_COUNT);
+ }
+ next_round_at_ = state->next_round_at_;
+ gifts_left_ = state->gifts_left_;
+ current_round_ = state->current_round_;
+ total_rounds_ = state->total_rounds_;
+ if (total_rounds_ <= 0) {
+ LOG(ERROR) << "Receive total " << total_rounds_ << " rounds";
+ total_rounds_ = 1;
+ }
+ if (current_round_ <= 0 || current_round_ > total_rounds_) {
+ LOG(ERROR) << "Receive round " << current_round_ << " out of " << total_rounds_ << " rounds";
+ current_round_ = clamp(current_round_, 1, total_rounds_);
+ }
+ break;
+ }
+ case telegram_api::starGiftAuctionStateFinished::ID: {
+ auto state = telegram_api::move_object_as<telegram_api::starGiftAuctionStateFinished>(state_ptr);
+ is_active_ = false;
+ start_date_ = state->start_date_;
+ end_date_ = state->end_date_;
+ average_price_ = StarManager::get_star_count(state->average_price_);
+ break;
+ }
+ default:
+ UNREACHABLE();
+ }
+}
+
+td_api::object_ptr<td_api::AuctionState> StarGiftAuctionState::get_auction_state_object(
+ Td *td, const StarGiftAuctionUserState &user_state) const {
+ if (is_active_) {
+ auto bid_levels =
+ transform(bid_levels_, [](const AuctionBidLevel &level) { return level.get_auction_bid_object(); });
+ auto top_bidder_user_ids = transform(top_bidder_user_ids_, [td](UserId user_id) {
+ return td->user_manager_->get_user_id_object(user_id, "auctionStateActive");
+ });
+ return td_api::make_object<td_api::auctionStateActive>(start_date_, end_date_, min_bid_amount_,
+ std::move(bid_levels), std::move(top_bidder_user_ids),
+ next_round_at_, current_round_, total_rounds_, gifts_left_);
+ } else {
+ return td_api::make_object<td_api::auctionStateFinished>(start_date_, end_date_, average_price_);
+ }
+}
+
+bool operator==(const StarGiftAuctionState &lhs, const StarGiftAuctionState &rhs) {
+ return lhs.is_active_ == rhs.is_active_ && lhs.start_date_ == rhs.start_date_ && lhs.end_date_ == rhs.end_date_ &&
+ lhs.version_ == rhs.version_ && lhs.min_bid_amount_ == rhs.min_bid_amount_ &&
+ lhs.bid_levels_ == rhs.bid_levels_ && lhs.top_bidder_user_ids_ == rhs.top_bidder_user_ids_ &&
+ lhs.next_round_at_ == rhs.next_round_at_ && lhs.gifts_left_ == rhs.gifts_left_ &&
+ lhs.current_round_ == rhs.current_round_ && lhs.total_rounds_ == rhs.total_rounds_ &&
+ lhs.average_price_ == rhs.average_price_;
+}
+
+} // namespace td
diff --git a/td/telegram/StarGiftAuctionState.h b/td/telegram/StarGiftAuctionState.h
new file mode 100644
index 000000000..add047db3
--- /dev/null
+++ b/td/telegram/StarGiftAuctionState.h
@@ -0,0 +1,50 @@
+//
+// 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/AuctionBidLevel.h"
+#include "td/telegram/td_api.h"
+#include "td/telegram/telegram_api.h"
+#include "td/telegram/UserId.h"
+
+#include "td/utils/common.h"
+
+namespace td {
+
+class StarGiftAuctionUserState;
+class Td;
+
+class StarGiftAuctionState {
+ bool is_active_ = false;
+ int32 start_date_ = 0;
+ int32 end_date_ = 0;
+
+ // active
+ int32 version_ = 0;
+ int64 min_bid_amount_ = 0;
+ vector<AuctionBidLevel> bid_levels_;
+ vector<UserId> top_bidder_user_ids_;
+ int32 next_round_at_ = 0;
+ int32 gifts_left_ = 0;
+ int32 current_round_ = 0;
+ int32 total_rounds_ = 0;
+
+ // finished
+ int64 average_price_ = 0;
+
+ friend bool operator==(const StarGiftAuctionState &lhs, const StarGiftAuctionState &rhs);
+
+ public:
+ explicit StarGiftAuctionState(telegram_api::object_ptr<telegram_api::StarGiftAuctionState> &state_ptr);
+
+ td_api::object_ptr<td_api::AuctionState> get_auction_state_object(Td *td,
+ const StarGiftAuctionUserState &user_state) const;
+};
+
+bool operator==(const StarGiftAuctionState &lhs, const StarGiftAuctionState &rhs);
+
+} // namespace td