From df89ddf059469002f7d6c6c9b46ef3b1e2bf777f Mon Sep 17 00:00:00 2001 From: levlam Date: Wed, 8 Dec 2021 14:04:49 +0300 Subject: [PATCH 1/4] Fix Message.is_automatic_forward flag for automatically forwarded manually forwarded messages. --- telegram-bot-api/Client.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/telegram-bot-api/Client.cpp b/telegram-bot-api/Client.cpp index 9d8f85f..a374e3e 100644 --- a/telegram-bot-api/Client.cpp +++ b/telegram-bot-api/Client.cpp @@ -9605,9 +9605,10 @@ Client::FullMessageId Client::add_message(object_ptr &&message, default: UNREACHABLE(); } - message_info->is_automatic_forward = message_info->initial_chat_id != 0 && message_info->initial_message_id != 0 && - message_info->initial_chat_id == message->forward_info_->from_chat_id_ && - message_info->initial_message_id == message->forward_info_->from_message_id_; + auto from_chat_id = message->forward_info_->from_chat_id_; + message_info->is_automatic_forward = + from_chat_id != 0 && from_chat_id != chat_id && message->forward_info_->from_message_id_ != 0 && + get_chat_type(chat_id) == ChatType::Supergroup && get_chat_type(from_chat_id) == ChatType::Channel; } message_info->can_be_saved = message->can_be_saved_; From 34a5f9c9cfaba89219d8a9e0b13076016732d621 Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 9 Dec 2021 18:36:38 +0300 Subject: [PATCH 2/4] Update TDLib. --- td | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/td b/td index a53cb30..6821219 160000 --- a/td +++ b/td @@ -1 +1 @@ -Subproject commit a53cb30e99f937cfd64e0266fa558785a184a553 +Subproject commit 68212198a0e44086bd8a63d23365c3f56e391f0f From 398074809982cd0605d89dbb5cd59b7c1f0ab2f8 Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 9 Dec 2021 18:48:39 +0300 Subject: [PATCH 3/4] Use channel_bot as sender of channel messages. --- telegram-bot-api/Client.cpp | 59 ++++++++++++++++++++----------------- telegram-bot-api/Client.h | 1 + 2 files changed, 33 insertions(+), 27 deletions(-) diff --git a/telegram-bot-api/Client.cpp b/telegram-bot-api/Client.cpp index a374e3e..dbf9f4f 100644 --- a/telegram-bot-api/Client.cpp +++ b/telegram-bot-api/Client.cpp @@ -4448,6 +4448,9 @@ void Client::on_update(object_ptr result) { if (name == "group_anonymous_bot_user_id" && update->value_->get_id() == td_api::optionValueInteger::ID) { group_anonymous_bot_user_id_ = move_object_as(update->value_)->value_; } + if (name == "channel_bot_user_id" && update->value_->get_id() == td_api::optionValueInteger::ID) { + channel_bot_user_id_ = move_object_as(update->value_)->value_; + } if (name == "telegram_service_notifications_chat_id" && update->value_->get_id() == td_api::optionValueInteger::ID) { service_notifications_user_id_ = move_object_as(update->value_)->value_; @@ -9536,33 +9539,6 @@ Client::FullMessageId Client::add_message(object_ptr &&message, message_info->media_album_id = message->media_album_id_; message_info->via_bot_user_id = message->via_bot_user_id_; - CHECK(message->sender_id_ != nullptr); - switch (message->sender_id_->get_id()) { - case td_api::messageSenderUser::ID: { - 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); - break; - } - case td_api::messageSenderChat::ID: { - auto sender_id = move_object_as(message->sender_id_); - message_info->sender_chat_id = sender_id->chat_id_; - - auto chat_type = get_chat_type(chat_id); - if (chat_type != ChatType::Channel) { - if (message_info->sender_chat_id == chat_id) { - message_info->sender_user_id = group_anonymous_bot_user_id_; - } else { - message_info->sender_user_id = service_notifications_user_id_; - } - CHECK(message_info->sender_user_id > 0); - } - break; - } - default: - UNREACHABLE(); - } - message_info->initial_chat_id = 0; message_info->initial_sender_user_id = 0; message_info->initial_sender_chat_id = 0; @@ -9611,6 +9587,35 @@ Client::FullMessageId Client::add_message(object_ptr &&message, get_chat_type(chat_id) == ChatType::Supergroup && get_chat_type(from_chat_id) == ChatType::Channel; } + CHECK(message->sender_id_ != nullptr); + switch (message->sender_id_->get_id()) { + case td_api::messageSenderUser::ID: { + 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); + break; + } + case td_api::messageSenderChat::ID: { + auto sender_id = move_object_as(message->sender_id_); + message_info->sender_chat_id = sender_id->chat_id_; + + auto chat_type = get_chat_type(chat_id); + if (chat_type != ChatType::Channel) { + if (message_info->sender_chat_id == chat_id) { + message_info->sender_user_id = group_anonymous_bot_user_id_; + } else if (message_info->is_automatic_forward) { + message_info->sender_user_id = service_notifications_user_id_; + } else { + message_info->sender_user_id = channel_bot_user_id_; + } + CHECK(message_info->sender_user_id > 0); + } + break; + } + default: + UNREACHABLE(); + } + message_info->can_be_saved = message->can_be_saved_; message_info->author_signature = std::move(message->author_signature_); diff --git a/telegram-bot-api/Client.h b/telegram-bot-api/Client.h index 5df4572..7468ab0 100644 --- a/telegram-bot-api/Client.h +++ b/telegram-bot-api/Client.h @@ -866,6 +866,7 @@ class Client : public WebhookActor::Callback { int32 authorization_date_ = -1; int64 group_anonymous_bot_user_id_ = 0; + int64 channel_bot_user_id_ = 0; int64 service_notifications_user_id_ = 0; static std::unordered_map methods_; From 90f52477814a2d8a08c9ffb1d780fd179815d715 Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 9 Dec 2021 19:06:22 +0300 Subject: [PATCH 4/4] Update version to 5.5.1. --- CMakeLists.txt | 2 +- telegram-bot-api/telegram-bot-api.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5709f9a..8c5a221 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,7 +6,7 @@ if (POLICY CMP0065) cmake_policy(SET CMP0065 NEW) endif() -project(TelegramBotApi VERSION 5.5 LANGUAGES CXX) +project(TelegramBotApi VERSION 5.5.1 LANGUAGES CXX) if (POLICY CMP0069) option(TELEGRAM_BOT_API_ENABLE_LTO "Use \"ON\" to enable Link Time Optimization.") diff --git a/telegram-bot-api/telegram-bot-api.cpp b/telegram-bot-api/telegram-bot-api.cpp index 8d527ac..f850db3 100644 --- a/telegram-bot-api/telegram-bot-api.cpp +++ b/telegram-bot-api/telegram-bot-api.cpp @@ -200,7 +200,7 @@ int main(int argc, char *argv[]) { auto start_time = td::Time::now(); auto shared_data = std::make_shared(); auto parameters = std::make_unique(); - parameters->version_ = "5.5"; + parameters->version_ = "5.5.1"; parameters->shared_data_ = shared_data; parameters->start_time_ = start_time; auto net_query_stats = td::create_net_query_stats();