Show "N left" badge on limited gifts.

This commit is contained in:
John Preston
2025-09-11 16:38:35 +04:00
parent e327e1bc9c
commit 5ec277b2ed
4 changed files with 28 additions and 5 deletions
+3
View File
@@ -3589,6 +3589,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_gift_stars_resale" = "resale";
"lng_gift_stars_on_sale" = "on sale";
"lng_gift_stars_premium" = "premium";
"lng_gift_stars_your_left#one" = "{count} left";
"lng_gift_stars_your_left#other" = "{count} left";
"lng_gift_stars_your_finished" = "none left";
"lng_gift_stars_tabs_all" = "All Gifts";
"lng_gift_stars_tabs_my" = "My Gifts";
"lng_gift_stars_tabs_limited" = "Limited";
+5 -3
View File
@@ -2738,6 +2738,10 @@ void SendGiftBox(
auto result = object_ptr<WidgetWithRange>((QWidget*)nullptr);
const auto raw = result.data();
Data::AmPremiumValue(&window->session()) | rpl::start_with_next([=] {
raw->update();
}, raw->lifetime());
struct State {
Delegate delegate;
std::vector<int> order;
@@ -2816,9 +2820,7 @@ void SendGiftBox(
}
}
if (!button) {
button = std::make_unique<GiftButton>(
raw,
&state->delegate);
button = std::make_unique<GiftButton>(raw, &state->delegate);
}
const auto raw = button.get();
if (validated[index]) {
@@ -634,6 +634,14 @@ void GiftButton::paintEvent(QPaintEvent *e) {
&& !unique
&& !data.userpic
&& !data.info.limitedLeft;
const auto yourLeft = data.info.perUserTotal
? (data.info.perUserRemains
? tr::lng_gift_stars_your_left(
tr::now,
lt_count,
data.info.perUserRemains)
: tr::lng_gift_stars_your_finished(tr::now))
: QString();
return GiftBadge{
.text = (onsale
? tr::lng_gift_stars_on_sale(tr::now)
@@ -646,9 +654,13 @@ void GiftButton::paintEvent(QPaintEvent *e) {
: (!data.userpic
&& !data.info.unique
&& data.info.requirePremium)
? tr::lng_gift_stars_premium(tr::now)
? ((yourLeft.isEmpty() || !_delegate->amPremium())
? tr::lng_gift_stars_premium(tr::now)
: yourLeft)
: (!data.userpic && !data.info.unique)
? tr::lng_gift_stars_limited(tr::now)
? (yourLeft.isEmpty()
? tr::lng_gift_stars_limited(tr::now)
: yourLeft)
: (count == 1)
? tr::lng_gift_limited_of_one(tr::now)
: tr::lng_gift_limited_of_count(
@@ -944,6 +956,10 @@ QImage Delegate::cachedBadge(const GiftBadge &badge) {
return image;
}
bool Delegate::amPremium() {
return _session->premium();
}
DocumentData *LookupGiftSticker(
not_null<Main::Session*> session,
const GiftDescriptor &descriptor) {
@@ -147,6 +147,7 @@ public:
const GiftDescriptor &descriptor) = 0;
[[nodiscard]] virtual not_null<StickerPremiumMark*> hiddenMark() = 0;
[[nodiscard]] virtual QImage cachedBadge(const GiftBadge &badge) = 0;
[[nodiscard]] virtual bool amPremium() = 0;
};
class GiftButton final : public Ui::AbstractButton {
@@ -244,6 +245,7 @@ public:
const GiftDescriptor &descriptor) override;
not_null<StickerPremiumMark*> hiddenMark() override;
QImage cachedBadge(const GiftBadge &badge) override;
bool amPremium() override;
private:
const not_null<Main::Session*> _session;