Simplify NetQuery creation in SecretChatActor.
GitOrigin-RevId: a6d00cb5175552f9aa6dc7b38462fc00eb5b78f7
This commit is contained in:
parent
ad3c28932b
commit
0d08895871
@ -68,6 +68,12 @@ SecretChatActor::SecretChatActor(int32 id, unique_ptr<Context> context, bool can
|
||||
auth_state_.id = id;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
NetQueryPtr SecretChatActor::create_net_query(QueryType type, const T &function) {
|
||||
return context_->net_query_creator().create(UniqueId::next(UniqueId::Type::Default, static_cast<uint8>(type)),
|
||||
create_storer(function));
|
||||
}
|
||||
|
||||
void SecretChatActor::update_chat(telegram_api::object_ptr<telegram_api::EncryptedChat> chat) {
|
||||
if (close_flag_) {
|
||||
return;
|
||||
@ -358,9 +364,8 @@ void SecretChatActor::send_message_action(tl_object_ptr<secret_api::SendMessageA
|
||||
}
|
||||
bool flag = action->get_id() != secret_api::sendMessageCancelAction::ID;
|
||||
|
||||
auto net_query = context_->net_query_creator().create(
|
||||
UniqueId::next(UniqueId::Type::Default, static_cast<uint8>(QueryType::Ignore)),
|
||||
create_storer(telegram_api::messages_setEncryptedTyping(get_input_chat(), flag)));
|
||||
auto net_query =
|
||||
create_net_query(QueryType::Ignore, telegram_api::messages_setEncryptedTyping(get_input_chat(), flag));
|
||||
if (!set_typing_query_.empty()) {
|
||||
LOG(INFO) << "Cancel previous set typing query";
|
||||
cancel_query(set_typing_query_);
|
||||
@ -390,9 +395,8 @@ void SecretChatActor::send_read_history(int32 date, Promise<> promise) {
|
||||
cancel_query(read_history_query_);
|
||||
}
|
||||
|
||||
auto net_query = context_->net_query_creator().create(
|
||||
UniqueId::next(UniqueId::Type::Default, static_cast<uint8>(QueryType::ReadHistory)),
|
||||
create_storer(telegram_api::messages_readEncryptedHistory(get_input_chat(), date)));
|
||||
auto net_query =
|
||||
create_net_query(QueryType::ReadHistory, telegram_api::messages_readEncryptedHistory(get_input_chat(), date));
|
||||
read_history_query_ = net_query.get_weak();
|
||||
last_read_history_date_ = date;
|
||||
read_history_promise_ = std::move(promise);
|
||||
@ -566,11 +570,10 @@ Status SecretChatActor::run_auth() {
|
||||
return Status::OK();
|
||||
}
|
||||
// messages.requestEncryption#f64daf43 user_id:InputUser random_id:int g_a:bytes = EncryptedChat;
|
||||
telegram_api::messages_requestEncryption tl_query(get_input_user(), auth_state_.random_id,
|
||||
BufferSlice(auth_state_.handshake.get_g_b()));
|
||||
auto query = context_->net_query_creator().create(
|
||||
UniqueId::next(UniqueId::Type::Default, static_cast<uint8>(QueryType::EncryptedChat)),
|
||||
create_storer(tl_query));
|
||||
;
|
||||
auto query = create_net_query(QueryType::EncryptedChat, telegram_api::messages_requestEncryption(
|
||||
get_input_user(), auth_state_.random_id,
|
||||
BufferSlice(auth_state_.handshake.get_g_b())));
|
||||
context_->send_net_query(std::move(query), actor_shared(this), false);
|
||||
auth_state_.state = State::WaitRequestResponse;
|
||||
return Status::OK();
|
||||
@ -584,11 +587,10 @@ Status SecretChatActor::run_auth() {
|
||||
pfs_state_.auth_key = mtproto::AuthKey(id_and_key.first, std::move(id_and_key.second));
|
||||
calc_key_hash();
|
||||
// messages.acceptEncryption#3dbc0415 peer:InputEncryptedChat g_b:bytes key_fingerprint:long = EncryptedChat;
|
||||
telegram_api::messages_acceptEncryption tl_query(get_input_chat(), BufferSlice(auth_state_.handshake.get_g_b()),
|
||||
pfs_state_.auth_key.id());
|
||||
auto query = context_->net_query_creator().create(
|
||||
UniqueId::next(UniqueId::Type::Default, static_cast<uint8>(QueryType::EncryptedChat)),
|
||||
create_storer(tl_query));
|
||||
auto query = create_net_query(
|
||||
QueryType::EncryptedChat,
|
||||
telegram_api::messages_acceptEncryption(get_input_chat(), BufferSlice(auth_state_.handshake.get_g_b()),
|
||||
pfs_state_.auth_key.id()));
|
||||
context_->send_net_query(std::move(query), actor_shared(this), false);
|
||||
auth_state_.state = State::WaitAcceptResponse;
|
||||
return Status::OK();
|
||||
@ -756,10 +758,8 @@ void SecretChatActor::do_close_chat_impl(unique_ptr<logevent::CloseSecretChat> e
|
||||
context_->secret_chat_db()->erase_value(config_state_);
|
||||
context_->secret_chat_db()->erase_value(pfs_state_);
|
||||
context_->secret_chat_db()->erase_value(seq_no_state_);
|
||||
telegram_api::messages_discardEncryption tl_query(auth_state_.id);
|
||||
auto query = context_->net_query_creator().create(
|
||||
UniqueId::next(UniqueId::Type::Default, static_cast<uint8>(QueryType::DiscardEncryption)),
|
||||
create_storer(tl_query));
|
||||
;
|
||||
auto query = create_net_query(QueryType::DiscardEncryption, telegram_api::messages_discardEncryption(auth_state_.id));
|
||||
|
||||
send_update_secret_chat();
|
||||
|
||||
@ -1464,22 +1464,19 @@ NetQueryPtr SecretChatActor::create_net_query(const logevent::OutboundSecretMess
|
||||
NetQueryPtr query;
|
||||
if (message.is_service) {
|
||||
CHECK(message.file.empty());
|
||||
query = context_->net_query_creator().create(
|
||||
UniqueId::next(UniqueId::Type::Default, static_cast<uint8>(QueryType::Message)),
|
||||
create_storer(telegram_api::messages_sendEncryptedService(get_input_chat(), message.random_id,
|
||||
message.encrypted_message.clone())));
|
||||
query->total_timeout_limit = 1000000000; // inf. We will re-sent it immediately anyway.
|
||||
query = create_net_query(QueryType::Message,
|
||||
telegram_api::messages_sendEncryptedService(get_input_chat(), message.random_id,
|
||||
message.encrypted_message.clone()));
|
||||
query->total_timeout_limit = 1000000000; // inf. We will re-sent it immediately anyway
|
||||
} else if (message.file.empty()) {
|
||||
query = context_->net_query_creator().create(
|
||||
UniqueId::next(UniqueId::Type::Default, static_cast<uint8>(QueryType::Message)),
|
||||
create_storer(telegram_api::messages_sendEncrypted(get_input_chat(), message.random_id,
|
||||
message.encrypted_message.clone())));
|
||||
query = create_net_query(
|
||||
QueryType::Message,
|
||||
telegram_api::messages_sendEncrypted(get_input_chat(), message.random_id, message.encrypted_message.clone()));
|
||||
} else {
|
||||
query = context_->net_query_creator().create(
|
||||
UniqueId::next(UniqueId::Type::Default, static_cast<uint8>(QueryType::Message)),
|
||||
create_storer(telegram_api::messages_sendEncryptedFile(get_input_chat(), message.random_id,
|
||||
message.encrypted_message.clone(),
|
||||
message.file.as_input_encrypted_file())));
|
||||
query = create_net_query(
|
||||
QueryType::Message,
|
||||
telegram_api::messages_sendEncryptedFile(get_input_chat(), message.random_id, message.encrypted_message.clone(),
|
||||
message.file.as_input_encrypted_file()));
|
||||
}
|
||||
if (message.is_external && context_->get_config_option_boolean("use_quick_ack")) {
|
||||
query->quick_ack_promise_ =
|
||||
@ -1964,11 +1961,8 @@ void SecretChatActor::get_dh_config() {
|
||||
}
|
||||
|
||||
auto version = auth_state_.dh_config.version;
|
||||
int random_length = 0;
|
||||
telegram_api::messages_getDhConfig tl_query(version, random_length);
|
||||
|
||||
auto query = context_->net_query_creator().create(
|
||||
UniqueId::next(UniqueId::Type::Default, static_cast<uint8>(QueryType::DhConfig)), create_storer(tl_query));
|
||||
int32 random_length = 0;
|
||||
auto query = create_net_query(QueryType::DhConfig, telegram_api::messages_getDhConfig(version, random_length));
|
||||
context_->send_net_query(std::move(query), actor_shared(this), false);
|
||||
}
|
||||
|
||||
|
@ -18,6 +18,7 @@
|
||||
#include "td/telegram/DhConfig.h"
|
||||
#include "td/telegram/logevent/SecretChatEvent.h"
|
||||
#include "td/telegram/MessageId.h"
|
||||
#include "td/telegram/net/NetQuery.h"
|
||||
#include "td/telegram/SecretChatDb.h"
|
||||
#include "td/telegram/SecretChatId.h"
|
||||
#include "td/telegram/UserId.h"
|
||||
@ -30,6 +31,7 @@
|
||||
#include "td/utils/port/Clocks.h"
|
||||
#include "td/utils/Slice.h"
|
||||
#include "td/utils/Status.h"
|
||||
#include "td/utils/StorerBase.h"
|
||||
#include "td/utils/StringBuilder.h"
|
||||
#include "td/utils/Time.h"
|
||||
#include "td/utils/tl_helpers.h"
|
||||
@ -589,6 +591,9 @@ class SecretChatActor : public NetQueryCallback {
|
||||
int32 last_read_history_date_ = -1;
|
||||
Promise<Unit> read_history_promise_;
|
||||
|
||||
template <class T>
|
||||
NetQueryPtr create_net_query(QueryType type, const T &function);
|
||||
|
||||
enum SendFlag : int32 {
|
||||
None = 0,
|
||||
External = 1,
|
||||
|
Loading…
Reference in New Issue
Block a user