Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
giuseppeM99 committed Dec 9, 2021
2 parents 9a1b509 + 90f5247 commit 768793e
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 33 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand Down
66 changes: 36 additions & 30 deletions telegram-bot-api/Client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5110,6 +5110,9 @@ void Client::on_update(object_ptr<td_api::Object> result) {
if (name == "group_anonymous_bot_user_id" && update->value_->get_id() == td_api::optionValueInteger::ID) {
group_anonymous_bot_user_id_ = move_object_as<td_api::optionValueInteger>(update->value_)->value_;
}
if (name == "channel_bot_user_id" && update->value_->get_id() == td_api::optionValueInteger::ID) {
channel_bot_user_id_ = move_object_as<td_api::optionValueInteger>(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<td_api::optionValueInteger>(update->value_)->value_;
Expand Down Expand Up @@ -10887,33 +10890,6 @@ Client::FullMessageId Client::add_message(object_ptr<td_api::message> &&message,
message_info->via_bot_user_id = message->via_bot_user_id_;
message_info->message_thread_id = message->message_thread_id_;

CHECK(message->sender_id_ != nullptr);
switch (message->sender_id_->get_id()) {
case td_api::messageSenderUser::ID: {
auto sender_id = move_object_as<td_api::messageSenderUser>(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<td_api::messageSenderChat>(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;
Expand Down Expand Up @@ -10956,9 +10932,39 @@ Client::FullMessageId Client::add_message(object_ptr<td_api::message> &&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;
}

CHECK(message->sender_id_ != nullptr);
switch (message->sender_id_->get_id()) {
case td_api::messageSenderUser::ID: {
auto sender_id = move_object_as<td_api::messageSenderUser>(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<td_api::messageSenderChat>(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();
}

if (message->interaction_info_ != nullptr) {
Expand Down
1 change: 1 addition & 0 deletions telegram-bot-api/Client.h
Original file line number Diff line number Diff line change
Expand Up @@ -990,6 +990,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<td::string, Status (Client::*)(PromisedQueryPtr &query)> methods_;
Expand Down
2 changes: 1 addition & 1 deletion telegram-bot-api/telegram-bot-api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ int main(int argc, char *argv[]) {
auto start_time = td::Time::now();
auto shared_data = std::make_shared<SharedData>();
auto parameters = std::make_unique<ClientParameters>();
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();
Expand Down

0 comments on commit 768793e

Please sign in to comment.