diff --git a/td/telegram/ForumTopicManager.cpp b/td/telegram/ForumTopicManager.cpp index 4681c7fda..b1a4c62d5 100644 --- a/td/telegram/ForumTopicManager.cpp +++ b/td/telegram/ForumTopicManager.cpp @@ -502,9 +502,7 @@ void ForumTopicManager::on_get_forum_topic_info(DialogId dialog_id, const ForumT MessageId top_thread_message_id = forum_topic_info->get_top_thread_message_id(); CHECK(can_be_message_thread_id(top_thread_message_id).is_ok()); auto topic = add_topic(dialog_topics, top_thread_message_id); - if (topic->info_ == nullptr || *topic->info_ != *forum_topic_info) { - topic->info_ = std::move(forum_topic_info); - send_update_forum_topic_info(dialog_id, topic->info_.get()); + if (set_topic_info(dialog_id, topic, std::move(forum_topic_info))) { save_topic_to_database(dialog_id, topic); } } @@ -529,9 +527,7 @@ void ForumTopicManager::on_get_forum_topic_infos(DialogId dialog_id, continue; } auto topic = add_topic(dialog_topics, top_thread_message_id); - if (topic->info_ == nullptr || *topic->info_ != *forum_topic_info) { - topic->info_ = std::move(forum_topic_info); - send_update_forum_topic_info(dialog_id, topic->info_.get()); + if (set_topic_info(dialog_id, topic, std::move(forum_topic_info))) { save_topic_to_database(dialog_id, topic); } } @@ -565,9 +561,7 @@ MessageId ForumTopicManager::on_get_forum_topic(DialogId dialog_id, topic->topic_ = std::move(forum_topic_full); need_save = true; } - if (topic->info_ == nullptr || *topic->info_ != *forum_topic_info) { - topic->info_ = std::move(forum_topic_info); - send_update_forum_topic_info(dialog_id, topic->info_.get()); + if (set_topic_info(dialog_id, topic, std::move(forum_topic_info))) { need_save = true; } if (need_save) { @@ -671,6 +665,15 @@ const ForumTopicInfo *ForumTopicManager::get_topic_info(DialogId dialog_id, Mess return topic->info_.get(); } +bool ForumTopicManager::set_topic_info(DialogId dialog_id, Topic *topic, unique_ptr forum_topic_info) { + if (topic->info_ == nullptr || *topic->info_ != *forum_topic_info) { + topic->info_ = std::move(forum_topic_info); + send_update_forum_topic_info(dialog_id, topic->info_.get()); + return true; + } + return false; +} + td_api::object_ptr ForumTopicManager::get_update_forum_topic_info( DialogId dialog_id, const ForumTopicInfo *topic_info) const { return td_api::make_object(dialog_id.get(), diff --git a/td/telegram/ForumTopicManager.h b/td/telegram/ForumTopicManager.h index 6715e77b4..1fd71aa80 100644 --- a/td/telegram/ForumTopicManager.h +++ b/td/telegram/ForumTopicManager.h @@ -116,6 +116,8 @@ class ForumTopicManager final : public Actor { const ForumTopicInfo *get_topic_info(DialogId dialog_id, MessageId top_thread_message_id) const; + bool set_topic_info(DialogId dialog_id, Topic *topic, unique_ptr forum_topic_info); + void on_delete_forum_topic(DialogId dialog_id, MessageId top_thread_message_id, Promise &&promise); td_api::object_ptr get_update_forum_topic_info(DialogId dialog_id,