mirror of https://github.com/procxx/kepka.git
Limit amount of displayed recent stickers.
This commit is contained in:
parent
ee182ea684
commit
c3ff5f2603
|
@ -558,7 +558,8 @@ void FeaturedSetsReceived(const QVector<MTPStickerSetCovered> &data, const QVect
|
||||||
? set->vinstalled_date.v
|
? set->vinstalled_date.v
|
||||||
: TimeId(0);
|
: TimeId(0);
|
||||||
if (it == sets.cend()) {
|
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)) {
|
if (unreadMap.contains(set->vid.v)) {
|
||||||
setClientFlags |= MTPDstickerSet_ClientFlag::f_unread;
|
setClientFlags |= MTPDstickerSet_ClientFlag::f_unread;
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,7 @@ namespace {
|
||||||
|
|
||||||
constexpr auto kInlineItemsMaxPerRow = 5;
|
constexpr auto kInlineItemsMaxPerRow = 5;
|
||||||
constexpr auto kSearchRequestDelay = 400;
|
constexpr auto kSearchRequestDelay = 400;
|
||||||
|
constexpr auto kRecentDisplayLimit = 20;
|
||||||
|
|
||||||
bool SetInMyList(MTPDstickerSet::Flags flags) {
|
bool SetInMyList(MTPDstickerSet::Flags flags) {
|
||||||
return (flags & MTPDstickerSet::Flag::f_installed_date)
|
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();
|
_custom.clear();
|
||||||
clearSelection();
|
auto result = Stickers::Pack();
|
||||||
|
|
||||||
auto &sets = Auth().data().stickerSets();
|
auto &sets = Auth().data().stickerSets();
|
||||||
auto &recent = Stickers::GetRecentPack();
|
auto &recent = Stickers::GetRecentPack();
|
||||||
auto customIt = sets.constFind(Stickers::CustomSetId);
|
auto customIt = sets.constFind(Stickers::CustomSetId);
|
||||||
auto cloudIt = sets.constFind(Stickers::CloudRecentSetId);
|
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;
|
auto add = [&](not_null<DocumentData*> document, bool custom) {
|
||||||
int customCnt = (customIt == sets.cend()) ? 0 : customIt->stickers.size();
|
if (result.size() >= kRecentDisplayLimit) {
|
||||||
int cloudCnt = (cloudIt == sets.cend()) ? 0 : cloudIt->stickers.size();
|
return;
|
||||||
recentPack.reserve(cloudCnt + recent.size() + customCnt);
|
}
|
||||||
_custom.reserve(cloudCnt + recent.size() + customCnt);
|
const auto index = result.indexOf(document);
|
||||||
if (cloudCnt > 0) {
|
if (index >= 0) {
|
||||||
for_const (auto sticker, cloudIt->stickers) {
|
if (index >= cloudCount && custom) {
|
||||||
if (!_favedStickersMap.contains(sticker)) {
|
// Mark stickers from local recent as custom.
|
||||||
recentPack.push_back(sticker);
|
_custom[index] = true;
|
||||||
_custom.push_back(false);
|
|
||||||
}
|
}
|
||||||
|
} 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) {
|
for_const (auto &recentSticker, recent) {
|
||||||
auto sticker = recentSticker.first;
|
add(recentSticker.first, false);
|
||||||
if (!_favedStickersMap.contains(sticker)) {
|
}
|
||||||
recentPack.push_back(sticker);
|
if (customCount > 0) {
|
||||||
_custom.push_back(false);
|
for_const (auto document, customIt->stickers) {
|
||||||
}
|
add(document, true);
|
||||||
}
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
void StickersListWidget::refreshRecentStickers(bool performResize) {
|
||||||
|
clearSelection();
|
||||||
|
|
||||||
|
auto recentPack = collectRecentStickers();
|
||||||
auto recentIt = std::find_if(_mySets.begin(), _mySets.end(), [](auto &set) {
|
auto recentIt = std::find_if(_mySets.begin(), _mySets.end(), [](auto &set) {
|
||||||
return set.id == Stickers::RecentSetId;
|
return set.id == Stickers::RecentSetId;
|
||||||
});
|
});
|
||||||
|
|
|
@ -172,6 +172,7 @@ private:
|
||||||
|
|
||||||
bool setHasTitle(const Set &set) const;
|
bool setHasTitle(const Set &set) const;
|
||||||
bool stickerHasDeleteButton(const Set &set, int index) const;
|
bool stickerHasDeleteButton(const Set &set, int index) const;
|
||||||
|
Stickers::Pack collectRecentStickers();
|
||||||
void refreshRecentStickers(bool resize = true);
|
void refreshRecentStickers(bool resize = true);
|
||||||
void refreshFavedStickers();
|
void refreshFavedStickers();
|
||||||
enum class GroupStickersPlace {
|
enum class GroupStickersPlace {
|
||||||
|
|
Loading…
Reference in New Issue