From f702cad110dc5f4081946fdb8a7d806f4a868822 Mon Sep 17 00:00:00 2001 From: levlam Date: Fri, 4 Nov 2022 00:59:45 +0300 Subject: [PATCH] Wait for emoji reactions to be loaded once in getEmojiReaction. --- td/telegram/StickersManager.cpp | 13 +++++++++++++ td/telegram/StickersManager.h | 2 ++ 2 files changed, 15 insertions(+) diff --git a/td/telegram/StickersManager.cpp b/td/telegram/StickersManager.cpp index 8953aaebf..93fbc6f2d 100644 --- a/td/telegram/StickersManager.cpp +++ b/td/telegram/StickersManager.cpp @@ -55,6 +55,7 @@ #include "td/utils/misc.h" #include "td/utils/PathView.h" #include "td/utils/Random.h" +#include "td/utils/ScopeGuard.h" #include "td/utils/Slice.h" #include "td/utils/SliceBuilder.h" #include "td/utils/StackAllocator.h" @@ -1580,6 +1581,10 @@ td_api::object_ptr StickersManager::get_emoji_reaction_ob void StickersManager::get_emoji_reaction(const string &emoji, Promise> &&promise) { load_reactions(); + if (reactions_.reactions_.empty() && reactions_.are_being_reloaded_) { + pending_get_emoji_reaction_queries_.emplace_back(emoji, std::move(promise)); + return; + } promise.set_value(get_emoji_reaction_object(emoji)); } @@ -4004,6 +4009,14 @@ void StickersManager::on_get_available_reactions( CHECK(reactions_.are_being_reloaded_); reactions_.are_being_reloaded_ = false; + auto get_emoji_reaction_queries = std::move(pending_get_emoji_reaction_queries_); + pending_get_emoji_reaction_queries_.clear(); + SCOPE_EXIT { + for (auto &query : get_emoji_reaction_queries) { + query.second.set_value(get_emoji_reaction_object(query.first)); + } + }; + if (available_reactions_ptr == nullptr) { // failed to get available reactions return; diff --git a/td/telegram/StickersManager.h b/td/telegram/StickersManager.h index f666fe735..8ad65608f 100644 --- a/td/telegram/StickersManager.h +++ b/td/telegram/StickersManager.h @@ -1052,6 +1052,8 @@ class StickersManager final : public Actor { vector> pending_get_default_statuses_queries_; vector> pending_get_default_topic_icons_queries_; + vector>>> pending_get_emoji_reaction_queries_; + double next_click_animated_emoji_message_time_ = 0; double next_update_animated_emoji_clicked_time_ = 0; vector pending_get_animated_emoji_click_stickers_;