Pass UserId instead of int32 when creating secret chat.

This commit is contained in:
levlam 2021-03-29 11:57:26 +03:00
parent 5de3751d8d
commit c739df8507
7 changed files with 30 additions and 27 deletions

View File

@ -19334,8 +19334,8 @@ void MessagesManager::create_new_secret_chat(UserId user_id, Promise<SecretChatI
} }
auto user = move_tl_object_as<telegram_api::inputUser>(user_base); auto user = move_tl_object_as<telegram_api::inputUser>(user_base);
send_closure(G()->secret_chats_manager(), &SecretChatsManager::create_chat, user->user_id_, user->access_hash_, send_closure(G()->secret_chats_manager(), &SecretChatsManager::create_chat, UserId(user->user_id_),
std::move(promise)); user->access_hash_, std::move(promise));
} }
DialogId MessagesManager::migrate_dialog_to_megagroup(DialogId dialog_id, Promise<Unit> &&promise) { DialogId MessagesManager::migrate_dialog_to_megagroup(DialogId dialog_id, Promise<Unit> &&promise) {

View File

@ -83,7 +83,7 @@ void SecretChatActor::update_chat(telegram_api::object_ptr<telegram_api::Encrypt
loop(); loop();
} }
void SecretChatActor::create_chat(int32 user_id, int64 user_access_hash, int32 random_id, void SecretChatActor::create_chat(UserId user_id, int64 user_access_hash, int32 random_id,
Promise<SecretChatId> promise) { Promise<SecretChatId> promise) {
if (close_flag_) { if (close_flag_) {
promise.set_error(Status::Error(400, "Chat is closed")); promise.set_error(Status::Error(400, "Chat is closed"));
@ -826,7 +826,7 @@ void SecretChatActor::do_create_chat_impl(unique_ptr<log_event::CreateSecretChat
} }
telegram_api::object_ptr<telegram_api::inputUser> SecretChatActor::get_input_user() { telegram_api::object_ptr<telegram_api::inputUser> SecretChatActor::get_input_user() {
return telegram_api::make_object<telegram_api::inputUser>(auth_state_.user_id, auth_state_.user_access_hash); return telegram_api::make_object<telegram_api::inputUser>(auth_state_.user_id.get(), auth_state_.user_access_hash);
} }
telegram_api::object_ptr<telegram_api::inputEncryptedChat> SecretChatActor::get_input_chat() { telegram_api::object_ptr<telegram_api::inputEncryptedChat> SecretChatActor::get_input_chat() {
return telegram_api::make_object<telegram_api::inputEncryptedChat>(auth_state_.id, auth_state_.access_hash); return telegram_api::make_object<telegram_api::inputEncryptedChat>(auth_state_.id, auth_state_.access_hash);
@ -1869,7 +1869,7 @@ Status SecretChatActor::on_update_chat(telegram_api::encryptedChatRequested &upd
} }
auth_state_.state = State::SendAccept; auth_state_.state = State::SendAccept;
auth_state_.x = 1; auth_state_.x = 1;
auth_state_.user_id = update.admin_id_; auth_state_.user_id = UserId(update.admin_id_);
auth_state_.date = context_->unix_time(); auth_state_.date = context_->unix_time();
TRY_STATUS(save_common_info(update)); TRY_STATUS(save_common_info(update));
auth_state_.handshake.set_g_a(update.g_a_.as_slice()); auth_state_.handshake.set_g_a(update.g_a_.as_slice());

View File

@ -6,15 +6,6 @@
// //
#pragma once #pragma once
#include "td/telegram/secret_api.h"
#include "td/telegram/telegram_api.h"
#include "td/actor/actor.h"
#include "td/actor/PromiseFuture.h"
#include "td/mtproto/AuthKey.h"
#include "td/mtproto/DhHandshake.h"
#include "td/telegram/DhConfig.h" #include "td/telegram/DhConfig.h"
#include "td/telegram/FolderId.h" #include "td/telegram/FolderId.h"
#include "td/telegram/logevent/SecretChatEvent.h" #include "td/telegram/logevent/SecretChatEvent.h"
@ -22,8 +13,16 @@
#include "td/telegram/net/NetQuery.h" #include "td/telegram/net/NetQuery.h"
#include "td/telegram/SecretChatDb.h" #include "td/telegram/SecretChatDb.h"
#include "td/telegram/SecretChatId.h" #include "td/telegram/SecretChatId.h"
#include "td/telegram/secret_api.h"
#include "td/telegram/telegram_api.h"
#include "td/telegram/UserId.h" #include "td/telegram/UserId.h"
#include "td/mtproto/AuthKey.h"
#include "td/mtproto/DhHandshake.h"
#include "td/actor/actor.h"
#include "td/actor/PromiseFuture.h"
#include "td/utils/buffer.h" #include "td/utils/buffer.h"
#include "td/utils/ChangesProcessor.h" #include "td/utils/ChangesProcessor.h"
#include "td/utils/common.h" #include "td/utils/common.h"
@ -115,7 +114,7 @@ class SecretChatActor : public NetQueryCallback {
// First query to new chat must be one of these two // First query to new chat must be one of these two
void update_chat(telegram_api::object_ptr<telegram_api::EncryptedChat> chat); void update_chat(telegram_api::object_ptr<telegram_api::EncryptedChat> chat);
void create_chat(int32 user_id, int64 user_access_hash, int32 random_id, Promise<SecretChatId> promise); void create_chat(UserId user_id, int64 user_access_hash, int32 random_id, Promise<SecretChatId> promise);
void cancel_chat(bool delete_history, bool is_already_discarded, Promise<> promise); void cancel_chat(bool delete_history, bool is_already_discarded, Promise<> promise);
@ -374,7 +373,7 @@ class SecretChatActor : public NetQueryCallback {
int32 id = 0; int32 id = 0;
int64 access_hash = 0; int64 access_hash = 0;
int32 user_id = 0; UserId user_id;
int64 user_access_hash = 0; int64 user_access_hash = 0;
int32 random_id = 0; int32 random_id = 0;
@ -408,7 +407,7 @@ class SecretChatActor : public NetQueryCallback {
storer.store_int(id); storer.store_int(id);
storer.store_long(access_hash); storer.store_long(access_hash);
storer.store_int(user_id); storer.store_int(user_id.get());
storer.store_long(user_access_hash); storer.store_long(user_access_hash);
storer.store_int(random_id); storer.store_int(random_id);
if (has_date) { if (has_date) {
@ -439,7 +438,7 @@ class SecretChatActor : public NetQueryCallback {
id = parser.fetch_int(); id = parser.fetch_int();
access_hash = parser.fetch_long(); access_hash = parser.fetch_long();
user_id = parser.fetch_int(); user_id = UserId(parser.fetch_int());
user_access_hash = parser.fetch_long(); user_access_hash = parser.fetch_long();
random_id = parser.fetch_int(); random_id = parser.fetch_int();
if (has_date) { if (has_date) {
@ -701,7 +700,7 @@ class SecretChatActor : public NetQueryCallback {
return SecretChatId(auth_state_.id); return SecretChatId(auth_state_.id);
} }
UserId get_user_id() { UserId get_user_id() {
return UserId(auth_state_.user_id); return auth_state_.user_id;
} }
void send_update_ttl(int32 ttl); void send_update_ttl(int32 ttl);
void send_update_secret_chat(); void send_update_secret_chat();

View File

@ -96,7 +96,7 @@ void SecretChatsManager::start_up() {
send_closure(G()->state_manager(), &StateManager::add_callback, make_unique<StateCallback>(actor_id(this))); send_closure(G()->state_manager(), &StateManager::add_callback, make_unique<StateCallback>(actor_id(this)));
} }
void SecretChatsManager::create_chat(int32 user_id, int64 user_access_hash, Promise<SecretChatId> promise) { void SecretChatsManager::create_chat(UserId user_id, int64 user_access_hash, Promise<SecretChatId> promise) {
int32 random_id; int32 random_id;
ActorId<SecretChatActor> actor; ActorId<SecretChatActor> actor;
do { do {

View File

@ -9,6 +9,7 @@
#include "td/telegram/logevent/SecretChatEvent.h" #include "td/telegram/logevent/SecretChatEvent.h"
#include "td/telegram/SecretChatActor.h" #include "td/telegram/SecretChatActor.h"
#include "td/telegram/SecretChatId.h" #include "td/telegram/SecretChatId.h"
#include "td/telegram/UserId.h"
#include "td/telegram/secret_api.h" #include "td/telegram/secret_api.h"
#include "td/telegram/telegram_api.h" #include "td/telegram/telegram_api.h"
@ -34,7 +35,7 @@ class SecretChatsManager : public Actor {
void on_update_chat(tl_object_ptr<telegram_api::updateEncryption> update); void on_update_chat(tl_object_ptr<telegram_api::updateEncryption> update);
void on_new_message(tl_object_ptr<telegram_api::EncryptedMessage> &&message_ptr, Promise<Unit> &&promise); void on_new_message(tl_object_ptr<telegram_api::EncryptedMessage> &&message_ptr, Promise<Unit> &&promise);
void create_chat(int32 user_id, int64 user_access_hash, Promise<SecretChatId> promise); void create_chat(UserId user_id, int64 user_access_hash, Promise<SecretChatId> promise);
void cancel_chat(SecretChatId secret_chat_id, bool delete_history, Promise<> promise); void cancel_chat(SecretChatId secret_chat_id, bool delete_history, Promise<> promise);
void send_message(SecretChatId secret_chat_id, tl_object_ptr<secret_api::decryptedMessage> message, void send_message(SecretChatId secret_chat_id, tl_object_ptr<secret_api::decryptedMessage> message,
tl_object_ptr<telegram_api::InputEncryptedFile> file, Promise<> promise); tl_object_ptr<telegram_api::InputEncryptedFile> file, Promise<> promise);

View File

@ -18,6 +18,7 @@
#include "td/telegram/secret_api.h" #include "td/telegram/secret_api.h"
#include "td/telegram/telegram_api.h" #include "td/telegram/telegram_api.h"
#include "td/telegram/UserId.h"
namespace td { namespace td {
namespace log_event { namespace log_event {
@ -445,14 +446,14 @@ class CreateSecretChat : public SecretChatLogEventBase<CreateSecretChat> {
public: public:
static constexpr Type type = SecretChatEvent::Type::CreateSecretChat; static constexpr Type type = SecretChatEvent::Type::CreateSecretChat;
int32 random_id = 0; int32 random_id = 0;
int32 user_id = 0; UserId user_id;
int64 user_access_hash = 0; int64 user_access_hash = 0;
template <class StorerT> template <class StorerT>
void store(StorerT &storer) const { void store(StorerT &storer) const {
using td::store; using td::store;
store(random_id, storer); store(random_id, storer);
store(user_id, storer); store(user_id.get(), storer);
store(user_access_hash, storer); store(user_access_hash, storer);
} }
@ -460,13 +461,15 @@ class CreateSecretChat : public SecretChatLogEventBase<CreateSecretChat> {
void parse(ParserT &parser) { void parse(ParserT &parser) {
using td::parse; using td::parse;
parse(random_id, parser); parse(random_id, parser);
parse(user_id, parser); int32 legacy_user_id;
parse(legacy_user_id, parser);
user_id = UserId(legacy_user_id);
parse(user_access_hash, parser); parse(user_access_hash, parser);
} }
StringBuilder &print(StringBuilder &sb) const override { StringBuilder &print(StringBuilder &sb) const override {
return sb << "[Logevent CreateSecretChat " << tag("id", log_event_id()) << tag("chat_id", random_id) return sb << "[Logevent CreateSecretChat " << tag("id", log_event_id()) << tag("chat_id", random_id) << user_id
<< tag("user_id", user_id) << "]"; << "]";
} }
}; };

View File

@ -765,7 +765,7 @@ class Master : public Actor {
auto old_context = set_context(std::make_shared<Global>()); auto old_context = set_context(std::make_shared<Global>());
alice_ = create_actor<SecretChatProxy>("SecretChatProxy alice", "alice", actor_shared(this, 1)); alice_ = create_actor<SecretChatProxy>("SecretChatProxy alice", "alice", actor_shared(this, 1));
bob_ = create_actor<SecretChatProxy>("SecretChatProxy bob", "bob", actor_shared(this, 2)); bob_ = create_actor<SecretChatProxy>("SecretChatProxy bob", "bob", actor_shared(this, 2));
send_closure(alice_->get_actor_unsafe()->actor_, &SecretChatActor::create_chat, 2, 0, 123, send_closure(alice_->get_actor_unsafe()->actor_, &SecretChatActor::create_chat, UserId(2), 0, 123,
PromiseCreator::lambda([actor_id = actor_id(this)](Result<SecretChatId> res) { PromiseCreator::lambda([actor_id = actor_id(this)](Result<SecretChatId> res) {
send_closure(actor_id, &Master::got_secret_chat_id, std::move(res), 0); send_closure(actor_id, &Master::got_secret_chat_id, std::move(res), 0);
})); }));