Keep reaction media in memory.

This commit is contained in:
John Preston 2022-01-07 16:19:43 +03:00
parent f98c08f4c6
commit c2c7a25487
3 changed files with 13 additions and 1 deletions

View file

@ -231,15 +231,22 @@ void Reactions::request() {
_hash = data.vhash().v;
const auto &list = data.vreactions().v;
const auto oldCache = base::take(_iconsCache);
_active.clear();
_available.clear();
_active.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) {
if (const auto parsed = parse(reaction)) {
_available.push_back(*parsed);
if (parsed->active) {
_active.push_back(*parsed);
toCache(parsed->appearAnimation);
toCache(parsed->selectAnimation);
}
}
}

View file

@ -97,6 +97,9 @@ private:
std::vector<Reaction> _active;
std::vector<Reaction> _available;
base::flat_map<
not_null<DocumentData*>,
std::shared_ptr<Data::DocumentMedia>> _iconsCache;
rpl::event_stream<> _updated;
mtpRequestId _requestId = 0;

View file

@ -550,7 +550,8 @@ void Manager::loadIcons() {
}
return entry.icon;
};
// #TODO reactions rebuild list better
const auto selected = _selectedIcon;
setSelectedIcon(-1);
_icons.clear();
auto main = true;
for (const auto &reaction : _list) {
@ -561,6 +562,7 @@ void Manager::loadIcons() {
});
main = false;
}
setSelectedIcon(selected < _icons.size() ? selected : -1);
}
void Manager::checkIcons() {