diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 565976b06..1fddcc358 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -4489,8 +4489,8 @@ updateAttachmentMenuBots bots:vector = Update; //@description A message was sent by an opened Web App, so the Web App needs to be closed @web_app_launch_id Identifier of Web App launch updateWebAppMessageSent web_app_launch_id:int64 = Update; -//@description The list of supported reactions has changed @reactions The new list of supported reactions -updateReactions reactions:vector = Update; +//@description The list of active emoji reactions has changed @emojis The new list of active emoji reactions +updateActiveEmojiReactions emojis:vector = Update; //@description The type of default reaction has changed @reaction_type The new type of the default reaction updateDefaultReactionType reaction_type:ReactionType = Update; @@ -5164,7 +5164,7 @@ editInlineMessageReplyMarkup inline_message_id:string reply_markup:ReplyMarkup = editMessageSchedulingState chat_id:int53 message_id:int53 scheduling_state:MessageSchedulingState = Ok; -//@description Returns reactions, which can be added to a message. The list can change after updateReactions, updateChatAvailableReactions for the chat, or updateMessageInteractionInfo for the message +//@description Returns reactions, which can be added to a message. The list can change after updateActiveEmojiReactions, updateChatAvailableReactions for the chat, or updateMessageInteractionInfo for the message //@chat_id Identifier of the chat to which the message belongs //@message_id Identifier of the message getMessageAvailableReactions chat_id:int53 message_id:int53 = AvailableReactions; diff --git a/td/telegram/StickersManager.cpp b/td/telegram/StickersManager.cpp index 5810edb45..b50a7ea30 100644 --- a/td/telegram/StickersManager.cpp +++ b/td/telegram/StickersManager.cpp @@ -1450,7 +1450,7 @@ void StickersManager::init() { } send_closure(G()->td(), &Td::send_update, get_update_dice_emojis_object()); - send_closure_later(actor_id(this), &StickersManager::load_reactions); + load_active_reactions(); on_update_dice_success_values(); on_update_dice_emojis(); @@ -3654,15 +3654,14 @@ void StickersManager::on_get_special_sticker_set(const SpecialStickerSetType &ty on_load_special_sticker_set(type, Status::OK()); } -td_api::object_ptr StickersManager::get_update_reactions_object() const { - auto reactions = transform(reactions_.reactions_, [this](const Reaction &reaction) { - return td_api::make_object( - reaction.reaction_, reaction.title_, reaction.is_active_, get_sticker_object(reaction.static_icon_), - get_sticker_object(reaction.appear_animation_), get_sticker_object(reaction.select_animation_), - get_sticker_object(reaction.activate_animation_), get_sticker_object(reaction.effect_animation_), - get_sticker_object(reaction.around_animation_), get_sticker_object(reaction.center_animation_)); - }); - return td_api::make_object(std::move(reactions)); +td_api::object_ptr StickersManager::get_update_active_emoji_reactions_object() + const { + return td_api::make_object(vector(active_reactions_)); +} + +void StickersManager::save_active_reactions() { + LOG(INFO) << "Save active reactions"; + G()->td_db()->get_binlog_pmc()->set("active_reactions", log_event_store(active_reactions_).as_slice().str()); } void StickersManager::save_reactions() { @@ -3670,6 +3669,23 @@ void StickersManager::save_reactions() { G()->td_db()->get_binlog_pmc()->set("reactions", log_event_store(reactions_).as_slice().str()); } +void StickersManager::load_active_reactions() { + string active_reactions = G()->td_db()->get_binlog_pmc()->get("active_reactions"); + if (active_reactions.empty()) { + return reload_reactions(); + } + + auto status = log_event_parse(active_reactions_, active_reactions); + if (status.is_error()) { + LOG(ERROR) << "Can't load active reactions: " << status; + active_reactions_ = {}; + return reload_reactions(); + } + + LOG(INFO) << "Successfully loaded " << active_reactions_.size() << " active reactions"; + send_closure(G()->td(), &Td::send_update, get_update_active_emoji_reactions_object()); +} + void StickersManager::load_reactions() { string reactions = G()->td_db()->get_binlog_pmc()->get("reactions"); if (reactions.empty()) { @@ -3691,8 +3707,6 @@ void StickersManager::load_reactions() { } LOG(INFO) << "Successfully loaded " << reactions_.reactions_.size() << " available reactions"; - send_closure(G()->td(), &Td::send_update, get_update_reactions_object()); - LOG(INFO) << "Successfully sent updateReactions"; update_active_reactions(); } @@ -3704,6 +3718,15 @@ void StickersManager::update_active_reactions() { active_reactions.emplace_back(reaction.reaction_); } } + if (active_reactions == active_reactions_) { + return; + } + active_reactions_ = active_reactions; + + save_active_reactions(); + + send_closure(G()->td(), &Td::send_update, get_update_active_emoji_reactions_object()); + td_->messages_manager_->set_active_reactions(std::move(active_reactions)); } @@ -3760,7 +3783,6 @@ void StickersManager::on_get_available_reactions( } reactions_.reactions_ = std::move(new_reactions); reactions_.hash_ = available_reactions->hash_; - send_closure(G()->td(), &Td::send_update, get_update_reactions_object()); save_reactions(); @@ -8985,8 +9007,8 @@ void StickersManager::get_current_state(vector get_update_reactions_object() const; + td_api::object_ptr get_update_active_emoji_reactions_object() const; SpecialStickerSet &add_special_sticker_set(const SpecialStickerSetType &type); @@ -1004,6 +1008,7 @@ class StickersManager final : public Actor { FlatHashMap>, FileIdHash> being_uploaded_files_; Reactions reactions_; + vector active_reactions_; FlatHashMap> emoji_language_codes_; FlatHashMap emoji_language_code_versions_;