From cdf36cc3873e97ddf80fec8f8632912ce774c903 Mon Sep 17 00:00:00 2001 From: John Preston Date: Sat, 15 Jan 2022 12:38:47 +0300 Subject: [PATCH] Fix reaction animations stopping after an hour uptime. --- .../data/data_message_reactions.cpp | 66 ++++++++++--------- .../SourceFiles/data/data_message_reactions.h | 1 + 2 files changed, 36 insertions(+), 31 deletions(-) diff --git a/Telegram/SourceFiles/data/data_message_reactions.cpp b/Telegram/SourceFiles/data/data_message_reactions.cpp index 12718cd28d..a349841259 100644 --- a/Telegram/SourceFiles/data/data_message_reactions.cpp +++ b/Telegram/SourceFiles/data/data_message_reactions.cpp @@ -279,38 +279,8 @@ void Reactions::request() { MTP_int(_hash) )).done([=](const MTPmessages_AvailableReactions &result) { _requestId = 0; - const auto oldCache = base::take(_iconsCache); - const auto toCache = [&](DocumentData *document) { - if (document) { - _iconsCache.emplace(document, document->createMediaView()); - } - }; result.match([&](const MTPDmessages_availableReactions &data) { - _hash = data.vhash().v; - - const auto &list = data.vreactions().v; - _active.clear(); - _available.clear(); - _active.reserve(list.size()); - _available.reserve(list.size()); - _iconsCache.reserve(list.size() * 2); - 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); - toCache(parsed->centerIcon); - toCache(parsed->aroundAnimation); - } - } - } - if (_waitingForList) { - _waitingForList = false; - resolveImages(); - } - _updated.fire({}); + updateFromData(data); }, [&](const MTPDmessages_availableReactionsNotModified &) { }); }).fail([=] { @@ -319,6 +289,40 @@ void Reactions::request() { }).send(); } +void Reactions::updateFromData(const MTPDmessages_availableReactions &data) { + _hash = data.vhash().v; + + const auto &list = data.vreactions().v; + const auto oldCache = base::take(_iconsCache); + const auto toCache = [&](DocumentData *document) { + if (document) { + _iconsCache.emplace(document, document->createMediaView()); + } + }; + _active.clear(); + _available.clear(); + _active.reserve(list.size()); + _available.reserve(list.size()); + _iconsCache.reserve(list.size() * 4); + 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); + toCache(parsed->centerIcon); + toCache(parsed->aroundAnimation); + } + } + } + if (_waitingForList) { + _waitingForList = false; + resolveImages(); + } + _updated.fire({}); +} + std::optional Reactions::parse(const MTPAvailableReaction &entry) { return entry.match([&](const MTPDavailableReaction &data) { const auto emoji = qs(data.vreaction()); diff --git a/Telegram/SourceFiles/data/data_message_reactions.h b/Telegram/SourceFiles/data/data_message_reactions.h index add18375f1..79626eddcf 100644 --- a/Telegram/SourceFiles/data/data_message_reactions.h +++ b/Telegram/SourceFiles/data/data_message_reactions.h @@ -78,6 +78,7 @@ private: }; void request(); + void updateFromData(const MTPDmessages_availableReactions &data); [[nodiscard]] std::optional parse( const MTPAvailableReaction &entry);