mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Keep reaction media in memory.
This commit is contained in:
parent
f98c08f4c6
commit
c2c7a25487
3 changed files with 13 additions and 1 deletions
|
@ -231,15 +231,22 @@ void Reactions::request() {
|
||||||
_hash = data.vhash().v;
|
_hash = data.vhash().v;
|
||||||
|
|
||||||
const auto &list = data.vreactions().v;
|
const auto &list = data.vreactions().v;
|
||||||
|
const auto oldCache = base::take(_iconsCache);
|
||||||
_active.clear();
|
_active.clear();
|
||||||
_available.clear();
|
_available.clear();
|
||||||
_active.reserve(list.size());
|
_active.reserve(list.size());
|
||||||
_available.reserve(list.size());
|
_available.reserve(list.size());
|
||||||
|
_iconsCache.reserve(list.size() * 2);
|
||||||
|
const auto toCache = [&](not_null<DocumentData*> document) {
|
||||||
|
_iconsCache.emplace(document, document->createMediaView());
|
||||||
|
};
|
||||||
for (const auto &reaction : list) {
|
for (const auto &reaction : list) {
|
||||||
if (const auto parsed = parse(reaction)) {
|
if (const auto parsed = parse(reaction)) {
|
||||||
_available.push_back(*parsed);
|
_available.push_back(*parsed);
|
||||||
if (parsed->active) {
|
if (parsed->active) {
|
||||||
_active.push_back(*parsed);
|
_active.push_back(*parsed);
|
||||||
|
toCache(parsed->appearAnimation);
|
||||||
|
toCache(parsed->selectAnimation);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -97,6 +97,9 @@ private:
|
||||||
|
|
||||||
std::vector<Reaction> _active;
|
std::vector<Reaction> _active;
|
||||||
std::vector<Reaction> _available;
|
std::vector<Reaction> _available;
|
||||||
|
base::flat_map<
|
||||||
|
not_null<DocumentData*>,
|
||||||
|
std::shared_ptr<Data::DocumentMedia>> _iconsCache;
|
||||||
rpl::event_stream<> _updated;
|
rpl::event_stream<> _updated;
|
||||||
|
|
||||||
mtpRequestId _requestId = 0;
|
mtpRequestId _requestId = 0;
|
||||||
|
|
|
@ -550,7 +550,8 @@ void Manager::loadIcons() {
|
||||||
}
|
}
|
||||||
return entry.icon;
|
return entry.icon;
|
||||||
};
|
};
|
||||||
// #TODO reactions rebuild list better
|
const auto selected = _selectedIcon;
|
||||||
|
setSelectedIcon(-1);
|
||||||
_icons.clear();
|
_icons.clear();
|
||||||
auto main = true;
|
auto main = true;
|
||||||
for (const auto &reaction : _list) {
|
for (const auto &reaction : _list) {
|
||||||
|
@ -561,6 +562,7 @@ void Manager::loadIcons() {
|
||||||
});
|
});
|
||||||
main = false;
|
main = false;
|
||||||
}
|
}
|
||||||
|
setSelectedIcon(selected < _icons.size() ? selected : -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Manager::checkIcons() {
|
void Manager::checkIcons() {
|
||||||
|
|
Loading…
Add table
Reference in a new issue