From aa09223b9cc280e9be62416f06932f699d57e228 Mon Sep 17 00:00:00 2001 From: levlam Date: Tue, 14 May 2024 14:04:12 +0300 Subject: [PATCH] Improve updateAvailableMessageEffects. --- td/generate/scheme/td_api.tl | 6 ++++-- td/telegram/ReactionManager.cpp | 23 ++++++++++++++++------- td/telegram/ReactionManager.h | 17 ++++++++++++++++- td/telegram/ReactionManager.hpp | 32 ++++++++++++++++++++++++++++++++ 4 files changed, 68 insertions(+), 10 deletions(-) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 6721b4e36..29550b9f3 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -7266,8 +7266,10 @@ updateWebAppMessageSent web_app_launch_id:int64 = Update; //@description The list of active emoji reactions has changed @emojis The new list of active emoji reactions updateActiveEmojiReactions emojis:vector = Update; -//@description The list of available message effects has changed @effect_ids The new list of available message effects. Emoji reaction effects are guaranteed to be returned before sticker effects -updateAvailableMessageEffects effect_ids:vector = Update; +//@description The list of available message effects has changed +//@reaction_effect_ids The new list of available message effects from emoji reactions +//@sticker_effect_ids The new list of available message effects from Premium stickers +updateAvailableMessageEffects reaction_effect_ids:vector sticker_effect_ids:vector = Update; //@description The type of default reaction has changed @reaction_type The new type of the default reaction updateDefaultReactionType reaction_type:ReactionType = Update; diff --git a/td/telegram/ReactionManager.cpp b/td/telegram/ReactionManager.cpp index a2f9cd0f5..5022358b4 100644 --- a/td/telegram/ReactionManager.cpp +++ b/td/telegram/ReactionManager.cpp @@ -1226,7 +1226,9 @@ td_api::object_ptr ReactionManager::get_message_effect_ob td_api::object_ptr ReactionManager::get_update_available_message_effects_object() const { - return td_api::make_object(vector(active_message_effects_)); + return td_api::make_object( + vector(active_message_effects_.reaction_effects_), + vector(active_message_effects_.sticker_effects_)); } void ReactionManager::reload_message_effects() { @@ -1391,7 +1393,8 @@ void ReactionManager::on_get_message_effects( } void ReactionManager::save_active_message_effects() { - LOG(INFO) << "Save " << active_message_effects_.size() << " available message effects"; + LOG(INFO) << "Save " << active_message_effects_.reaction_effects_.size() << " + " + << active_message_effects_.sticker_effects_.size() << " available message effects"; G()->td_db()->get_binlog_pmc()->set("active_message_effects", log_event_store(active_message_effects_).as_slice().str()); } @@ -1410,17 +1413,23 @@ void ReactionManager::load_active_message_effects() { return reload_message_effects(); } - LOG(INFO) << "Successfully loaded " << active_message_effects_.size() << " active message effects"; + LOG(INFO) << "Successfully loaded " << active_message_effects_.reaction_effects_.size() << " + " + << active_message_effects_.sticker_effects_.size() << " active message effects"; send_closure(G()->td(), &Td::send_update, get_update_available_message_effects_object()); } void ReactionManager::update_active_message_effects() { - vector active_message_effects; + ActiveEffects active_message_effects; for (auto &effect : message_effects_.effects_) { - active_message_effects.push_back(effect.id_); + if (effect.is_sticker()) { + active_message_effects.sticker_effects_.push_back(effect.id_); + } else { + active_message_effects.reaction_effects_.push_back(effect.id_); + } } - if (active_message_effects == active_message_effects_) { + if (active_message_effects.reaction_effects_ == active_message_effects_.reaction_effects_ && + active_message_effects.sticker_effects_ == active_message_effects_.sticker_effects_) { return; } active_message_effects_ = std::move(active_message_effects); @@ -1454,7 +1463,7 @@ void ReactionManager::get_current_state(vector reaction_effects_; + vector sticker_effects_; + + bool is_empty() const { + return reaction_effects_.empty() && sticker_effects_.empty(); + } + + template + void store(StorerT &storer) const; + + template + void parse(ParserT &parser); + }; + td_api::object_ptr get_emoji_reaction_object(const string &emoji) const; ReactionList &get_reaction_list(ReactionListType reaction_list_type); @@ -314,7 +329,7 @@ class ReactionManager final : public Actor { pending_get_topic_saved_reaction_tags_queries_; Effects message_effects_; - vector active_message_effects_; + ActiveEffects active_message_effects_; vector>>> pending_get_message_effect_queries_; }; diff --git a/td/telegram/ReactionManager.hpp b/td/telegram/ReactionManager.hpp index 3214d6862..dc5af6225 100644 --- a/td/telegram/ReactionManager.hpp +++ b/td/telegram/ReactionManager.hpp @@ -185,4 +185,36 @@ void ReactionManager::Effects::parse(ParserT &parser) { } } +template +void ReactionManager::ActiveEffects::store(StorerT &storer) const { + bool has_reaction_effects = !reaction_effects_.empty(); + bool has_sticker_effects = !sticker_effects_.empty(); + BEGIN_STORE_FLAGS(); + STORE_FLAG(has_reaction_effects); + STORE_FLAG(has_sticker_effects); + END_STORE_FLAGS(); + if (has_reaction_effects) { + td::store(reaction_effects_, storer); + } + if (has_sticker_effects) { + td::store(sticker_effects_, storer); + } +} + +template +void ReactionManager::ActiveEffects::parse(ParserT &parser) { + bool has_reaction_effects; + bool has_sticker_effects; + BEGIN_PARSE_FLAGS(); + PARSE_FLAG(has_reaction_effects); + PARSE_FLAG(has_sticker_effects); + END_PARSE_FLAGS(); + if (has_reaction_effects) { + td::parse(reaction_effects_, parser); + } + if (has_sticker_effects) { + td::parse(sticker_effects_, parser); + } +} + } // namespace td