diff --git a/td/telegram/CallActor.cpp b/td/telegram/CallActor.cpp index 9e330f54d..1ff807884 100644 --- a/td/telegram/CallActor.cpp +++ b/td/telegram/CallActor.cpp @@ -17,7 +17,6 @@ #include "td/telegram/net/NetQueryDispatcher.h" #include "td/telegram/NotificationManager.h" #include "td/telegram/Td.h" -#include "td/telegram/telegram_api.hpp" #include "td/telegram/UpdatesManager.h" #include "td/utils/algorithm.h" @@ -475,8 +474,25 @@ void CallActor::on_save_log_query_result(FileId file_id, Promise promise, // Requests void CallActor::update_call(tl_object_ptr call) { LOG(INFO) << "Receive " << to_string(call); - Status status; - downcast_call(*call, [&](auto &call) { status = this->do_update_call(call); }); + auto status = [&] { + switch (call->get_id()) { + case telegram_api::phoneCallEmpty::ID: + return do_update_call(static_cast(*call)); + case telegram_api::phoneCallWaiting::ID: + return do_update_call(static_cast(*call)); + case telegram_api::phoneCallRequested::ID: + return do_update_call(static_cast(*call)); + case telegram_api::phoneCallAccepted::ID: + return do_update_call(static_cast(*call)); + case telegram_api::phoneCall::ID: + return do_update_call(static_cast(*call)); + case telegram_api::phoneCallDiscarded::ID: + return do_update_call(static_cast(*call)); + default: + UNREACHABLE(); + return Status::OK(); + } + }(); if (status.is_error()) { LOG(INFO) << "Receive error " << status << ", while handling update " << to_string(call); on_error(std::move(status)); diff --git a/td/telegram/CallManager.cpp b/td/telegram/CallManager.cpp index aa2c907c7..3f61c0946 100644 --- a/td/telegram/CallManager.cpp +++ b/td/telegram/CallManager.cpp @@ -6,8 +6,6 @@ // #include "td/telegram/CallManager.h" -#include "td/telegram/telegram_api.hpp" - #include "td/utils/common.h" #include "td/utils/logging.h" #include "td/utils/misc.h" @@ -21,8 +19,25 @@ CallManager::CallManager(ActorShared<> parent) : parent_(std::move(parent)) { } void CallManager::update_call(Update call) { - int64 call_id = 0; - downcast_call(*call->phone_call_, [&](auto &update) { call_id = update.id_; }); + auto call_id = [phone_call = call->phone_call_.get()] { + switch (phone_call->get_id()) { + case telegram_api::phoneCallEmpty::ID: + return static_cast(phone_call)->id_; + case telegram_api::phoneCallWaiting::ID: + return static_cast(phone_call)->id_; + case telegram_api::phoneCallRequested::ID: + return static_cast(phone_call)->id_; + case telegram_api::phoneCallAccepted::ID: + return static_cast(phone_call)->id_; + case telegram_api::phoneCall::ID: + return static_cast(phone_call)->id_; + case telegram_api::phoneCallDiscarded::ID: + return static_cast(phone_call)->id_; + default: + UNREACHABLE(); + return static_cast(0); + } + }(); LOG(DEBUG) << "Receive UpdateCall for " << call_id; auto &info = call_info_[call_id]; diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index 52b52c68f..1835b315e 100644 --- a/td/telegram/ContactsManager.cpp +++ b/td/telegram/ContactsManager.cpp @@ -49,7 +49,6 @@ #include "td/telegram/StoryManager.h" #include "td/telegram/Td.h" #include "td/telegram/TdDb.h" -#include "td/telegram/telegram_api.hpp" #include "td/telegram/UpdatesManager.h" #include "td/telegram/Version.h" @@ -12750,7 +12749,25 @@ void ContactsManager::on_get_user_photos(UserId user_id, int32 offset, int32 lim void ContactsManager::on_get_chat(tl_object_ptr &&chat, const char *source) { LOG(DEBUG) << "Receive from " << source << ' ' << to_string(chat); - downcast_call(*chat, [this, source](auto &c) { this->on_chat_update(c, source); }); + switch (chat->get_id()) { + case telegram_api::chatEmpty::ID: + on_chat_update(static_cast(*chat), source); + break; + case telegram_api::chat::ID: + on_chat_update(static_cast(*chat), source); + break; + case telegram_api::chatForbidden::ID: + on_chat_update(static_cast(*chat), source); + break; + case telegram_api::channel::ID: + on_chat_update(static_cast(*chat), source); + break; + case telegram_api::channelForbidden::ID: + on_chat_update(static_cast(*chat), source); + break; + default: + UNREACHABLE(); + } } void ContactsManager::on_get_chats(vector> &&chats, const char *source) { diff --git a/td/telegram/InlineQueriesManager.cpp b/td/telegram/InlineQueriesManager.cpp index 85ddfa40f..98d461119 100644 --- a/td/telegram/InlineQueriesManager.cpp +++ b/td/telegram/InlineQueriesManager.cpp @@ -36,7 +36,6 @@ #include "td/telegram/Td.h" #include "td/telegram/td_api.hpp" #include "td/telegram/TdDb.h" -#include "td/telegram/telegram_api.hpp" #include "td/telegram/ThemeManager.h" #include "td/telegram/UpdatesManager.h" #include "td/telegram/Venue.h" @@ -1856,9 +1855,17 @@ void InlineQueriesManager::on_get_inline_query_results(DialogId dialog_id, UserI continue; } - vector> attributes; - downcast_call(*result->content_, - [&attributes](auto &web_document) { attributes = std::move(web_document.attributes_); }); + auto attributes = [content = result->content_.get()] { + switch (content->get_id()) { + case telegram_api::webDocument::ID: + return std::move(static_cast(content)->attributes_); + case telegram_api::webDocumentNoProxy::ID: + return std::move(static_cast(content)->attributes_); + default: + UNREACHABLE(); + return vector>(); + } + }(); bool is_animation = result->type_ == "gif" && (content_type == "image/gif" || content_type == "video/mp4"); if (is_animation) { diff --git a/td/telegram/SecretChatsManager.cpp b/td/telegram/SecretChatsManager.cpp index 47e7911c1..5bbeb1d4f 100644 --- a/td/telegram/SecretChatsManager.cpp +++ b/td/telegram/SecretChatsManager.cpp @@ -18,7 +18,6 @@ #include "td/telegram/SequenceDispatcher.h" #include "td/telegram/StateManager.h" #include "td/telegram/TdDb.h" -#include "td/telegram/telegram_api.hpp" #include "td/mtproto/DhCallback.h" @@ -181,12 +180,24 @@ void SecretChatsManager::on_update_chat(tl_object_ptr update) { - int32 id = 0; - downcast_call(*update->chat_, [&](auto &x) { id = x.id_; }); - - send_closure( - update->chat_->get_id() == telegram_api::encryptedChatDiscarded::ID ? get_chat_actor(id) : create_chat_actor(id), - &SecretChatActor::update_chat, std::move(update->chat_)); + auto actor_id = [this, chat = update->chat_.get()] { + switch (chat->get_id()) { + case telegram_api::encryptedChatEmpty::ID: + return create_chat_actor(static_cast(chat)->id_); + case telegram_api::encryptedChatWaiting::ID: + return create_chat_actor(static_cast(chat)->id_); + case telegram_api::encryptedChatRequested::ID: + return create_chat_actor(static_cast(chat)->id_); + case telegram_api::encryptedChat::ID: + return create_chat_actor(static_cast(chat)->id_); + case telegram_api::encryptedChatDiscarded::ID: + return get_chat_actor(static_cast(chat)->id_); + default: + UNREACHABLE(); + return ActorId(); + } + }(); + send_closure(actor_id, &SecretChatActor::update_chat, std::move(update->chat_)); } void SecretChatsManager::on_new_message(tl_object_ptr &&message_ptr, @@ -198,14 +209,24 @@ void SecretChatsManager::on_new_message(tl_object_ptr(); event->promise = std::move(promise); - downcast_call(*message_ptr, [&](auto &x) { - event->chat_id = x.chat_id_; - event->date = x.date_; - event->encrypted_message = std::move(x.bytes_); - }); - if (message_ptr->get_id() == telegram_api::encryptedMessage::ID) { - auto message = move_tl_object_as(message_ptr); - event->file = EncryptedFile::get_encrypted_file(std::move(message->file_)); + switch (message_ptr->get_id()) { + case telegram_api::encryptedMessage::ID: { + auto message = telegram_api::move_object_as(message_ptr); + event->chat_id = message->chat_id_; + event->date = message->date_; + event->encrypted_message = std::move(message->bytes_); + event->file = EncryptedFile::get_encrypted_file(std::move(message->file_)); + break; + } + case telegram_api::encryptedMessageService::ID: { + auto message = telegram_api::move_object_as(message_ptr); + event->chat_id = message->chat_id_; + event->date = message->date_; + event->encrypted_message = std::move(message->bytes_); + break; + } + default: + UNREACHABLE(); } add_inbound_message(std::move(event)); } diff --git a/td/telegram/SecureValue.cpp b/td/telegram/SecureValue.cpp index 402a4101e..6c7c79a4b 100644 --- a/td/telegram/SecureValue.cpp +++ b/td/telegram/SecureValue.cpp @@ -15,7 +15,6 @@ #include "td/telegram/misc.h" #include "td/telegram/net/DcId.h" #include "td/telegram/OrderInfo.h" -#include "td/telegram/telegram_api.hpp" #include "td/utils/algorithm.h" #include "td/utils/base64.h" @@ -24,7 +23,6 @@ #include "td/utils/JsonBuilder.h" #include "td/utils/logging.h" #include "td/utils/misc.h" -#include "td/utils/overloaded.h" #include "td/utils/SliceBuilder.h" #include "td/utils/utf8.h" @@ -399,12 +397,10 @@ telegram_api::object_ptr get_input_secure_file_ob if (res == nullptr) { return file_manager->get_file_view(file.file.file_id).remote_location().as_input_secure_file(); } - telegram_api::downcast_call(*res, overloaded( - [&](telegram_api::inputSecureFileUploaded &uploaded) { - uploaded.secret_ = BufferSlice(file.encrypted_secret); - uploaded.file_hash_ = BufferSlice(file.file_hash); - }, - [&](telegram_api::inputSecureFile &) { UNREACHABLE(); })); + CHECK(res->get_id() == telegram_api::inputSecureFileUploaded::ID); + auto uploaded = static_cast(res.get()); + uploaded->secret_ = BufferSlice(file.encrypted_secret); + uploaded->file_hash_ = BufferSlice(file.file_hash); return res; }