aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorlevlam <levlam@telegram.org>2025-09-25 01:53:23 +0300
committerlevlam <levlam@telegram.org>2025-09-25 01:53:23 +0300
commitea39d7af6b8de324bb1af7e631669e6a2a98c815 (patch)
tree13fd69b5cd41ebe2d5e358dd48e854ef22d6d218
parent3dba688ffaf0501f05fba45e1089507d7290aa03 (diff)
Add td_api::upgradedGiftColors.
-rw-r--r--CMakeLists.txt3
-rw-r--r--SplitSource.php2
-rw-r--r--td/generate/scheme/td_api.tl10
-rw-r--r--td/telegram/PeerColor.cpp6
-rw-r--r--td/telegram/PeerColorCollectible.cpp71
-rw-r--r--td/telegram/PeerColorCollectible.h56
-rw-r--r--td/telegram/PeerColorCollectible.hpp63
7 files changed, 210 insertions, 1 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index c3eab3d5a..aacf2a33b 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -554,6 +554,7 @@ set(TDLIB_SOURCE_PART2
td/telegram/PasswordManager.cpp
td/telegram/Payments.cpp
td/telegram/PeerColor.cpp
+ td/telegram/PeerColorCollectible.cpp
td/telegram/PeopleNearbyManager.cpp
td/telegram/PhoneNumberManager.cpp
td/telegram/Photo.cpp
@@ -936,6 +937,7 @@ set(TDLIB_SOURCE_PART2
td/telegram/PasswordManager.h
td/telegram/Payments.h
td/telegram/PeerColor.h
+ td/telegram/PeerColorCollectible.h
td/telegram/PeopleNearbyManager.h
td/telegram/PhoneNumberManager.h
td/telegram/Photo.h
@@ -1142,6 +1144,7 @@ set(TDLIB_SOURCE_PART2
td/telegram/NotificationGroupInfo.hpp
td/telegram/OrderInfo.hpp
td/telegram/PaidReactionType.hpp
+ td/telegram/PeerColorCollectible.hpp
td/telegram/Photo.hpp
td/telegram/PhotoSize.hpp
td/telegram/PhotoSizeSource.hpp
diff --git a/SplitSource.php b/SplitSource.php
index 9cbb8a4e6..d3a721a02 100644
--- a/SplitSource.php
+++ b/SplitSource.php
@@ -391,6 +391,8 @@ function split_file($file, $chunks, $undo) {
'option_manager[_(-](?![.]get[(][)])|OptionManager' => 'OptionManager',
'PaidReactionType' => 'PaidReactionType',
'password_manager[_(-](?![.]get[(][)])|PasswordManager' => 'PasswordManager',
+ 'PeerColor[^A-Z]' => 'PeerColor',
+ 'PeerColorCollectible' => 'PeerColorCollectible',
'people_nearby_manager[_(-](?![.]get[(][)])|PeopleNearbyManager' => 'PeopleNearbyManager',
'phone_number_manager[_(-](?![.]get[(][)])|PhoneNumberManager' => 'PhoneNumberManager',
'PhotoSizeSource' => 'PhotoSizeSource',
diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl
index 22752a245..6cb79f955 100644
--- a/td/generate/scheme/td_api.tl
+++ b/td/generate/scheme/td_api.tl
@@ -1285,6 +1285,16 @@ upgradedGiftBackdrop id:int32 name:string colors:upgradedGiftBackdropColors rari
//@date Point in time (Unix timestamp) when the gift was sent
upgradedGiftOriginalDetails sender_id:MessageSender receiver_id:MessageSender text:formattedText date:int32 = UpgradedGiftOriginalDetails;
+//@description Contains information about accent colors for user's name, background of empty chat photo, replies to messages and link previews
+//@id Unique identifier of the upgraded gift colors
+//@model_custom_emoji_id Custom emoji identifier of the model of the upgraded gift
+//@symbol_custom_emoji_id Custom emoji identifier of the symbol of the upgraded gift
+//@light_theme_accent_color Accent color to use in light themes in RGB format
+//@light_theme_colors The list of 1-3 colors in RGB format, describing the accent color, as expected to be shown in light themes
+//@dark_theme_accent_color Accent color to use in dark themes in RGB format
+//@dark_theme_colors The list of 1-3 colors in RGB format, describing the accent color, as expected to be shown in dark themes
+upgradedGiftColors id:int64 model_custom_emoji_id:int64 symbol_custom_emoji_id:int64 light_theme_accent_color:int32 light_theme_colors:vector<int32> dark_theme_accent_color:int32 dark_theme_colors:vector<int32> = UpgradedGiftColors;
+
//@description Describes a gift that can be sent to another user or channel chat
//@id Unique identifier of the gift
//@publisher_chat_id Identifier of the chat that published the gift; 0 if none
diff --git a/td/telegram/PeerColor.cpp b/td/telegram/PeerColor.cpp
index 72b4ea936..212cd6d29 100644
--- a/td/telegram/PeerColor.cpp
+++ b/td/telegram/PeerColor.cpp
@@ -11,7 +11,11 @@
namespace td {
PeerColor::PeerColor(const telegram_api::object_ptr<telegram_api::PeerColor> &peer_color_ptr) {
- if (peer_color_ptr == nullptr || peer_color_ptr->get_id() != telegram_api::peerColor::ID) {
+ if (peer_color_ptr == nullptr) {
+ return;
+ }
+ if (peer_color_ptr->get_id() != telegram_api::peerColor::ID) {
+ LOG(ERROR) << "Receive " << to_string(peer_color_ptr);
return;
}
auto peer_color = static_cast<const telegram_api::peerColor *>(peer_color_ptr.get());
diff --git a/td/telegram/PeerColorCollectible.cpp b/td/telegram/PeerColorCollectible.cpp
new file mode 100644
index 000000000..6c45055d3
--- /dev/null
+++ b/td/telegram/PeerColorCollectible.cpp
@@ -0,0 +1,71 @@
+//
+// 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/PeerColorCollectible.h"
+
+#include "td/utils/logging.h"
+
+namespace td {
+
+PeerColorCollectible::PeerColorCollectible(telegram_api::object_ptr<telegram_api::peerColorCollectible> peer_color) {
+ CHECK(peer_color != nullptr);
+ unique_gift_id_ = peer_color->collectible_id_;
+ gift_custom_emoji_id_ = CustomEmojiId(peer_color->gift_emoji_id_);
+ if (!gift_custom_emoji_id_.is_valid()) {
+ LOG(ERROR) << "Receive " << to_string(peer_color);
+ gift_custom_emoji_id_ = {};
+ }
+ background_custom_emoji_id_ = CustomEmojiId(peer_color->background_emoji_id_);
+ if (!background_custom_emoji_id_.is_valid()) {
+ LOG(ERROR) << "Receive " << to_string(peer_color);
+ background_custom_emoji_id_ = {};
+ }
+ light_accent_color_ = peer_color->accent_color_;
+ light_colors_ = peer_color->colors_;
+ if (light_colors_.size() > 3u) {
+ LOG(ERROR) << "Receive " << to_string(peer_color);
+ light_colors_ = {};
+ }
+ if ((peer_color->flags_ & telegram_api::peerColorCollectible::DARK_ACCENT_COLOR_MASK) != 0) {
+ dark_accent_color_ = peer_color->dark_accent_color_;
+ } else {
+ dark_accent_color_ = light_accent_color_;
+ }
+ if ((peer_color->flags_ & telegram_api::peerColorCollectible::DARK_COLORS_MASK) != 0) {
+ dark_colors_ = peer_color->dark_colors_;
+ if (dark_colors_.size() > 3u) {
+ LOG(ERROR) << "Receive " << to_string(peer_color);
+ dark_colors_ = {};
+ }
+ } else {
+ dark_colors_ = light_colors_;
+ }
+}
+
+unique_ptr<PeerColorCollectible> PeerColorCollectible::get_peer_color_collectible(
+ telegram_api::object_ptr<telegram_api::peerColorCollectible> peer_color) {
+ CHECK(peer_color != nullptr);
+ auto result = make_unique<PeerColorCollectible>(std::move(peer_color));
+ if (!result->is_valid()) {
+ return nullptr;
+ }
+ return result;
+}
+
+td_api::object_ptr<td_api::upgradedGiftColors> PeerColorCollectible::get_upgraded_gift_colors_object() const {
+ return td_api::make_object<td_api::upgradedGiftColors>(
+ unique_gift_id_, gift_custom_emoji_id_.get(), background_custom_emoji_id_.get(), light_accent_color_,
+ vector<int32>(light_colors_), dark_accent_color_, vector<int32>(dark_colors_));
+}
+
+bool operator==(const PeerColorCollectible &lhs, const PeerColorCollectible &rhs) {
+ return lhs.unique_gift_id_ == rhs.unique_gift_id_ && lhs.gift_custom_emoji_id_ == rhs.gift_custom_emoji_id_ &&
+ lhs.background_custom_emoji_id_ == rhs.background_custom_emoji_id_ &&
+ lhs.light_accent_color_ == rhs.light_accent_color_ && lhs.light_colors_ == rhs.light_colors_ &&
+ lhs.dark_accent_color_ == rhs.dark_accent_color_ && lhs.dark_colors_ == rhs.dark_colors_;
+}
+
+} // namespace td
diff --git a/td/telegram/PeerColorCollectible.h b/td/telegram/PeerColorCollectible.h
new file mode 100644
index 000000000..ee6a5d4c7
--- /dev/null
+++ b/td/telegram/PeerColorCollectible.h
@@ -0,0 +1,56 @@
+//
+// 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/AccentColorId.h"
+#include "td/telegram/CustomEmojiId.h"
+#include "td/telegram/td_api.h"
+#include "td/telegram/telegram_api.h"
+
+#include "td/utils/common.h"
+
+namespace td {
+
+class PeerColorCollectible {
+ int64 unique_gift_id_ = 0;
+ CustomEmojiId gift_custom_emoji_id_;
+ CustomEmojiId background_custom_emoji_id_;
+ int32 light_accent_color_;
+ vector<int32> light_colors_;
+ int32 dark_accent_color_;
+ vector<int32> dark_colors_;
+
+ friend bool operator==(const PeerColorCollectible &lhs, const PeerColorCollectible &rhs);
+
+ public:
+ PeerColorCollectible() = default;
+
+ explicit PeerColorCollectible(telegram_api::object_ptr<telegram_api::peerColorCollectible> peer_color);
+
+ static unique_ptr<PeerColorCollectible> get_peer_color_collectible(
+ telegram_api::object_ptr<telegram_api::peerColorCollectible> peer_color);
+
+ bool is_valid() const {
+ return !light_colors_.empty() && !dark_colors_.empty();
+ }
+
+ td_api::object_ptr<td_api::upgradedGiftColors> get_upgraded_gift_colors_object() const;
+
+ template <class StorerT>
+ void store(StorerT &storer) const;
+
+ template <class ParserT>
+ void parse(ParserT &parser);
+};
+
+bool operator==(const PeerColorCollectible &lhs, const PeerColorCollectible &rhs);
+
+inline bool operator!=(const PeerColorCollectible &lhs, const PeerColorCollectible &rhs) {
+ return !(lhs == rhs);
+}
+
+} // namespace td
diff --git a/td/telegram/PeerColorCollectible.hpp b/td/telegram/PeerColorCollectible.hpp
new file mode 100644
index 000000000..eb84f49de
--- /dev/null
+++ b/td/telegram/PeerColorCollectible.hpp
@@ -0,0 +1,63 @@
+//
+// 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/PeerColorCollectible.h"
+
+#include "td/telegram/BackgroundInfo.hpp"
+
+#include "td/utils/tl_helpers.h"
+
+namespace td {
+
+template <class StorerT>
+void PeerColorCollectible::store(StorerT &storer) const {
+ bool has_dark_accent_color = dark_accent_color_ != light_accent_color_;
+ bool has_dark_colors = dark_colors_ != light_colors_;
+ BEGIN_STORE_FLAGS();
+ STORE_FLAG(has_dark_accent_color);
+ STORE_FLAG(has_dark_colors);
+ END_STORE_FLAGS();
+ td::store(unique_gift_id_, storer);
+ td::store(gift_custom_emoji_id_, storer);
+ td::store(background_custom_emoji_id_, storer);
+ td::store(light_accent_color_, storer);
+ td::store(light_colors_, storer);
+ if (has_dark_accent_color) {
+ td::store(dark_accent_color_, storer);
+ }
+ if (has_dark_colors) {
+ td::store(dark_colors_, storer);
+ }
+}
+
+template <class ParserT>
+void PeerColorCollectible::parse(ParserT &parser) {
+ bool has_dark_accent_color;
+ bool has_dark_colors;
+ BEGIN_PARSE_FLAGS();
+ PARSE_FLAG(has_dark_accent_color);
+ PARSE_FLAG(has_dark_colors);
+ END_PARSE_FLAGS();
+ td::parse(unique_gift_id_, parser);
+ td::parse(gift_custom_emoji_id_, parser);
+ td::parse(background_custom_emoji_id_, parser);
+ td::parse(light_accent_color_, parser);
+ td::parse(light_colors_, parser);
+ if (has_dark_accent_color) {
+ td::parse(dark_accent_color_, parser);
+ } else {
+ dark_accent_color_ = light_accent_color_;
+ }
+ if (has_dark_colors) {
+ td::parse(dark_colors_, parser);
+ } else {
+ dark_colors_ = light_colors_;
+ }
+}
+
+} // namespace td