Skip to content

Commit 1782a0a

Browse files
committed
Add td_api::giftBackground.
1 parent 617059b commit 1782a0a

File tree

7 files changed

+146
-27
lines changed

7 files changed

+146
-27
lines changed

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,7 @@ set(TDLIB_SOURCE_PART2
613613
td/telegram/StarGiftAttributeId.cpp
614614
td/telegram/StarGiftAuctionState.cpp
615615
td/telegram/StarGiftAuctionUserState.cpp
616+
td/telegram/StarGiftBackground.cpp
616617
td/telegram/StarGiftCollection.cpp
617618
td/telegram/StarGiftId.cpp
618619
td/telegram/StarGiftManager.cpp
@@ -1018,6 +1019,7 @@ set(TDLIB_SOURCE_PART2
10181019
td/telegram/StarGiftAttributeId.h
10191020
td/telegram/StarGiftAuctionState.h
10201021
td/telegram/StarGiftAuctionUserState.h
1022+
td/telegram/StarGiftBackground.h
10211023
td/telegram/StarGiftCollection.h
10221024
td/telegram/StarGiftCollectionId.h
10231025
td/telegram/StarGiftId.h
@@ -1184,6 +1186,7 @@ set(TDLIB_SOURCE_PART2
11841186
td/telegram/StarAmount.hpp
11851187
td/telegram/StarGift.hpp
11861188
td/telegram/StarGiftAttribute.hpp
1189+
td/telegram/StarGiftBackground.hpp
11871190
td/telegram/StarGiftId.hpp
11881191
td/telegram/StarGiftResalePrice.hpp
11891192
td/telegram/StarGiftSettings.hpp

SplitSource.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,7 @@ function ($matches) use ($needed_std_headers) {
432432
'StarGiftAttributeId' => 'StarGiftAttributeId',
433433
'StarGiftAuctionState' => 'StarGiftAuctionState',
434434
'StarGiftAuctionUserState' => 'StarGiftAuctionUserState',
435+
'StarGiftBackground' => 'StarGiftBackground',
435436
'StarGiftCollectionId' => 'StarGiftCollectionId',
436437
'StarGiftId' => 'StarGiftId',
437438
'star_gift_manager[_(-](?![.]get[(][)])|StarGiftManager' => 'StarGiftManager',

td/generate/scheme/td_api.tl

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1210,6 +1210,12 @@ giftSettings show_gift_button:Bool accepted_gift_types:acceptedGiftTypes = GiftS
12101210
//@gifts_per_round Number of gifts distributed in each round
12111211
giftAuction id:string gifts_per_round:int32 = GiftAuction;
12121212

1213+
//@description Describes background of a gift
1214+
//@center_color Center color in RGB format
1215+
//@edge_color Edge color in RGB format
1216+
//@text_color Text color in RGB format
1217+
giftBackground center_color:int32 edge_color:int32 text_color:int32 = GiftBackground;
1218+
12131219
//@description Describes the maximum number of times that a specific gift can be purchased
12141220
//@total_count The maximum number of times the gifts can be purchased
12151221
//@remaining_count Number of remaining times the gift can be purchased
@@ -3835,11 +3841,9 @@ linkPreviewTypeExternalVideo url:string mime_type:string width:int32 height:int3
38353841

38363842
//@description The link is a link to a gift auction
38373843
//@gift The gift
3844+
//@gift_background Describes background of the gift
38383845
//@auction_end_date Point in time (Unix timestamp) when the auction will be ended
3839-
//@center_color Center color in RGB format
3840-
//@edge_color Edge color in RGB format
3841-
//@text_color Text color in RGB format
3842-
linkPreviewTypeGiftAuction gift:gift auction_end_date:int32 center_color:int32 edge_color:int32 text_color:int32 = LinkPreviewType;
3846+
linkPreviewTypeGiftAuction gift:gift gift_background:giftBackground auction_end_date:int32 = LinkPreviewType;
38433847

38443848
//@description The link is a link to a gift collection @icons Icons for some gifts from the collection; may be empty
38453849
linkPreviewTypeGiftCollection icons:vector<sticker> = LinkPreviewType;

td/telegram/StarGiftBackground.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//
2+
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2025
3+
//
4+
// Distributed under the Boost Software License, Version 1.0. (See accompanying
5+
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6+
//
7+
#include "td/telegram/StarGiftBackground.h"
8+
9+
#include "td/utils/logging.h"
10+
11+
namespace td {
12+
13+
td_api::object_ptr<td_api::giftBackground> StarGiftBackground::get_gift_background_object() const {
14+
return td_api::make_object<td_api::giftBackground>(center_color_, edge_color_, text_color_);
15+
}
16+
17+
bool operator==(const StarGiftBackground &lhs, const StarGiftBackground &rhs) {
18+
return lhs.center_color_ == rhs.center_color_ && lhs.edge_color_ == rhs.edge_color_ &&
19+
lhs.text_color_ == rhs.text_color_;
20+
}
21+
22+
StringBuilder &operator<<(StringBuilder &string_builder, const StarGiftBackground &background) {
23+
return string_builder << "GiftBackground[" << background.center_color_ << '/' << background.edge_color_ << '/'
24+
<< background.text_color_ << ']';
25+
}
26+
27+
} // namespace td

td/telegram/StarGiftBackground.h

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
//
2+
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2025
3+
//
4+
// Distributed under the Boost Software License, Version 1.0. (See accompanying
5+
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6+
//
7+
#pragma once
8+
9+
#include "td/telegram/td_api.h"
10+
11+
#include "td/utils/common.h"
12+
#include "td/utils/StringBuilder.h"
13+
14+
namespace td {
15+
16+
class StarGiftBackground {
17+
int32 center_color_ = 0;
18+
int32 edge_color_ = 0;
19+
int32 text_color_ = 0;
20+
21+
friend bool operator==(const StarGiftBackground &lhs, const StarGiftBackground &rhs);
22+
23+
friend StringBuilder &operator<<(StringBuilder &string_builder, const StarGiftBackground &background);
24+
25+
public:
26+
StarGiftBackground() = default;
27+
28+
StarGiftBackground(int32 center_color, int32 edge_color, int32 text_color)
29+
: center_color_(center_color), edge_color_(edge_color), text_color_(text_color) {
30+
}
31+
32+
td_api::object_ptr<td_api::giftBackground> get_gift_background_object() const;
33+
34+
template <class StorerT>
35+
void store(StorerT &storer) const;
36+
37+
template <class ParserT>
38+
void parse(ParserT &parser);
39+
};
40+
41+
bool operator==(const StarGiftBackground &lhs, const StarGiftBackground &rhs);
42+
43+
inline bool operator!=(const StarGiftBackground &lhs, const StarGiftBackground &rhs) {
44+
return !(lhs == rhs);
45+
}
46+
47+
StringBuilder &operator<<(StringBuilder &string_builder, const StarGiftBackground &background);
48+
49+
} // namespace td

td/telegram/StarGiftBackground.hpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//
2+
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2025
3+
//
4+
// Distributed under the Boost Software License, Version 1.0. (See accompanying
5+
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6+
//
7+
#pragma once
8+
9+
#include "td/telegram/StarGiftBackground.h"
10+
11+
namespace td {
12+
13+
template <class StorerT>
14+
void StarGiftBackground::store(StorerT &storer) const {
15+
BEGIN_STORE_FLAGS();
16+
END_STORE_FLAGS();
17+
td::store(center_color_, storer);
18+
td::store(edge_color_, storer);
19+
td::store(text_color_, storer);
20+
}
21+
22+
template <class ParserT>
23+
void StarGiftBackground::parse(ParserT &parser) {
24+
BEGIN_PARSE_FLAGS();
25+
END_PARSE_FLAGS();
26+
td::parse(center_color_, parser);
27+
td::parse(edge_color_, parser);
28+
td::parse(text_color_, parser);
29+
}
30+
31+
} // namespace td

td/telegram/WebPagesManager.cpp

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
#include "td/telegram/PhotoFormat.h"
3131
#include "td/telegram/QuickReplyManager.h"
3232
#include "td/telegram/StarGift.h"
33+
#include "td/telegram/StarGiftBackground.h"
34+
#include "td/telegram/StarGiftBackground.hpp"
3335
#include "td/telegram/StickerFormat.h"
3436
#include "td/telegram/StickersManager.h"
3537
#include "td/telegram/StickersManager.hpp"
@@ -262,9 +264,7 @@ class WebPagesManager::WebPage {
262264
vector<StarGift> star_gifts_;
263265
WebPageInstantView instant_view_;
264266
int32 auction_end_date_ = 0;
265-
int32 auction_center_color_ = 0;
266-
int32 auction_edge_color_ = 0;
267-
int32 auction_text_color_ = 0;
267+
unique_ptr<StarGiftBackground> gift_background_;
268268

269269
FileSourceId file_source_id_;
270270

@@ -291,8 +291,8 @@ class WebPagesManager::WebPage {
291291
bool has_sticker_ids = !sticker_ids_.empty();
292292
bool has_theme_settings = !theme_settings_.is_empty();
293293
bool has_star_gifts = !star_gifts_.empty();
294-
bool has_auction =
295-
auction_end_date_ != 0 || auction_center_color_ != 0 || auction_edge_color_ != 0 || auction_text_color_ != 0;
294+
bool has_auction_end_date = auction_end_date_ != 0;
295+
bool has_gift_background = gift_background_ != nullptr;
296296
BEGIN_STORE_FLAGS();
297297
STORE_FLAG(has_type);
298298
STORE_FLAG(has_site_name);
@@ -314,7 +314,8 @@ class WebPagesManager::WebPage {
314314
STORE_FLAG(has_theme_settings);
315315
STORE_FLAG(has_star_gifts);
316316
STORE_FLAG(video_cover_photo_);
317-
STORE_FLAG(has_auction);
317+
STORE_FLAG(has_auction_end_date);
318+
STORE_FLAG(has_gift_background);
318319
END_STORE_FLAGS();
319320

320321
store(url_, storer);
@@ -369,11 +370,11 @@ class WebPagesManager::WebPage {
369370
if (has_star_gifts) {
370371
store(star_gifts_, storer);
371372
}
372-
if (has_auction) {
373+
if (has_auction_end_date) {
373374
store(auction_end_date_, storer);
374-
store(auction_center_color_, storer);
375-
store(auction_edge_color_, storer);
376-
store(auction_text_color_, storer);
375+
}
376+
if (has_gift_background) {
377+
store(gift_background_, storer);
377378
}
378379
}
379380

@@ -398,7 +399,8 @@ class WebPagesManager::WebPage {
398399
bool has_sticker_ids;
399400
bool has_theme_settings;
400401
bool has_star_gifts;
401-
bool has_auction;
402+
bool has_auction_end_date;
403+
bool has_gift_background;
402404
BEGIN_PARSE_FLAGS();
403405
PARSE_FLAG(has_type);
404406
PARSE_FLAG(has_site_name);
@@ -420,7 +422,8 @@ class WebPagesManager::WebPage {
420422
PARSE_FLAG(has_theme_settings);
421423
PARSE_FLAG(has_star_gifts);
422424
PARSE_FLAG(video_cover_photo_);
423-
PARSE_FLAG(has_auction);
425+
PARSE_FLAG(has_auction_end_date);
426+
PARSE_FLAG(has_gift_background);
424427
END_PARSE_FLAGS();
425428

426429
parse(url_, parser);
@@ -484,11 +487,11 @@ class WebPagesManager::WebPage {
484487
if (has_star_gifts) {
485488
parse(star_gifts_, parser);
486489
}
487-
if (has_auction) {
490+
if (has_auction_end_date) {
488491
parse(auction_end_date_, parser);
489-
parse(auction_center_color_, parser);
490-
parse(auction_edge_color_, parser);
491-
parse(auction_text_color_, parser);
492+
}
493+
if (has_gift_background) {
494+
parse(gift_background_, parser);
492495
}
493496

494497
if (has_instant_view) {
@@ -509,8 +512,7 @@ class WebPagesManager::WebPage {
509512
lhs.document_ == rhs.document_ && lhs.documents_ == rhs.documents_ &&
510513
lhs.theme_settings_ == rhs.theme_settings_ && lhs.story_full_ids_ == rhs.story_full_ids_ &&
511514
lhs.sticker_ids_ == rhs.sticker_ids_ && lhs.star_gifts_ == rhs.star_gifts_ &&
512-
lhs.auction_end_date_ == rhs.auction_end_date_ && lhs.auction_center_color_ == rhs.auction_center_color_ &&
513-
lhs.auction_edge_color_ == rhs.auction_edge_color_ && lhs.auction_text_color_ == rhs.auction_text_color_ &&
515+
lhs.auction_end_date_ == rhs.auction_end_date_ && lhs.gift_background_ == rhs.gift_background_ &&
514516
lhs.instant_view_.is_empty_ == rhs.instant_view_.is_empty_ &&
515517
lhs.instant_view_.is_v2_ == rhs.instant_view_.is_v2_;
516518
}
@@ -748,9 +750,8 @@ WebPageId WebPagesManager::on_get_web_page(tl_object_ptr<telegram_api::WebPage>
748750
}
749751
page->star_gifts_.push_back(std::move(star_gift));
750752
page->auction_end_date_ = attribute->end_date_;
751-
page->auction_center_color_ = attribute->center_color_;
752-
page->auction_edge_color_ = attribute->edge_color_;
753-
page->auction_text_color_ = attribute->text_color_;
753+
page->gift_background_ = make_unique<StarGiftBackground>(attribute->center_color_, attribute->edge_color_,
754+
attribute->text_color_);
754755
if (page->type_ != "telegram_auction") {
755756
LOG(ERROR) << "Receive webPageAttributeStarGiftAuction for " << page->type_;
756757
}
@@ -1541,9 +1542,12 @@ td_api::object_ptr<td_api::LinkPreviewType> WebPagesManager::get_link_preview_ty
15411542
Slice type = Slice(web_page->type_).substr(9);
15421543
if (type == "auction") {
15431544
if (web_page->star_gifts_.size() == 1) {
1545+
td_api::object_ptr<td_api::giftBackground> background;
1546+
if (web_page->gift_background_ != nullptr) {
1547+
background = web_page->gift_background_->get_gift_background_object();
1548+
}
15441549
return td_api::make_object<td_api::linkPreviewTypeGiftAuction>(
1545-
web_page->star_gifts_[0].get_gift_object(td_), web_page->auction_end_date_, web_page->auction_center_color_,
1546-
web_page->auction_edge_color_, web_page->auction_text_color_);
1550+
web_page->star_gifts_[0].get_gift_object(td_), std::move(background), web_page->auction_end_date_);
15471551
} else {
15481552
LOG(ERROR) << "Receive gift auction " << web_page->url_ << " without the gift";
15491553
need_reload = true;

0 commit comments

Comments
 (0)