From f0503191e4e1a2fd88e1c3f9fc38088f4f1557a2 Mon Sep 17 00:00:00 2001 From: levlam Date: Fri, 2 Feb 2024 17:09:49 +0300 Subject: [PATCH] Load Saved Messages tags in topic from database. --- td/telegram/ReactionManager.cpp | 21 +++++++++++++++++++++ td/telegram/ReactionManager.h | 2 ++ 2 files changed, 23 insertions(+) diff --git a/td/telegram/ReactionManager.cpp b/td/telegram/ReactionManager.cpp index 5c4b4efc7..4f0a6dac6 100644 --- a/td/telegram/ReactionManager.cpp +++ b/td/telegram/ReactionManager.cpp @@ -964,6 +964,26 @@ void ReactionManager::load_all_saved_reaction_tags_from_database() { reget_saved_messages_tags(SavedMessagesTopicId(), Auto()); } +void ReactionManager::load_saved_reaction_tags_from_database(SavedMessagesTopicId saved_messages_topic_id, + SavedReactionTags *tags) { + if (!G()->use_message_database()) { + return; + } + + auto value = G()->td_db()->get_sqlite_sync_pmc()->get(get_saved_messages_tags_database_key(saved_messages_topic_id)); + if (value.empty()) { + return; + } + if (log_event_parse(*tags, value).is_error()) { + LOG(ERROR) << "Failed to load all tags from database"; + *tags = {}; + return; + } + + send_update_saved_messages_tags(saved_messages_topic_id, tags, true); + reget_saved_messages_tags(saved_messages_topic_id, Auto()); +} + ReactionManager::SavedReactionTags *ReactionManager::get_saved_reaction_tags( SavedMessagesTopicId saved_messages_topic_id) { if (saved_messages_topic_id == SavedMessagesTopicId()) { @@ -973,6 +993,7 @@ ReactionManager::SavedReactionTags *ReactionManager::get_saved_reaction_tags( auto &tags = topic_tags_[saved_messages_topic_id]; if (tags == nullptr) { tags = make_unique(); + load_saved_reaction_tags_from_database(saved_messages_topic_id, tags.get()); } return tags.get(); } diff --git a/td/telegram/ReactionManager.h b/td/telegram/ReactionManager.h index 79d8e14a1..2a014bdb3 100644 --- a/td/telegram/ReactionManager.h +++ b/td/telegram/ReactionManager.h @@ -224,6 +224,8 @@ class ReactionManager final : public Actor { void load_all_saved_reaction_tags_from_database(); + void load_saved_reaction_tags_from_database(SavedMessagesTopicId saved_messages_topic_id, SavedReactionTags *tags); + td_api::object_ptr get_update_saved_messages_tags_object( SavedMessagesTopicId saved_messages_topic_id, const SavedReactionTags *tags) const;