Add ForumTopicManager::set_topic_info.

This commit is contained in:
levlam 2022-12-05 18:40:08 +03:00
parent 426c308e23
commit d27181a69d
2 changed files with 14 additions and 9 deletions

View File

@ -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<ForumTopicInfo> 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<td_api::updateForumTopicInfo> ForumTopicManager::get_update_forum_topic_info(
DialogId dialog_id, const ForumTopicInfo *topic_info) const {
return td_api::make_object<td_api::updateForumTopicInfo>(dialog_id.get(),

View File

@ -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<ForumTopicInfo> forum_topic_info);
void on_delete_forum_topic(DialogId dialog_id, MessageId top_thread_message_id, Promise<Unit> &&promise);
td_api::object_ptr<td_api::updateForumTopicInfo> get_update_forum_topic_info(DialogId dialog_id,