diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 4bf77b1f1..52c307276 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -21559,7 +21559,6 @@ Status MessagesManager::view_messages(DialogId dialog_id, vector mess // get information about thread of the messages MessageId top_thread_message_id; - MessageId max_thread_message_id; if (source == MessageSource::MessageThreadHistory) { if (dialog_id.get_type() != DialogType::Channel || is_broadcast_channel(dialog_id)) { return Status::Error(400, "There are no message threads in the chat"); @@ -21581,15 +21580,19 @@ Status MessagesManager::view_messages(DialogId dialog_id, vector mess } } else { top_thread_message_id = m->top_thread_message_id; - const auto *top_m = get_message_force(d, top_thread_message_id, "view_messages 2"); - if (top_m != nullptr && !top_m->reply_info.is_comment_) { - max_thread_message_id = top_m->reply_info.max_message_id_; - } } } } } + MessageId max_thread_message_id; + if (top_thread_message_id.is_valid()) { + const auto *top_m = get_message_force(d, top_thread_message_id, "view_messages 2"); + if (top_m != nullptr && !top_m->reply_info.is_comment_) { + max_thread_message_id = top_m->reply_info.max_message_id_; + } + } + // get forum topic identifier for the messages MessageId forum_topic_id; if (source == MessageSource::ForumTopicHistory) {