diff --git a/Telegram/SourceFiles/chat_helpers/stickers.cpp b/Telegram/SourceFiles/chat_helpers/stickers.cpp index 62761ddb29..f4833bc09c 100644 --- a/Telegram/SourceFiles/chat_helpers/stickers.cpp +++ b/Telegram/SourceFiles/chat_helpers/stickers.cpp @@ -188,6 +188,25 @@ bool IsFaved(gsl::not_null document) { return (it != Global::StickerSets().cend()) && it->stickers.contains(document); } +void CheckFavedLimit(Set &set) { + if (set.stickers.size() <= Global::StickersFavedLimit()) { + return; + } + auto removing = set.stickers.back(); + set.stickers.pop_back(); + for (auto i = set.emoji.begin(); i != set.emoji.end();) { + auto index = i->indexOf(removing); + if (index >= 0) { + i->removeAt(index); + if (i->empty()) { + i = set.emoji.erase(i); + continue; + } + } + ++i; + } +} + void SetIsFaved(gsl::not_null document, const std::vector> *emojiList = nullptr) { auto &sets = Global::RefStickerSets(); auto it = sets.find(FavedSetId); @@ -252,6 +271,7 @@ void SetIsFaved(gsl::not_null document, const std::vectoremoji[emoji].push_front(document); } + CheckFavedLimit(*it); } Local::writeFavedStickers(); Auth().data().stickersUpdated().notify(true);