Don't use downcast_call in simple cases.
This commit is contained in:
parent
6702a001f0
commit
d67d93e5af
@ -17,7 +17,6 @@
|
|||||||
#include "td/telegram/net/NetQueryDispatcher.h"
|
#include "td/telegram/net/NetQueryDispatcher.h"
|
||||||
#include "td/telegram/NotificationManager.h"
|
#include "td/telegram/NotificationManager.h"
|
||||||
#include "td/telegram/Td.h"
|
#include "td/telegram/Td.h"
|
||||||
#include "td/telegram/telegram_api.hpp"
|
|
||||||
#include "td/telegram/UpdatesManager.h"
|
#include "td/telegram/UpdatesManager.h"
|
||||||
|
|
||||||
#include "td/utils/algorithm.h"
|
#include "td/utils/algorithm.h"
|
||||||
@ -475,8 +474,25 @@ void CallActor::on_save_log_query_result(FileId file_id, Promise<Unit> promise,
|
|||||||
// Requests
|
// Requests
|
||||||
void CallActor::update_call(tl_object_ptr<telegram_api::PhoneCall> call) {
|
void CallActor::update_call(tl_object_ptr<telegram_api::PhoneCall> call) {
|
||||||
LOG(INFO) << "Receive " << to_string(call);
|
LOG(INFO) << "Receive " << to_string(call);
|
||||||
Status status;
|
auto status = [&] {
|
||||||
downcast_call(*call, [&](auto &call) { status = this->do_update_call(call); });
|
switch (call->get_id()) {
|
||||||
|
case telegram_api::phoneCallEmpty::ID:
|
||||||
|
return do_update_call(static_cast<telegram_api::phoneCallEmpty &>(*call));
|
||||||
|
case telegram_api::phoneCallWaiting::ID:
|
||||||
|
return do_update_call(static_cast<telegram_api::phoneCallWaiting &>(*call));
|
||||||
|
case telegram_api::phoneCallRequested::ID:
|
||||||
|
return do_update_call(static_cast<telegram_api::phoneCallRequested &>(*call));
|
||||||
|
case telegram_api::phoneCallAccepted::ID:
|
||||||
|
return do_update_call(static_cast<telegram_api::phoneCallAccepted &>(*call));
|
||||||
|
case telegram_api::phoneCall::ID:
|
||||||
|
return do_update_call(static_cast<telegram_api::phoneCall &>(*call));
|
||||||
|
case telegram_api::phoneCallDiscarded::ID:
|
||||||
|
return do_update_call(static_cast<telegram_api::phoneCallDiscarded &>(*call));
|
||||||
|
default:
|
||||||
|
UNREACHABLE();
|
||||||
|
return Status::OK();
|
||||||
|
}
|
||||||
|
}();
|
||||||
if (status.is_error()) {
|
if (status.is_error()) {
|
||||||
LOG(INFO) << "Receive error " << status << ", while handling update " << to_string(call);
|
LOG(INFO) << "Receive error " << status << ", while handling update " << to_string(call);
|
||||||
on_error(std::move(status));
|
on_error(std::move(status));
|
||||||
|
@ -6,8 +6,6 @@
|
|||||||
//
|
//
|
||||||
#include "td/telegram/CallManager.h"
|
#include "td/telegram/CallManager.h"
|
||||||
|
|
||||||
#include "td/telegram/telegram_api.hpp"
|
|
||||||
|
|
||||||
#include "td/utils/common.h"
|
#include "td/utils/common.h"
|
||||||
#include "td/utils/logging.h"
|
#include "td/utils/logging.h"
|
||||||
#include "td/utils/misc.h"
|
#include "td/utils/misc.h"
|
||||||
@ -21,8 +19,25 @@ CallManager::CallManager(ActorShared<> parent) : parent_(std::move(parent)) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void CallManager::update_call(Update call) {
|
void CallManager::update_call(Update call) {
|
||||||
int64 call_id = 0;
|
auto call_id = [phone_call = call->phone_call_.get()] {
|
||||||
downcast_call(*call->phone_call_, [&](auto &update) { call_id = update.id_; });
|
switch (phone_call->get_id()) {
|
||||||
|
case telegram_api::phoneCallEmpty::ID:
|
||||||
|
return static_cast<const telegram_api::phoneCallEmpty *>(phone_call)->id_;
|
||||||
|
case telegram_api::phoneCallWaiting::ID:
|
||||||
|
return static_cast<const telegram_api::phoneCallWaiting *>(phone_call)->id_;
|
||||||
|
case telegram_api::phoneCallRequested::ID:
|
||||||
|
return static_cast<const telegram_api::phoneCallRequested *>(phone_call)->id_;
|
||||||
|
case telegram_api::phoneCallAccepted::ID:
|
||||||
|
return static_cast<const telegram_api::phoneCallAccepted *>(phone_call)->id_;
|
||||||
|
case telegram_api::phoneCall::ID:
|
||||||
|
return static_cast<const telegram_api::phoneCall *>(phone_call)->id_;
|
||||||
|
case telegram_api::phoneCallDiscarded::ID:
|
||||||
|
return static_cast<const telegram_api::phoneCallDiscarded *>(phone_call)->id_;
|
||||||
|
default:
|
||||||
|
UNREACHABLE();
|
||||||
|
return static_cast<int64>(0);
|
||||||
|
}
|
||||||
|
}();
|
||||||
LOG(DEBUG) << "Receive UpdateCall for " << call_id;
|
LOG(DEBUG) << "Receive UpdateCall for " << call_id;
|
||||||
|
|
||||||
auto &info = call_info_[call_id];
|
auto &info = call_info_[call_id];
|
||||||
|
@ -49,7 +49,6 @@
|
|||||||
#include "td/telegram/StoryManager.h"
|
#include "td/telegram/StoryManager.h"
|
||||||
#include "td/telegram/Td.h"
|
#include "td/telegram/Td.h"
|
||||||
#include "td/telegram/TdDb.h"
|
#include "td/telegram/TdDb.h"
|
||||||
#include "td/telegram/telegram_api.hpp"
|
|
||||||
#include "td/telegram/UpdatesManager.h"
|
#include "td/telegram/UpdatesManager.h"
|
||||||
#include "td/telegram/Version.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<telegram_api::Chat> &&chat, const char *source) {
|
void ContactsManager::on_get_chat(tl_object_ptr<telegram_api::Chat> &&chat, const char *source) {
|
||||||
LOG(DEBUG) << "Receive from " << source << ' ' << to_string(chat);
|
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<telegram_api::chatEmpty &>(*chat), source);
|
||||||
|
break;
|
||||||
|
case telegram_api::chat::ID:
|
||||||
|
on_chat_update(static_cast<telegram_api::chat &>(*chat), source);
|
||||||
|
break;
|
||||||
|
case telegram_api::chatForbidden::ID:
|
||||||
|
on_chat_update(static_cast<telegram_api::chatForbidden &>(*chat), source);
|
||||||
|
break;
|
||||||
|
case telegram_api::channel::ID:
|
||||||
|
on_chat_update(static_cast<telegram_api::channel &>(*chat), source);
|
||||||
|
break;
|
||||||
|
case telegram_api::channelForbidden::ID:
|
||||||
|
on_chat_update(static_cast<telegram_api::channelForbidden &>(*chat), source);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
UNREACHABLE();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ContactsManager::on_get_chats(vector<tl_object_ptr<telegram_api::Chat>> &&chats, const char *source) {
|
void ContactsManager::on_get_chats(vector<tl_object_ptr<telegram_api::Chat>> &&chats, const char *source) {
|
||||||
|
@ -36,7 +36,6 @@
|
|||||||
#include "td/telegram/Td.h"
|
#include "td/telegram/Td.h"
|
||||||
#include "td/telegram/td_api.hpp"
|
#include "td/telegram/td_api.hpp"
|
||||||
#include "td/telegram/TdDb.h"
|
#include "td/telegram/TdDb.h"
|
||||||
#include "td/telegram/telegram_api.hpp"
|
|
||||||
#include "td/telegram/ThemeManager.h"
|
#include "td/telegram/ThemeManager.h"
|
||||||
#include "td/telegram/UpdatesManager.h"
|
#include "td/telegram/UpdatesManager.h"
|
||||||
#include "td/telegram/Venue.h"
|
#include "td/telegram/Venue.h"
|
||||||
@ -1856,9 +1855,17 @@ void InlineQueriesManager::on_get_inline_query_results(DialogId dialog_id, UserI
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
vector<tl_object_ptr<telegram_api::DocumentAttribute>> attributes;
|
auto attributes = [content = result->content_.get()] {
|
||||||
downcast_call(*result->content_,
|
switch (content->get_id()) {
|
||||||
[&attributes](auto &web_document) { attributes = std::move(web_document.attributes_); });
|
case telegram_api::webDocument::ID:
|
||||||
|
return std::move(static_cast<telegram_api::webDocument *>(content)->attributes_);
|
||||||
|
case telegram_api::webDocumentNoProxy::ID:
|
||||||
|
return std::move(static_cast<telegram_api::webDocumentNoProxy *>(content)->attributes_);
|
||||||
|
default:
|
||||||
|
UNREACHABLE();
|
||||||
|
return vector<telegram_api::object_ptr<telegram_api::DocumentAttribute>>();
|
||||||
|
}
|
||||||
|
}();
|
||||||
|
|
||||||
bool is_animation = result->type_ == "gif" && (content_type == "image/gif" || content_type == "video/mp4");
|
bool is_animation = result->type_ == "gif" && (content_type == "image/gif" || content_type == "video/mp4");
|
||||||
if (is_animation) {
|
if (is_animation) {
|
||||||
|
@ -18,7 +18,6 @@
|
|||||||
#include "td/telegram/SequenceDispatcher.h"
|
#include "td/telegram/SequenceDispatcher.h"
|
||||||
#include "td/telegram/StateManager.h"
|
#include "td/telegram/StateManager.h"
|
||||||
#include "td/telegram/TdDb.h"
|
#include "td/telegram/TdDb.h"
|
||||||
#include "td/telegram/telegram_api.hpp"
|
|
||||||
|
|
||||||
#include "td/mtproto/DhCallback.h"
|
#include "td/mtproto/DhCallback.h"
|
||||||
|
|
||||||
@ -181,12 +180,24 @@ void SecretChatsManager::on_update_chat(tl_object_ptr<telegram_api::updateEncryp
|
|||||||
}
|
}
|
||||||
|
|
||||||
void SecretChatsManager::do_update_chat(tl_object_ptr<telegram_api::updateEncryption> update) {
|
void SecretChatsManager::do_update_chat(tl_object_ptr<telegram_api::updateEncryption> update) {
|
||||||
int32 id = 0;
|
auto actor_id = [this, chat = update->chat_.get()] {
|
||||||
downcast_call(*update->chat_, [&](auto &x) { id = x.id_; });
|
switch (chat->get_id()) {
|
||||||
|
case telegram_api::encryptedChatEmpty::ID:
|
||||||
send_closure(
|
return create_chat_actor(static_cast<const telegram_api::encryptedChatEmpty *>(chat)->id_);
|
||||||
update->chat_->get_id() == telegram_api::encryptedChatDiscarded::ID ? get_chat_actor(id) : create_chat_actor(id),
|
case telegram_api::encryptedChatWaiting::ID:
|
||||||
&SecretChatActor::update_chat, std::move(update->chat_));
|
return create_chat_actor(static_cast<const telegram_api::encryptedChatWaiting *>(chat)->id_);
|
||||||
|
case telegram_api::encryptedChatRequested::ID:
|
||||||
|
return create_chat_actor(static_cast<const telegram_api::encryptedChatRequested *>(chat)->id_);
|
||||||
|
case telegram_api::encryptedChat::ID:
|
||||||
|
return create_chat_actor(static_cast<const telegram_api::encryptedChat *>(chat)->id_);
|
||||||
|
case telegram_api::encryptedChatDiscarded::ID:
|
||||||
|
return get_chat_actor(static_cast<const telegram_api::encryptedChatDiscarded *>(chat)->id_);
|
||||||
|
default:
|
||||||
|
UNREACHABLE();
|
||||||
|
return ActorId<SecretChatActor>();
|
||||||
|
}
|
||||||
|
}();
|
||||||
|
send_closure(actor_id, &SecretChatActor::update_chat, std::move(update->chat_));
|
||||||
}
|
}
|
||||||
|
|
||||||
void SecretChatsManager::on_new_message(tl_object_ptr<telegram_api::EncryptedMessage> &&message_ptr,
|
void SecretChatsManager::on_new_message(tl_object_ptr<telegram_api::EncryptedMessage> &&message_ptr,
|
||||||
@ -198,14 +209,24 @@ void SecretChatsManager::on_new_message(tl_object_ptr<telegram_api::EncryptedMes
|
|||||||
|
|
||||||
auto event = make_unique<log_event::InboundSecretMessage>();
|
auto event = make_unique<log_event::InboundSecretMessage>();
|
||||||
event->promise = std::move(promise);
|
event->promise = std::move(promise);
|
||||||
downcast_call(*message_ptr, [&](auto &x) {
|
switch (message_ptr->get_id()) {
|
||||||
event->chat_id = x.chat_id_;
|
case telegram_api::encryptedMessage::ID: {
|
||||||
event->date = x.date_;
|
auto message = telegram_api::move_object_as<telegram_api::encryptedMessage>(message_ptr);
|
||||||
event->encrypted_message = std::move(x.bytes_);
|
event->chat_id = message->chat_id_;
|
||||||
});
|
event->date = message->date_;
|
||||||
if (message_ptr->get_id() == telegram_api::encryptedMessage::ID) {
|
event->encrypted_message = std::move(message->bytes_);
|
||||||
auto message = move_tl_object_as<telegram_api::encryptedMessage>(message_ptr);
|
event->file = EncryptedFile::get_encrypted_file(std::move(message->file_));
|
||||||
event->file = EncryptedFile::get_encrypted_file(std::move(message->file_));
|
break;
|
||||||
|
}
|
||||||
|
case telegram_api::encryptedMessageService::ID: {
|
||||||
|
auto message = telegram_api::move_object_as<telegram_api::encryptedMessageService>(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));
|
add_inbound_message(std::move(event));
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,6 @@
|
|||||||
#include "td/telegram/misc.h"
|
#include "td/telegram/misc.h"
|
||||||
#include "td/telegram/net/DcId.h"
|
#include "td/telegram/net/DcId.h"
|
||||||
#include "td/telegram/OrderInfo.h"
|
#include "td/telegram/OrderInfo.h"
|
||||||
#include "td/telegram/telegram_api.hpp"
|
|
||||||
|
|
||||||
#include "td/utils/algorithm.h"
|
#include "td/utils/algorithm.h"
|
||||||
#include "td/utils/base64.h"
|
#include "td/utils/base64.h"
|
||||||
@ -24,7 +23,6 @@
|
|||||||
#include "td/utils/JsonBuilder.h"
|
#include "td/utils/JsonBuilder.h"
|
||||||
#include "td/utils/logging.h"
|
#include "td/utils/logging.h"
|
||||||
#include "td/utils/misc.h"
|
#include "td/utils/misc.h"
|
||||||
#include "td/utils/overloaded.h"
|
|
||||||
#include "td/utils/SliceBuilder.h"
|
#include "td/utils/SliceBuilder.h"
|
||||||
#include "td/utils/utf8.h"
|
#include "td/utils/utf8.h"
|
||||||
|
|
||||||
@ -399,12 +397,10 @@ telegram_api::object_ptr<telegram_api::InputSecureFile> get_input_secure_file_ob
|
|||||||
if (res == nullptr) {
|
if (res == nullptr) {
|
||||||
return file_manager->get_file_view(file.file.file_id).remote_location().as_input_secure_file();
|
return file_manager->get_file_view(file.file.file_id).remote_location().as_input_secure_file();
|
||||||
}
|
}
|
||||||
telegram_api::downcast_call(*res, overloaded(
|
CHECK(res->get_id() == telegram_api::inputSecureFileUploaded::ID);
|
||||||
[&](telegram_api::inputSecureFileUploaded &uploaded) {
|
auto uploaded = static_cast<telegram_api::inputSecureFileUploaded *>(res.get());
|
||||||
uploaded.secret_ = BufferSlice(file.encrypted_secret);
|
uploaded->secret_ = BufferSlice(file.encrypted_secret);
|
||||||
uploaded.file_hash_ = BufferSlice(file.file_hash);
|
uploaded->file_hash_ = BufferSlice(file.file_hash);
|
||||||
},
|
|
||||||
[&](telegram_api::inputSecureFile &) { UNREACHABLE(); }));
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user