Replace updateReactions with updateActiveEmojiReactions.

This commit is contained in:
levlam 2022-09-12 01:35:47 +03:00
parent f119e867df
commit d29d3674ba
3 changed files with 46 additions and 19 deletions

View File

@ -4489,8 +4489,8 @@ updateAttachmentMenuBots bots:vector<attachmentMenuBot> = 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 //@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; updateWebAppMessageSent web_app_launch_id:int64 = Update;
//@description The list of supported reactions has changed @reactions The new list of supported reactions //@description The list of active emoji reactions has changed @emojis The new list of active emoji reactions
updateReactions reactions:vector<reaction> = Update; updateActiveEmojiReactions emojis:vector<string> = Update;
//@description The type of default reaction has changed @reaction_type The new type of the default reaction //@description The type of default reaction has changed @reaction_type The new type of the default reaction
updateDefaultReactionType reaction_type:ReactionType = Update; 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; 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 //@chat_id Identifier of the chat to which the message belongs
//@message_id Identifier of the message //@message_id Identifier of the message
getMessageAvailableReactions chat_id:int53 message_id:int53 = AvailableReactions; getMessageAvailableReactions chat_id:int53 message_id:int53 = AvailableReactions;

View File

@ -1450,7 +1450,7 @@ void StickersManager::init() {
} }
send_closure(G()->td(), &Td::send_update, get_update_dice_emojis_object()); 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_success_values();
on_update_dice_emojis(); 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()); on_load_special_sticker_set(type, Status::OK());
} }
td_api::object_ptr<td_api::updateReactions> StickersManager::get_update_reactions_object() const { td_api::object_ptr<td_api::updateActiveEmojiReactions> StickersManager::get_update_active_emoji_reactions_object()
auto reactions = transform(reactions_.reactions_, [this](const Reaction &reaction) { const {
return td_api::make_object<td_api::reaction>( return td_api::make_object<td_api::updateActiveEmojiReactions>(vector<string>(active_reactions_));
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_), void StickersManager::save_active_reactions() {
get_sticker_object(reaction.around_animation_), get_sticker_object(reaction.center_animation_)); LOG(INFO) << "Save active reactions";
}); G()->td_db()->get_binlog_pmc()->set("active_reactions", log_event_store(active_reactions_).as_slice().str());
return td_api::make_object<td_api::updateReactions>(std::move(reactions));
} }
void StickersManager::save_reactions() { 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()); 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() { void StickersManager::load_reactions() {
string reactions = G()->td_db()->get_binlog_pmc()->get("reactions"); string reactions = G()->td_db()->get_binlog_pmc()->get("reactions");
if (reactions.empty()) { if (reactions.empty()) {
@ -3691,8 +3707,6 @@ void StickersManager::load_reactions() {
} }
LOG(INFO) << "Successfully loaded " << reactions_.reactions_.size() << " available 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(); update_active_reactions();
} }
@ -3704,6 +3718,15 @@ void StickersManager::update_active_reactions() {
active_reactions.emplace_back(reaction.reaction_); 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)); 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_.reactions_ = std::move(new_reactions);
reactions_.hash_ = available_reactions->hash_; reactions_.hash_ = available_reactions->hash_;
send_closure(G()->td(), &Td::send_update, get_update_reactions_object());
save_reactions(); save_reactions();
@ -8985,8 +9007,8 @@ void StickersManager::get_current_state(vector<td_api::object_ptr<td_api::Update
return; return;
} }
if (!reactions_.reactions_.empty()) { if (!active_reactions_.empty()) {
updates.push_back(get_update_reactions_object()); updates.push_back(get_update_active_emoji_reactions_object());
} }
for (int32 type = 0; type < MAX_STICKER_TYPE; type++) { for (int32 type = 0; type < MAX_STICKER_TYPE; type++) {
if (are_installed_sticker_sets_loaded_[type]) { if (are_installed_sticker_sets_loaded_[type]) {

View File

@ -821,13 +821,17 @@ class StickersManager final : public Actor {
void tear_down() final; void tear_down() final;
void save_active_reactions();
void save_reactions(); void save_reactions();
void load_active_reactions();
void load_reactions(); void load_reactions();
void update_active_reactions(); void update_active_reactions();
td_api::object_ptr<td_api::updateReactions> get_update_reactions_object() const; td_api::object_ptr<td_api::updateActiveEmojiReactions> get_update_active_emoji_reactions_object() const;
SpecialStickerSet &add_special_sticker_set(const SpecialStickerSetType &type); SpecialStickerSet &add_special_sticker_set(const SpecialStickerSetType &type);
@ -1004,6 +1008,7 @@ class StickersManager final : public Actor {
FlatHashMap<FileId, std::pair<UserId, Promise<Unit>>, FileIdHash> being_uploaded_files_; FlatHashMap<FileId, std::pair<UserId, Promise<Unit>>, FileIdHash> being_uploaded_files_;
Reactions reactions_; Reactions reactions_;
vector<string> active_reactions_;
FlatHashMap<string, vector<string>> emoji_language_codes_; FlatHashMap<string, vector<string>> emoji_language_codes_;
FlatHashMap<string, int32> emoji_language_code_versions_; FlatHashMap<string, int32> emoji_language_code_versions_;