From c2c7a25487a919f084e047aa9c8c5caca1cf9a48 Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 7 Jan 2022 16:19:43 +0300 Subject: [PATCH] Keep reaction media in memory. --- Telegram/SourceFiles/data/data_message_reactions.cpp | 7 +++++++ Telegram/SourceFiles/data/data_message_reactions.h | 3 +++ .../SourceFiles/history/view/history_view_react_button.cpp | 4 +++- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/Telegram/SourceFiles/data/data_message_reactions.cpp b/Telegram/SourceFiles/data/data_message_reactions.cpp index c1b041fb4..715643db5 100644 --- a/Telegram/SourceFiles/data/data_message_reactions.cpp +++ b/Telegram/SourceFiles/data/data_message_reactions.cpp @@ -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 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); } } } diff --git a/Telegram/SourceFiles/data/data_message_reactions.h b/Telegram/SourceFiles/data/data_message_reactions.h index cfa284bd1..d52146441 100644 --- a/Telegram/SourceFiles/data/data_message_reactions.h +++ b/Telegram/SourceFiles/data/data_message_reactions.h @@ -97,6 +97,9 @@ private: std::vector _active; std::vector _available; + base::flat_map< + not_null, + std::shared_ptr> _iconsCache; rpl::event_stream<> _updated; mtpRequestId _requestId = 0; diff --git a/Telegram/SourceFiles/history/view/history_view_react_button.cpp b/Telegram/SourceFiles/history/view/history_view_react_button.cpp index 8744d0554..5eecb615d 100644 --- a/Telegram/SourceFiles/history/view/history_view_react_button.cpp +++ b/Telegram/SourceFiles/history/view/history_view_react_button.cpp @@ -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() {