2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-29 13:39:06 +00:00

Show premium badge on gifts.

This commit is contained in:
John Preston 2025-07-15 18:18:58 +04:00
parent f655297052
commit be6dbefe7c
4 changed files with 26 additions and 1 deletions

View File

@ -3521,6 +3521,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_gift_stars_sold_out" = "sold out"; "lng_gift_stars_sold_out" = "sold out";
"lng_gift_stars_resale" = "resale"; "lng_gift_stars_resale" = "resale";
"lng_gift_stars_on_sale" = "on sale"; "lng_gift_stars_on_sale" = "on sale";
"lng_gift_stars_premium" = "premium";
"lng_gift_stars_tabs_all" = "All Gifts"; "lng_gift_stars_tabs_all" = "All Gifts";
"lng_gift_stars_tabs_my" = "My Gifts"; "lng_gift_stars_tabs_my" = "My Gifts";
"lng_gift_stars_tabs_limited" = "Limited"; "lng_gift_stars_tabs_limited" = "Limited";

View File

@ -825,8 +825,11 @@ std::optional<Data::StarGift> FromTL(
.resellCount = int(data.vavailability_resale().value_or_empty()), .resellCount = int(data.vavailability_resale().value_or_empty()),
.limitedLeft = remaining.value_or_empty(), .limitedLeft = remaining.value_or_empty(),
.limitedCount = total.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(), .firstSaleDate = data.vfirst_sale_date().value_or_empty(),
.lastSaleDate = data.vlast_sale_date().value_or_empty(), .lastSaleDate = data.vlast_sale_date().value_or_empty(),
.requirePremium = data.is_require_premium(),
.upgradable = data.vupgrade_stars().has_value(), .upgradable = data.vupgrade_stars().has_value(),
.birthday = data.is_birthday(), .birthday = data.is_birthday(),
.soldOut = data.is_sold_out(), .soldOut = data.is_sold_out(),
@ -877,6 +880,7 @@ std::optional<Data::StarGift> FromTL(
.releasedBy = releasedBy, .releasedBy = releasedBy,
.limitedLeft = (total - data.vavailability_issued().v), .limitedLeft = (total - data.vavailability_issued().v),
.limitedCount = total, .limitedCount = total,
.requirePremium = data.is_require_premium(),
}; };
const auto unique = result.unique.get(); const auto unique = result.unique.get();
for (const auto &attribute : data.vattributes().v) { for (const auto &attribute : data.vattributes().v) {

View File

@ -74,8 +74,11 @@ struct StarGift {
int resellCount = 0; int resellCount = 0;
int limitedLeft = 0; int limitedLeft = 0;
int limitedCount = 0; int limitedCount = 0;
int perUserTotal = 0;
int perUserRemains = 0;
TimeId firstSaleDate = 0; TimeId firstSaleDate = 0;
TimeId lastSaleDate = 0; TimeId lastSaleDate = 0;
bool requirePremium = false;
bool upgradable = false; bool upgradable = false;
bool birthday = false; bool birthday = false;
bool soldOut = false; bool soldOut = false;

View File

@ -419,8 +419,11 @@ void GiftButton::paintEvent(QPaintEvent *e) {
? v::get<GiftTypeStars>(_descriptor).info.unique.get() ? v::get<GiftTypeStars>(_descriptor).info.unique.get()
: nullptr; : nullptr;
const auto onsale = (unique && unique->starsForResale && _small); const auto onsale = (unique && unique->starsForResale && _small);
const auto requirePremium = v::is<GiftTypeStars>(_descriptor)
&& !v::get<GiftTypeStars>(_descriptor).userpic
&& v::get<GiftTypeStars>(_descriptor).info.requirePremium;
const auto hidden = v::is<GiftTypeStars>(_descriptor) const auto hidden = v::is<GiftTypeStars>(_descriptor)
&& v::get<GiftTypeStars>(_descriptor).hidden;; && v::get<GiftTypeStars>(_descriptor).hidden;
const auto extend = currentExtend(); const auto extend = currentExtend();
const auto position = QPoint(extend.left(), extend.top()); const auto position = QPoint(extend.left(), extend.top());
const auto background = _delegate->background(); const auto background = _delegate->background();
@ -430,6 +433,16 @@ void GiftButton::paintEvent(QPaintEvent *e) {
if (unique) { if (unique) {
cacheUniqueBackground(unique, width, background.height() / dpr); cacheUniqueBackground(unique, width, background.height() / dpr);
p.drawImage(extend.left(), extend.top(), _uniqueBackgroundCache); 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) { if (_userpic) {
@ -526,6 +539,8 @@ void GiftButton::paintEvent(QPaintEvent *e) {
? tr::lng_gift_stars_resale(tr::now) ? tr::lng_gift_stars_resale(tr::now)
: soldOut : soldOut
? tr::lng_gift_stars_sold_out(tr::now) ? 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) : (!data.userpic && !data.info.unique)
? tr::lng_gift_stars_limited(tr::now) ? tr::lng_gift_stars_limited(tr::now)
: (count == 1) : (count == 1)
@ -544,6 +559,8 @@ void GiftButton::paintEvent(QPaintEvent *e) {
? st::boxTextFgGood->c ? st::boxTextFgGood->c
: soldOut : soldOut
? st::attentionButtonFg->c ? st::attentionButtonFg->c
: data.info.requirePremium
? st::creditsFg->c
: st::windowActiveTextFg->c), : st::windowActiveTextFg->c),
.bg2 = (onsale .bg2 = (onsale
? QColor(0, 0, 0, 0) ? QColor(0, 0, 0, 0)