Load Saved Messages tags in topic from database.

This commit is contained in:
levlam 2024-02-02 17:09:49 +03:00
parent 3e9f2ba515
commit f0503191e4
2 changed files with 23 additions and 0 deletions

View File

@ -964,6 +964,26 @@ void ReactionManager::load_all_saved_reaction_tags_from_database() {
reget_saved_messages_tags(SavedMessagesTopicId(), Auto()); 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( ReactionManager::SavedReactionTags *ReactionManager::get_saved_reaction_tags(
SavedMessagesTopicId saved_messages_topic_id) { SavedMessagesTopicId saved_messages_topic_id) {
if (saved_messages_topic_id == SavedMessagesTopicId()) { 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]; auto &tags = topic_tags_[saved_messages_topic_id];
if (tags == nullptr) { if (tags == nullptr) {
tags = make_unique<SavedReactionTags>(); tags = make_unique<SavedReactionTags>();
load_saved_reaction_tags_from_database(saved_messages_topic_id, tags.get());
} }
return tags.get(); return tags.get();
} }

View File

@ -224,6 +224,8 @@ class ReactionManager final : public Actor {
void load_all_saved_reaction_tags_from_database(); 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<td_api::updateSavedMessagesTags> get_update_saved_messages_tags_object( td_api::object_ptr<td_api::updateSavedMessagesTags> get_update_saved_messages_tags_object(
SavedMessagesTopicId saved_messages_topic_id, const SavedReactionTags *tags) const; SavedMessagesTopicId saved_messages_topic_id, const SavedReactionTags *tags) const;