From b7189556f82df3258e10aa81c82aa49e8b7cbe7c Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Fri, 15 Jul 2022 18:56:50 +0300 Subject: [PATCH] Respected order from special pack for premium gifts. --- .../chat_helpers/stickers_gift_box_pack.cpp | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/Telegram/SourceFiles/chat_helpers/stickers_gift_box_pack.cpp b/Telegram/SourceFiles/chat_helpers/stickers_gift_box_pack.cpp index 5bfa80acb..8b1c206d5 100644 --- a/Telegram/SourceFiles/chat_helpers/stickers_gift_box_pack.cpp +++ b/Telegram/SourceFiles/chat_helpers/stickers_gift_box_pack.cpp @@ -16,15 +16,16 @@ namespace Stickers { GiftBoxPack::GiftBoxPack(not_null session) : _session(session) -, _localMonths({ 3, 6, 12 }) { +, _localMonths({ 1, 3, 6, 12, 24 }) { } GiftBoxPack::~GiftBoxPack() = default; DocumentData *GiftBoxPack::lookup(int months) const { const auto it = ranges::lower_bound(_localMonths, months); + const auto fallback = _documents.empty() ? nullptr : _documents[0]; if (it == begin(_localMonths)) { - return _documents.empty() ? nullptr : _documents[0]; + return fallback; } const auto left = *(it - 1); const auto right = *it; @@ -32,7 +33,7 @@ DocumentData *GiftBoxPack::lookup(int months) const { ? -1 : 0; const auto index = int(std::distance(begin(_localMonths), it - shift)); - return (index >= _documents.size()) ? nullptr : _documents[index]; + return (index >= _documents.size()) ? fallback : _documents[index]; } void GiftBoxPack::load() { @@ -70,7 +71,19 @@ void GiftBoxPack::applySet(const MTPDmessages_stickerSet &data) { } for (const auto &id : data.vdocuments().v) { if (const auto document = documents.take(id.v)) { - _documents.push_back(*document); + if (const auto sticker = (*document)->sticker()) { + if (!sticker->alt.isEmpty()) { + const auto ch = int(sticker->alt[0].unicode()); + const auto index = (ch - '1'); // [0, 4]; + if (index < 0 || index >= _localMonths.size()) { + return; + } + if (_documents.empty()) { + _documents.resize(_localMonths.size()); + } + _documents[index] = (*document); + } + } } } });