From f6616f6ba3927ea9ad3136e4bbab83e4f1fb723e Mon Sep 17 00:00:00 2001 From: levlam Date: Sat, 4 Feb 2023 17:59:17 +0300 Subject: [PATCH] Fix creator in ForumTopicInfo. --- td/telegram/DialogEventLog.cpp | 12 ++++++------ td/telegram/ForumTopicInfo.cpp | 8 +++++++- td/telegram/ForumTopicInfo.h | 2 +- td/telegram/ForumTopicManager.cpp | 4 ++-- td/telegram/MessagesManager.cpp | 3 ++- 5 files changed, 18 insertions(+), 11 deletions(-) diff --git a/td/telegram/DialogEventLog.cpp b/td/telegram/DialogEventLog.cpp index b1cd069e4..87fb649c6 100644 --- a/td/telegram/DialogEventLog.cpp +++ b/td/telegram/DialogEventLog.cpp @@ -364,7 +364,7 @@ static td_api::object_ptr get_chat_event_action_object( } case telegram_api::channelAdminLogEventActionCreateTopic::ID: { auto action = move_tl_object_as(action_ptr); - auto topic_info = ForumTopicInfo(action->topic_); + auto topic_info = ForumTopicInfo(td, action->topic_); if (topic_info.is_empty()) { return nullptr; } @@ -373,8 +373,8 @@ static td_api::object_ptr get_chat_event_action_object( } case telegram_api::channelAdminLogEventActionEditTopic::ID: { auto action = move_tl_object_as(action_ptr); - auto old_topic_info = ForumTopicInfo(action->prev_topic_); - auto new_topic_info = ForumTopicInfo(action->new_topic_); + auto old_topic_info = ForumTopicInfo(td, action->prev_topic_); + auto new_topic_info = ForumTopicInfo(td, action->new_topic_); if (old_topic_info.is_empty() || new_topic_info.is_empty() || old_topic_info.get_top_thread_message_id() != new_topic_info.get_top_thread_message_id()) { LOG(ERROR) << "Receive " << to_string(action); @@ -395,7 +395,7 @@ static td_api::object_ptr get_chat_event_action_object( } case telegram_api::channelAdminLogEventActionDeleteTopic::ID: { auto action = move_tl_object_as(action_ptr); - auto topic_info = ForumTopicInfo(action->topic_); + auto topic_info = ForumTopicInfo(td, action->topic_); if (topic_info.is_empty()) { return nullptr; } @@ -406,10 +406,10 @@ static td_api::object_ptr get_chat_event_action_object( ForumTopicInfo old_topic_info; ForumTopicInfo new_topic_info; if (action->prev_topic_ != nullptr) { - old_topic_info = ForumTopicInfo(action->prev_topic_); + old_topic_info = ForumTopicInfo(td, action->prev_topic_); } if (action->new_topic_ != nullptr) { - new_topic_info = ForumTopicInfo(action->new_topic_); + new_topic_info = ForumTopicInfo(td, action->new_topic_); } if (old_topic_info.is_empty() && new_topic_info.is_empty()) { return nullptr; diff --git a/td/telegram/ForumTopicInfo.cpp b/td/telegram/ForumTopicInfo.cpp index 3002cb498..924de3dfd 100644 --- a/td/telegram/ForumTopicInfo.cpp +++ b/td/telegram/ForumTopicInfo.cpp @@ -7,13 +7,15 @@ #include "td/telegram/ForumTopicInfo.h" #include "td/telegram/MessageSender.h" +#include "td/telegram/MessagesManager.h" #include "td/telegram/ServerMessageId.h" +#include "td/telegram/Td.h" #include "td/utils/logging.h" namespace td { -ForumTopicInfo::ForumTopicInfo(const tl_object_ptr &forum_topic_ptr) { +ForumTopicInfo::ForumTopicInfo(Td *td, const tl_object_ptr &forum_topic_ptr) { CHECK(forum_topic_ptr != nullptr); if (forum_topic_ptr->get_id() != telegram_api::forumTopic::ID) { LOG(ERROR) << "Receive " << to_string(forum_topic_ptr); @@ -26,6 +28,10 @@ ForumTopicInfo::ForumTopicInfo(const tl_object_ptr &fo icon_ = ForumTopicIcon(forum_topic->icon_color_, forum_topic->icon_emoji_id_); creation_date_ = forum_topic->date_; creator_dialog_id_ = DialogId(forum_topic->from_id_); + if (creator_dialog_id_.is_valid() && creator_dialog_id_.get_type() != DialogType::User && + td->messages_manager_->have_dialog_info_force(creator_dialog_id_)) { + td->messages_manager_->force_create_dialog(creator_dialog_id_, "ForumTopicInfo", true); + } is_outgoing_ = forum_topic->my_; is_closed_ = forum_topic->closed_; is_hidden_ = forum_topic->hidden_; diff --git a/td/telegram/ForumTopicInfo.h b/td/telegram/ForumTopicInfo.h index cadfce0b8..c9b6cda7a 100644 --- a/td/telegram/ForumTopicInfo.h +++ b/td/telegram/ForumTopicInfo.h @@ -38,7 +38,7 @@ class ForumTopicInfo { public: ForumTopicInfo() = default; - explicit ForumTopicInfo(const tl_object_ptr &forum_topic_ptr); + ForumTopicInfo(Td *td, const tl_object_ptr &forum_topic_ptr); ForumTopicInfo(MessageId top_thread_message_id, string title, ForumTopicIcon icon, int32 creation_date, DialogId creator_dialog_id, bool is_outgoing, bool is_closed, bool is_hidden) diff --git a/td/telegram/ForumTopicManager.cpp b/td/telegram/ForumTopicManager.cpp index 736f27a7a..f9cf75995 100644 --- a/td/telegram/ForumTopicManager.cpp +++ b/td/telegram/ForumTopicManager.cpp @@ -945,7 +945,7 @@ void ForumTopicManager::on_get_forum_topic_infos(DialogId dialog_id, auto dialog_topics = add_dialog_topics(dialog_id); CHECK(dialog_topics != nullptr); for (auto &forum_topic : forum_topics) { - auto forum_topic_info = td::make_unique(forum_topic); + auto forum_topic_info = td::make_unique(td_, forum_topic); MessageId top_thread_message_id = forum_topic_info->get_top_thread_message_id(); if (can_be_message_thread_id(top_thread_message_id).is_error()) { continue; @@ -973,7 +973,7 @@ MessageId ForumTopicManager::on_get_forum_topic_impl(DialogId dialog_id, return MessageId(); } case telegram_api::forumTopic::ID: { - auto forum_topic_info = td::make_unique(forum_topic); + auto forum_topic_info = td::make_unique(td_, forum_topic); MessageId top_thread_message_id = forum_topic_info->get_top_thread_message_id(); Topic *topic = add_topic(dialog_id, top_thread_message_id); if (topic == nullptr) { diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 234ebc510..ef99ec750 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -14934,7 +14934,8 @@ std::pair> MessagesManager::creat bool has_forward_info = message_info.forward_header != nullptr; if (sender_dialog_id.is_valid() && sender_dialog_id != dialog_id && have_dialog_info_force(sender_dialog_id)) { - force_create_dialog(sender_dialog_id, "create_message", sender_dialog_id.get_type() != DialogType::User); + CHECK(sender_dialog_id.get_type() != DialogType::User); + force_create_dialog(sender_dialog_id, "create_message", true); } LOG(INFO) << "Receive " << message_id << " in " << dialog_id << " from " << sender_user_id << "/" << sender_dialog_id;