From facb8f754aaea124411600ee86de0c8229f781a7 Mon Sep 17 00:00:00 2001 From: levlam Date: Wed, 19 Jan 2022 18:59:48 +0300 Subject: [PATCH] Move list of active reactions to MessagesManager. --- td/telegram/DialogEventLog.cpp | 9 ++------- td/telegram/MessageContent.cpp | 8 -------- td/telegram/MessageContent.h | 4 ---- td/telegram/MessagesManager.cpp | 21 ++++++++++++++++----- td/telegram/MessagesManager.h | 6 ++++++ td/telegram/OptionManager.cpp | 5 +++-- td/telegram/StickersManager.cpp | 16 +++++++++------- td/telegram/StickersManager.h | 5 +---- 8 files changed, 37 insertions(+), 37 deletions(-) diff --git a/td/telegram/DialogEventLog.cpp b/td/telegram/DialogEventLog.cpp index 802a92e23..3c573849c 100644 --- a/td/telegram/DialogEventLog.cpp +++ b/td/telegram/DialogEventLog.cpp @@ -342,13 +342,8 @@ static td_api::object_ptr get_chat_event_action_object( } case telegram_api::channelAdminLogEventActionChangeAvailableReactions::ID: { auto action = move_tl_object_as(action_ptr); - auto old_value = td->stickers_manager_->get_active_reactions(std::move(action->prev_value_)); - auto new_value = td->stickers_manager_->get_active_reactions(std::move(action->new_value_)); - if (old_value == new_value) { - return nullptr; - } - return td_api::make_object(std::move(old_value), - std::move(new_value)); + return td_api::make_object(std::move(action->prev_value_), + std::move(action->new_value_)); } default: UNREACHABLE(); diff --git a/td/telegram/MessageContent.cpp b/td/telegram/MessageContent.cpp index 471fce1ea..93b488947 100644 --- a/td/telegram/MessageContent.cpp +++ b/td/telegram/MessageContent.cpp @@ -5649,14 +5649,6 @@ bool is_unsent_animated_emoji_click(Td *td, DialogId dialog_id, const DialogActi return !td->stickers_manager_->is_sent_animated_emoji_click(dialog_id, remove_emoji_modifiers(emoji)); } -vector get_all_active_reactions(Td *td) { - return td->stickers_manager_->get_all_active_reactions(); -} - -vector get_active_reactions(Td *td, const vector &available_reactions) { - return td->stickers_manager_->get_active_reactions(available_reactions); -} - void on_dialog_used(TopDialogCategory category, DialogId dialog_id, int32 date) { send_closure(G()->top_dialog_manager(), &TopDialogManager::on_dialog_used, category, dialog_id, date); } diff --git a/td/telegram/MessageContent.h b/td/telegram/MessageContent.h index bb284cd0f..b74177e9d 100644 --- a/td/telegram/MessageContent.h +++ b/td/telegram/MessageContent.h @@ -248,10 +248,6 @@ void on_sent_message_content(Td *td, const MessageContent *content); bool is_unsent_animated_emoji_click(Td *td, DialogId dialog_id, const DialogAction &action); -vector get_all_active_reactions(Td *td); - -vector get_active_reactions(Td *td, const vector &available_reactions); - void on_dialog_used(TopDialogCategory category, DialogId dialog_id, int32 date); void update_used_hashtags(Td *td, const MessageContent *content); diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 2cc193670..b73557b24 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -8194,8 +8194,7 @@ void MessagesManager::set_dialog_available_reactions(Dialog *d, vector & VLOG(notifications) << "Update available reactions in " << d->dialog_id << " to " << available_reactions; - bool need_update = - get_active_reactions(td_, d->available_reactions) != get_active_reactions(td_, available_reactions); + bool need_update = get_active_reactions(d->available_reactions) != get_active_reactions(available_reactions); d->available_reactions = std::move(available_reactions); d->is_available_reactions_inited = true; @@ -8206,14 +8205,26 @@ void MessagesManager::set_dialog_available_reactions(Dialog *d, vector & } } +void MessagesManager::set_active_reactions(vector active_reactions) { + if (active_reactions == active_reactions_) { + return; + } + + active_reactions_ = std::move(active_reactions); +} + +vector MessagesManager::get_active_reactions(const vector &available_reactions) const { + return available_reactions; +} + vector MessagesManager::get_dialog_active_reactions(const Dialog *d) const { CHECK(d != nullptr); switch (d->dialog_id.get_type()) { case DialogType::User: - return get_all_active_reactions(td_); + return active_reactions_; case DialogType::Chat: case DialogType::Channel: - return get_active_reactions(td_, d->available_reactions); + return get_active_reactions(d->available_reactions); case DialogType::SecretChat: return {}; default: @@ -32439,7 +32450,7 @@ void MessagesManager::set_dialog_available_reactions(DialogId dialog_id, vector< return promise.set_error(Status::Error(400, "Chat not found")); } - if (get_active_reactions(td_, available_reactions) != available_reactions) { + if (get_active_reactions(available_reactions) != available_reactions) { return promise.set_error(Status::Error(400, "Invalid reactions specified")); } std::unordered_set unique_reactions{available_reactions.begin(), available_reactions.end()}; diff --git a/td/telegram/MessagesManager.h b/td/telegram/MessagesManager.h index 5984c3e83..b1438d706 100644 --- a/td/telegram/MessagesManager.h +++ b/td/telegram/MessagesManager.h @@ -504,6 +504,8 @@ class MessagesManager final : public Actor { void set_dialog_description(DialogId dialog_id, const string &description, Promise &&promise); + void set_active_reactions(vector active_reactions); + void set_dialog_available_reactions(DialogId dialog_id, vector available_reactions, Promise &&promise); void set_dialog_permissions(DialogId dialog_id, const td_api::object_ptr &permissions, @@ -2580,6 +2582,8 @@ class MessagesManager final : public Actor { void set_dialog_available_reactions(Dialog *d, vector &&available_reactions); + vector get_active_reactions(const vector &available_reactions) const; + vector get_dialog_active_reactions(const Dialog *d) const; bool is_dialog_action_unneeded(DialogId dialog_id) const; @@ -3581,6 +3585,8 @@ class MessagesManager final : public Actor { std::unordered_map previous_repaired_read_inbox_max_message_id_; + vector active_reactions_; + uint32 scheduled_messages_sync_generation_ = 1; int64 authorization_date_ = 0; diff --git a/td/telegram/OptionManager.cpp b/td/telegram/OptionManager.cpp index e21a9395d..1346035d8 100644 --- a/td/telegram/OptionManager.cpp +++ b/td/telegram/OptionManager.cpp @@ -475,7 +475,7 @@ void OptionManager::set_option(const string &name, td_api::object_ptrstickers_manager_->get_active_reactions({value.str()}).size() == 1; + return td->stickers_manager_->is_active_reaction(value.str()); })) { G()->shared_config().set_option_boolean("default_reaction_needs_sync", true); return; @@ -709,7 +709,8 @@ void OptionManager::set_default_reaction() { auto promise = PromiseCreator::lambda([actor_id = actor_id(this)](Result &&result) { send_closure(actor_id, &OptionManager::on_set_default_reaction, result.is_ok()); }); - td_->create_handler(std::move(promise))->send(G()->shared_config().get_option_string("default_reaction")); + td_->create_handler(std::move(promise)) + ->send(G()->shared_config().get_option_string("default_reaction")); } void OptionManager::on_set_default_reaction(bool success) { diff --git a/td/telegram/StickersManager.cpp b/td/telegram/StickersManager.cpp index 0646cf622..7324a34b3 100644 --- a/td/telegram/StickersManager.cpp +++ b/td/telegram/StickersManager.cpp @@ -3201,9 +3201,10 @@ void StickersManager::on_get_available_reactions( new_reactions.push_back(std::move(reaction)); } reactions_.reactions_ = std::move(new_reactions); - reactions_.active_reactions_ = std::move(new_active_reactions); reactions_.hash_ = available_reactions->hash_; send_closure(G()->td(), &Td::send_update, get_update_reactions_object()); + + td_->messages_manager_->set_active_reactions(std::move(new_active_reactions)); } void StickersManager::on_get_installed_sticker_sets(bool is_masks, @@ -4848,12 +4849,13 @@ void StickersManager::send_update_animated_emoji_clicked(FullMessageId full_mess dialog_id.get(), full_message_id.get_message_id().get(), get_sticker_object(sticker_id, false, true))); } -vector StickersManager::get_all_active_reactions() const { - return reactions_.active_reactions_; -} - -vector StickersManager::get_active_reactions(const vector &available_reactions) const { - return available_reactions; +bool StickersManager::is_active_reaction(const string &reaction) const { + for (auto &supported_reaction : reactions_.reactions_) { + if (supported_reaction.reaction_ == reaction) { + return supported_reaction.is_active_; + } + } + return false; } void StickersManager::view_featured_sticker_sets(const vector &sticker_set_ids) { diff --git a/td/telegram/StickersManager.h b/td/telegram/StickersManager.h index b443bdb48..bd506778e 100644 --- a/td/telegram/StickersManager.h +++ b/td/telegram/StickersManager.h @@ -89,9 +89,7 @@ class StickersManager final : public Actor { Status on_animated_emoji_message_clicked(Slice emoji, FullMessageId full_message_id, string data); - vector get_all_active_reactions() const; - - vector get_active_reactions(const vector &available_reactions) const; + bool is_active_reaction(const string &reaction) const; void create_sticker(FileId file_id, string minithumbnail, PhotoSize thumbnail, Dimensions dimensions, tl_object_ptr sticker, StickerFormat sticker_format, @@ -459,7 +457,6 @@ class StickersManager final : public Actor { int32 hash_ = 0; bool are_being_reloaded_ = false; vector reactions_; - vector active_reactions_; }; class StickerListLogEvent;