From be6dbefe7cac4e89cd14d9ec99a200cd53271fdc Mon Sep 17 00:00:00 2001 From: John Preston Date: Tue, 15 Jul 2025 18:18:58 +0400 Subject: [PATCH] Show premium badge on gifts. --- Telegram/Resources/langs/lang.strings | 1 + Telegram/SourceFiles/api/api_premium.cpp | 4 ++++ Telegram/SourceFiles/data/data_star_gift.h | 3 +++ .../peer_gifts/info_peer_gifts_common.cpp | 19 ++++++++++++++++++- 4 files changed, 26 insertions(+), 1 deletion(-) diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index 0b988fb211..7ba789dab5 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -3521,6 +3521,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_gift_stars_sold_out" = "sold out"; "lng_gift_stars_resale" = "resale"; "lng_gift_stars_on_sale" = "on sale"; +"lng_gift_stars_premium" = "premium"; "lng_gift_stars_tabs_all" = "All Gifts"; "lng_gift_stars_tabs_my" = "My Gifts"; "lng_gift_stars_tabs_limited" = "Limited"; diff --git a/Telegram/SourceFiles/api/api_premium.cpp b/Telegram/SourceFiles/api/api_premium.cpp index 5065541e27..835f3a1c70 100644 --- a/Telegram/SourceFiles/api/api_premium.cpp +++ b/Telegram/SourceFiles/api/api_premium.cpp @@ -825,8 +825,11 @@ std::optional FromTL( .resellCount = int(data.vavailability_resale().value_or_empty()), .limitedLeft = remaining.value_or_empty(), .limitedCount = total.value_or_empty(), + .perUserTotal = data.vper_user_total().value_or_empty(), + .perUserRemains = data.vper_user_remains().value_or_empty(), .firstSaleDate = data.vfirst_sale_date().value_or_empty(), .lastSaleDate = data.vlast_sale_date().value_or_empty(), + .requirePremium = data.is_require_premium(), .upgradable = data.vupgrade_stars().has_value(), .birthday = data.is_birthday(), .soldOut = data.is_sold_out(), @@ -877,6 +880,7 @@ std::optional FromTL( .releasedBy = releasedBy, .limitedLeft = (total - data.vavailability_issued().v), .limitedCount = total, + .requirePremium = data.is_require_premium(), }; const auto unique = result.unique.get(); for (const auto &attribute : data.vattributes().v) { diff --git a/Telegram/SourceFiles/data/data_star_gift.h b/Telegram/SourceFiles/data/data_star_gift.h index df0aacc953..8b53bd5581 100644 --- a/Telegram/SourceFiles/data/data_star_gift.h +++ b/Telegram/SourceFiles/data/data_star_gift.h @@ -74,8 +74,11 @@ struct StarGift { int resellCount = 0; int limitedLeft = 0; int limitedCount = 0; + int perUserTotal = 0; + int perUserRemains = 0; TimeId firstSaleDate = 0; TimeId lastSaleDate = 0; + bool requirePremium = false; bool upgradable = false; bool birthday = false; bool soldOut = false; diff --git a/Telegram/SourceFiles/info/peer_gifts/info_peer_gifts_common.cpp b/Telegram/SourceFiles/info/peer_gifts/info_peer_gifts_common.cpp index 33e28a9227..da39de9903 100644 --- a/Telegram/SourceFiles/info/peer_gifts/info_peer_gifts_common.cpp +++ b/Telegram/SourceFiles/info/peer_gifts/info_peer_gifts_common.cpp @@ -419,8 +419,11 @@ void GiftButton::paintEvent(QPaintEvent *e) { ? v::get(_descriptor).info.unique.get() : nullptr; const auto onsale = (unique && unique->starsForResale && _small); + const auto requirePremium = v::is(_descriptor) + && !v::get(_descriptor).userpic + && v::get(_descriptor).info.requirePremium; const auto hidden = v::is(_descriptor) - && v::get(_descriptor).hidden;; + && v::get(_descriptor).hidden; const auto extend = currentExtend(); const auto position = QPoint(extend.left(), extend.top()); const auto background = _delegate->background(); @@ -430,6 +433,16 @@ void GiftButton::paintEvent(QPaintEvent *e) { if (unique) { cacheUniqueBackground(unique, width, background.height() / dpr); p.drawImage(extend.left(), extend.top(), _uniqueBackgroundCache); + } else if (requirePremium) { + auto hq = PainterHighQualityEnabler(p); + auto pen = st::creditsFg->p; + pen.setWidth(style::ConvertScaleExact(2.)); + p.setPen(pen); + p.setBrush(Qt::NoBrush); + const auto outer = QRect(0, 0, width, background.height() / dpr); + const auto extend = currentExtend(); + const auto radius = st::giftBoxGiftRadius; + p.drawRoundedRect(outer.marginsRemoved(extend), radius, radius); } if (_userpic) { @@ -526,6 +539,8 @@ void GiftButton::paintEvent(QPaintEvent *e) { ? tr::lng_gift_stars_resale(tr::now) : soldOut ? tr::lng_gift_stars_sold_out(tr::now) + : (!data.userpic && data.info.requirePremium) + ? tr::lng_gift_stars_premium(tr::now) : (!data.userpic && !data.info.unique) ? tr::lng_gift_stars_limited(tr::now) : (count == 1) @@ -544,6 +559,8 @@ void GiftButton::paintEvent(QPaintEvent *e) { ? st::boxTextFgGood->c : soldOut ? st::attentionButtonFg->c + : data.info.requirePremium + ? st::creditsFg->c : st::windowActiveTextFg->c), .bg2 = (onsale ? QColor(0, 0, 0, 0)