From 5d349d86e1c6b0414294ef9ae9b622cd69f09be4 Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 9 May 2024 16:54:06 +0300 Subject: [PATCH] Add td_api::updateAvailableMessageEffects. --- td/generate/scheme/td_api.tl | 3 ++ td/telegram/ReactionManager.cpp | 54 +++++++++++++++++++++++++++++++++ td/telegram/ReactionManager.h | 11 +++++++ td/telegram/Td.cpp | 1 - td/telegram/UpdatesManager.cpp | 1 + 5 files changed, 69 insertions(+), 1 deletion(-) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 195f07565..5725b67ae 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -7250,6 +7250,9 @@ 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 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 9dcb7553e..0ec33d80d 100644 --- a/td/telegram/ReactionManager.cpp +++ b/td/telegram/ReactionManager.cpp @@ -475,6 +475,7 @@ void ReactionManager::init() { td_->stickers_manager_->init(); load_active_reactions(); + load_active_message_effects(); if (td_->option_manager_->get_option_boolean("default_reaction_needs_sync")) { send_set_default_reaction_query(); @@ -1228,6 +1229,14 @@ td_api::object_ptr ReactionManager::get_message_effects_ return td_api::make_object(std::move(effects)); } +td_api::object_ptr ReactionManager::get_update_available_message_effects_object() + const { + return td_api::make_object(vector(active_message_effects_)); +} + +void ReactionManager::reload_message_effects() { +} + void ReactionManager::get_message_effects(Promise> &&promise) { auto query_promise = PromiseCreator::lambda( [actor_id = actor_id(this), promise = std::move(promise)]( @@ -1324,6 +1333,8 @@ void ReactionManager::on_get_message_effects( message_effects_.effects_ = std::move(new_effects); message_effects_.hash_ = effects->hash_; + + update_active_message_effects(); break; } default: @@ -1332,6 +1343,46 @@ void ReactionManager::on_get_message_effects( promise.set_value(get_message_effects_object()); } +void ReactionManager::save_active_message_effects() { + LOG(INFO) << "Save " << active_message_effects_.size() << " available message effects"; + G()->td_db()->get_binlog_pmc()->set("active_message_effects", + log_event_store(active_message_effects_).as_slice().str()); +} + +void ReactionManager::load_active_message_effects() { + LOG(INFO) << "Loading active message effects"; + string active_message_effects = G()->td_db()->get_binlog_pmc()->get("active_message_effects"); + if (active_message_effects.empty()) { + return reload_message_effects(); + } + + auto status = log_event_parse(active_message_effects_, active_message_effects); + if (status.is_error()) { + LOG(ERROR) << "Can't load active message effects: " << status; + active_message_effects_ = {}; + return reload_message_effects(); + } + + LOG(INFO) << "Successfully loaded " << active_message_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; + for (auto &effect : message_effects_.effects_) { + active_message_effects.push_back(effect.id_); + } + if (active_message_effects == active_message_effects_) { + return; + } + active_message_effects_ = std::move(active_message_effects); + + save_active_message_effects(); + + send_closure(G()->td(), &Td::send_update, get_update_available_message_effects_object()); +} + void ReactionManager::get_message_effect(int64 effect_id, Promise> &&promise) { /* @@ -1358,6 +1409,9 @@ void ReactionManager::get_current_state(vector &&promise); + void reload_message_effects(); + void get_message_effects(Promise> &&promise); void get_message_effect(int64 effect_id, Promise> &&promise); @@ -265,9 +267,17 @@ class ReactionManager final : public Actor { td_api::object_ptr get_message_effects_object() const; + td_api::object_ptr get_update_available_message_effects_object() const; + void on_get_message_effects(Result> r_effects, Promise> promise); + void save_active_message_effects(); + + void load_active_message_effects(); + + void update_active_message_effects(); + Td *td_; ActorShared<> parent_; @@ -291,6 +301,7 @@ class ReactionManager final : public Actor { pending_get_topic_saved_reaction_tags_queries_; Effects message_effects_; + vector active_message_effects_; }; } // namespace td diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index f3c5b7f71..7ed2a8346 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -3957,7 +3957,6 @@ void Td::send_update(tl_object_ptr &&object) { VLOG(td_requests) << "Sending update: " << to_string(object); } break; - case td_api::updateSpeedLimitNotification::ID: case td_api::updateDefaultReactionType::ID / 2: LOG(ERROR) << "Sending update: " << oneline(to_string(object)); break; diff --git a/td/telegram/UpdatesManager.cpp b/td/telegram/UpdatesManager.cpp index 5b81983f7..ec35337c6 100644 --- a/td/telegram/UpdatesManager.cpp +++ b/td/telegram/UpdatesManager.cpp @@ -2260,6 +2260,7 @@ void UpdatesManager::try_reload_data() { Auto()); td_->quick_reply_manager_->reload_quick_reply_shortcuts(); td_->reaction_manager_->reload_reactions(); + td_->reaction_manager_->reload_message_effects(); for (int32 type = 0; type < MAX_REACTION_LIST_TYPE; type++) { auto reaction_list_type = static_cast(type);