From f531d0cd17cd959c1f2e77d9f19b280e7e26ffe2 Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 16 Apr 2026 15:45:38 +0300 Subject: [PATCH] Improve Client::init_message. --- telegram-bot-api/Client.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/telegram-bot-api/Client.cpp b/telegram-bot-api/Client.cpp index f52cad6..66e4346 100644 --- a/telegram-bot-api/Client.cpp +++ b/telegram-bot-api/Client.cpp @@ -17520,8 +17520,6 @@ td::unique_ptr Client::delete_message(int64 chat_id, int64 const Client::MessageInfo *Client::add_message(object_ptr &&message, bool force_update_content) { CHECK(message != nullptr); - CHECK(message->sending_state_ == nullptr); - int64 chat_id = message->chat_id_; int64 message_id = message->id_; @@ -17537,6 +17535,7 @@ const Client::MessageInfo *Client::add_message(object_ptr &&mes } void Client::init_message(MessageInfo *message_info, object_ptr &&message, bool force_update_content) { + CHECK(message->sending_state_ == nullptr); int64 chat_id = message->chat_id_; message_info->id = message->id_; message_info->chat_id = chat_id; @@ -17548,10 +17547,6 @@ void Client::init_message(MessageInfo *message_info, object_ptr if (message->forward_info_ != nullptr) { message_info->initial_send_date = message->forward_info_->date_; message_info->forward_origin = std::move(message->forward_info_->origin_); - - message_info->is_automatic_forward = message->forward_info_->source_ != nullptr && - get_chat_type(chat_id) == ChatType::Supergroup && - get_chat_type(message->forward_info_->source_->chat_id_) == ChatType::Channel; } else if (message->import_info_ != nullptr) { message_info->initial_send_date = message->import_info_->date_; message_info->forward_origin = make_object(message->import_info_->sender_name_); @@ -17559,6 +17554,10 @@ void Client::init_message(MessageInfo *message_info, object_ptr message_info->initial_send_date = 0; message_info->forward_origin = nullptr; } + message_info->is_automatic_forward = message->forward_info_ != nullptr && + message->forward_info_->source_ != nullptr && + get_chat_type(chat_id) == ChatType::Supergroup && + get_chat_type(message->forward_info_->source_->chat_id_) == ChatType::Channel; CHECK(message->sender_id_ != nullptr); switch (message->sender_id_->get_id()) { @@ -17566,6 +17565,7 @@ void Client::init_message(MessageInfo *message_info, object_ptr auto sender_id = move_object_as(message->sender_id_); message_info->sender_user_id = sender_id->user_id_; CHECK(message_info->sender_user_id > 0); + message_info->sender_chat_id = 0; break; } case td_api::messageSenderChat::ID: { @@ -17582,6 +17582,8 @@ void Client::init_message(MessageInfo *message_info, object_ptr message_info->sender_user_id = channel_bot_user_id_; } CHECK(message_info->sender_user_id > 0); + } else { + message_info->sender_user_id = 0; } break; }