diff --git a/Telegram/SourceFiles/chat_helpers/stickers.cpp b/Telegram/SourceFiles/chat_helpers/stickers.cpp index db43d6db2..9db1abdec 100644 --- a/Telegram/SourceFiles/chat_helpers/stickers.cpp +++ b/Telegram/SourceFiles/chat_helpers/stickers.cpp @@ -558,7 +558,8 @@ void FeaturedSetsReceived(const QVector &data, const QVect ? set->vinstalled_date.v : TimeId(0); if (it == sets.cend()) { - auto setClientFlags = MTPDstickerSet_ClientFlag::f_featured | MTPDstickerSet_ClientFlag::f_not_loaded; + auto setClientFlags = MTPDstickerSet_ClientFlag::f_featured + | MTPDstickerSet_ClientFlag::f_not_loaded; if (unreadMap.contains(set->vid.v)) { setClientFlags |= MTPDstickerSet_ClientFlag::f_unread; } diff --git a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp index 66ed895b8..357cc8a61 100644 --- a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp +++ b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp @@ -32,6 +32,7 @@ namespace { constexpr auto kInlineItemsMaxPerRow = 5; constexpr auto kSearchRequestDelay = 400; +constexpr auto kRecentDisplayLimit = 20; bool SetInMyList(MTPDstickerSet::Flags flags) { return (flags & MTPDstickerSet::Flag::f_installed_date) @@ -1796,45 +1797,59 @@ void StickersListWidget::refreshRecent() { } } -void StickersListWidget::refreshRecentStickers(bool performResize) { +Stickers::Pack StickersListWidget::collectRecentStickers() { _custom.clear(); - clearSelection(); + auto result = Stickers::Pack(); + auto &sets = Auth().data().stickerSets(); auto &recent = Stickers::GetRecentPack(); auto customIt = sets.constFind(Stickers::CustomSetId); auto cloudIt = sets.constFind(Stickers::CloudRecentSetId); + const auto customCount = (customIt != sets.cend()) + ? customIt->stickers.size() + : 0; + const auto cloudCount = (cloudIt != sets.cend()) + ? cloudIt->stickers.size() + : 0; + result.reserve(cloudCount + recent.size() + customCount); + _custom.reserve(cloudCount + recent.size() + customCount); - Stickers::Pack recentPack; - int customCnt = (customIt == sets.cend()) ? 0 : customIt->stickers.size(); - int cloudCnt = (cloudIt == sets.cend()) ? 0 : cloudIt->stickers.size(); - recentPack.reserve(cloudCnt + recent.size() + customCnt); - _custom.reserve(cloudCnt + recent.size() + customCnt); - if (cloudCnt > 0) { - for_const (auto sticker, cloudIt->stickers) { - if (!_favedStickersMap.contains(sticker)) { - recentPack.push_back(sticker); - _custom.push_back(false); + auto add = [&](not_null document, bool custom) { + if (result.size() >= kRecentDisplayLimit) { + return; + } + const auto index = result.indexOf(document); + if (index >= 0) { + if (index >= cloudCount && custom) { + // Mark stickers from local recent as custom. + _custom[index] = true; } + } else if (!_favedStickersMap.contains(document)) { + result.push_back(document); + _custom.push_back(custom); + } + }; + + if (cloudCount > 0) { + for_const (auto document, cloudIt->stickers) { + add(document, false); } } for_const (auto &recentSticker, recent) { - auto sticker = recentSticker.first; - if (!_favedStickersMap.contains(sticker)) { - recentPack.push_back(sticker); - _custom.push_back(false); - } - } - if (customCnt > 0) { - for_const (auto &sticker, customIt->stickers) { - auto index = recentPack.indexOf(sticker); - if (index >= cloudCnt) { - _custom[index] = true; // mark stickers from recent as custom - } else if (!_favedStickersMap.contains(sticker)) { - recentPack.push_back(sticker); - _custom.push_back(true); - } + add(recentSticker.first, false); + } + if (customCount > 0) { + for_const (auto document, customIt->stickers) { + add(document, true); } } + return result; +} + +void StickersListWidget::refreshRecentStickers(bool performResize) { + clearSelection(); + + auto recentPack = collectRecentStickers(); auto recentIt = std::find_if(_mySets.begin(), _mySets.end(), [](auto &set) { return set.id == Stickers::RecentSetId; }); diff --git a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.h b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.h index 400d359e8..ed494be87 100644 --- a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.h +++ b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.h @@ -172,6 +172,7 @@ private: bool setHasTitle(const Set &set) const; bool stickerHasDeleteButton(const Set &set, int index) const; + Stickers::Pack collectRecentStickers(); void refreshRecentStickers(bool resize = true); void refreshFavedStickers(); enum class GroupStickersPlace {