Show correct presents in Stars gifts.

This commit is contained in:
John Preston 2024-07-25 10:30:39 +02:00
parent a5ffd8b7cf
commit 992c876930
3 changed files with 13 additions and 1 deletions

View file

@ -22,6 +22,16 @@ GiftBoxPack::GiftBoxPack(not_null<Main::Session*> session)
GiftBoxPack::~GiftBoxPack() = default;
int GiftBoxPack::monthsForStars(int stars) const {
if (stars <= 1000) {
return 3;
} else if (stars < 2500) {
return 6;
} else {
return 12;
}
}
DocumentData *GiftBoxPack::lookup(int months) const {
const auto it = ranges::lower_bound(_localMonths, months);
const auto fallback = _documents.empty() ? nullptr : _documents[0];

View file

@ -25,6 +25,7 @@ public:
~GiftBoxPack();
void load();
[[nodiscard]] int monthsForStars(int stars) const;
[[nodiscard]] DocumentData *lookup(int months) const;
[[nodiscard]] Data::FileOrigin origin() const;

View file

@ -185,8 +185,9 @@ void PremiumGift::ensureStickerCreated() const {
return;
}
const auto &session = _parent->history()->session();
const auto months = stars() ? 1 : _data.count;
auto &packs = session.giftBoxStickersPacks();
const auto count = stars();
const auto months = count ? packs.monthsForStars(count) : _data.count;
if (const auto document = packs.lookup(months)) {
if (const auto sticker = document->sticker()) {
const auto skipPremiumEffect = false;