Rewrite PhoneNumberManager as regular manager.
This commit is contained in:
parent
5bf1142506
commit
99d8de1e88
@ -8,253 +8,271 @@
|
||||
|
||||
#include "td/telegram/ConfigManager.h"
|
||||
#include "td/telegram/Global.h"
|
||||
#include "td/telegram/net/NetQueryDispatcher.h"
|
||||
#include "td/telegram/SuggestedAction.h"
|
||||
#include "td/telegram/Td.h"
|
||||
#include "td/telegram/td_api.h"
|
||||
#include "td/telegram/telegram_api.h"
|
||||
#include "td/telegram/UserManager.h"
|
||||
|
||||
#include "td/utils/buffer.h"
|
||||
#include "td/utils/logging.h"
|
||||
|
||||
namespace td {
|
||||
|
||||
PhoneNumberManager::PhoneNumberManager(Type type, ActorShared<> parent)
|
||||
: type_(type), parent_(std::move(parent)) {
|
||||
}
|
||||
class SendCodeQuery final : public Td::ResultHandler {
|
||||
Promise<telegram_api::object_ptr<telegram_api::auth_sentCode>> promise_;
|
||||
|
||||
void PhoneNumberManager::send_new_send_code_query(uint64 query_id, const telegram_api::Function &send_code) {
|
||||
on_new_query(query_id);
|
||||
start_net_query(NetQueryType::SendCode, G()->net_query_creator().create(send_code));
|
||||
}
|
||||
|
||||
void PhoneNumberManager::set_phone_number(uint64 query_id, string phone_number, Settings settings) {
|
||||
if (phone_number.empty()) {
|
||||
return on_query_error(query_id, Status::Error(400, "Phone number must be non-empty"));
|
||||
public:
|
||||
explicit SendCodeQuery(Promise<telegram_api::object_ptr<telegram_api::auth_sentCode>> &&promise)
|
||||
: promise_(std::move(promise)) {
|
||||
}
|
||||
|
||||
switch (type_) {
|
||||
case Type::ChangePhone:
|
||||
send_closure(G()->config_manager(), &ConfigManager::hide_suggested_action,
|
||||
SuggestedAction{SuggestedAction::Type::CheckPhoneNumber});
|
||||
return send_new_send_code_query(query_id, send_code_helper_.send_change_phone_code(phone_number, settings));
|
||||
case Type::VerifyPhone:
|
||||
return send_new_send_code_query(query_id, send_code_helper_.send_verify_phone_code(phone_number, settings));
|
||||
case Type::ConfirmPhone:
|
||||
default:
|
||||
UNREACHABLE();
|
||||
}
|
||||
}
|
||||
|
||||
void PhoneNumberManager::set_phone_number_and_hash(uint64 query_id, string hash, string phone_number,
|
||||
Settings settings) {
|
||||
if (phone_number.empty()) {
|
||||
return on_query_error(query_id, Status::Error(400, "Phone number must be non-empty"));
|
||||
}
|
||||
if (hash.empty()) {
|
||||
return on_query_error(query_id, Status::Error(400, "Hash must be non-empty"));
|
||||
void send(const telegram_api::Function &send_code) {
|
||||
send_query(G()->net_query_creator().create(send_code));
|
||||
}
|
||||
|
||||
switch (type_) {
|
||||
case Type::ConfirmPhone:
|
||||
return send_new_send_code_query(query_id,
|
||||
send_code_helper_.send_confirm_phone_code(hash, phone_number, settings));
|
||||
case Type::ChangePhone:
|
||||
case Type::VerifyPhone:
|
||||
default:
|
||||
UNREACHABLE();
|
||||
}
|
||||
}
|
||||
void on_result(BufferSlice packet) final {
|
||||
auto result_ptr = fetch_result<telegram_api::account_sendChangePhoneCode>(packet);
|
||||
if (result_ptr.is_error()) {
|
||||
return on_error(result_ptr.move_as_error());
|
||||
}
|
||||
|
||||
void PhoneNumberManager::resend_authentication_code(uint64 query_id) {
|
||||
if (state_ != State::WaitCode) {
|
||||
return on_query_error(query_id, Status::Error(400, "Can't resend code"));
|
||||
}
|
||||
|
||||
auto r_resend_code = send_code_helper_.resend_code();
|
||||
if (r_resend_code.is_error()) {
|
||||
return on_query_error(query_id, r_resend_code.move_as_error());
|
||||
}
|
||||
|
||||
on_new_query(query_id);
|
||||
|
||||
start_net_query(NetQueryType::SendCode, G()->net_query_creator().create_unauth(r_resend_code.move_as_ok()));
|
||||
}
|
||||
|
||||
void PhoneNumberManager::send_new_check_code_query(const telegram_api::Function &check_code) {
|
||||
start_net_query(NetQueryType::CheckCode, G()->net_query_creator().create(check_code));
|
||||
}
|
||||
|
||||
void PhoneNumberManager::check_code(uint64 query_id, string code) {
|
||||
if (state_ != State::WaitCode) {
|
||||
return on_query_error(query_id, Status::Error(400, "Can't check code"));
|
||||
}
|
||||
|
||||
on_new_query(query_id);
|
||||
|
||||
switch (type_) {
|
||||
case Type::ChangePhone:
|
||||
return send_new_check_code_query(telegram_api::account_changePhone(
|
||||
send_code_helper_.phone_number().str(), send_code_helper_.phone_code_hash().str(), code));
|
||||
case Type::ConfirmPhone:
|
||||
return send_new_check_code_query(
|
||||
telegram_api::account_confirmPhone(send_code_helper_.phone_code_hash().str(), code));
|
||||
case Type::VerifyPhone:
|
||||
return send_new_check_code_query(telegram_api::account_verifyPhone(
|
||||
send_code_helper_.phone_number().str(), send_code_helper_.phone_code_hash().str(), code));
|
||||
default:
|
||||
UNREACHABLE();
|
||||
}
|
||||
}
|
||||
|
||||
void PhoneNumberManager::on_new_query(uint64 query_id) {
|
||||
if (query_id_ != 0) {
|
||||
on_current_query_error(Status::Error(400, "Another query has started"));
|
||||
}
|
||||
net_query_id_ = 0;
|
||||
net_query_type_ = NetQueryType::None;
|
||||
query_id_ = query_id;
|
||||
// TODO: cancel older net_query
|
||||
}
|
||||
|
||||
void PhoneNumberManager::on_current_query_error(Status status) {
|
||||
if (query_id_ == 0) {
|
||||
return;
|
||||
}
|
||||
auto id = query_id_;
|
||||
query_id_ = 0;
|
||||
net_query_id_ = 0;
|
||||
net_query_type_ = NetQueryType::None;
|
||||
on_query_error(id, std::move(status));
|
||||
}
|
||||
|
||||
void PhoneNumberManager::on_query_error(uint64 id, Status status) {
|
||||
send_closure(G()->td(), &Td::send_error, id, std::move(status));
|
||||
}
|
||||
|
||||
void PhoneNumberManager::on_current_query_ok() {
|
||||
if (query_id_ == 0) {
|
||||
return;
|
||||
}
|
||||
auto id = query_id_;
|
||||
net_query_id_ = 0;
|
||||
net_query_type_ = NetQueryType::None;
|
||||
query_id_ = 0;
|
||||
|
||||
switch (state_) {
|
||||
case State::Ok:
|
||||
send_closure(G()->td(), &Td::send_result, id, td_api::make_object<td_api::ok>());
|
||||
break;
|
||||
case State::WaitCode:
|
||||
send_closure(G()->td(), &Td::send_result, id, send_code_helper_.get_authentication_code_info_object());
|
||||
break;
|
||||
default:
|
||||
UNREACHABLE();
|
||||
}
|
||||
}
|
||||
|
||||
void PhoneNumberManager::start_net_query(NetQueryType net_query_type, NetQueryPtr net_query) {
|
||||
// TODO: cancel old net_query?
|
||||
net_query_type_ = net_query_type;
|
||||
net_query_id_ = net_query->id();
|
||||
G()->net_query_dispatcher().dispatch_with_callback(std::move(net_query), actor_shared(this));
|
||||
}
|
||||
|
||||
void PhoneNumberManager::process_check_code_result(Result<tl_object_ptr<telegram_api::User>> &&result) {
|
||||
if (result.is_error()) {
|
||||
return on_current_query_error(result.move_as_error());
|
||||
}
|
||||
send_closure(G()->user_manager(), &UserManager::on_get_user, result.move_as_ok(), "process_check_code_result");
|
||||
state_ = State::Ok;
|
||||
on_current_query_ok();
|
||||
}
|
||||
|
||||
void PhoneNumberManager::process_check_code_result(Result<bool> &&result) {
|
||||
if (result.is_error()) {
|
||||
return on_current_query_error(result.move_as_error());
|
||||
}
|
||||
state_ = State::Ok;
|
||||
on_current_query_ok();
|
||||
}
|
||||
|
||||
void PhoneNumberManager::on_check_code_result(NetQueryPtr &&net_query) {
|
||||
switch (type_) {
|
||||
case Type::ChangePhone:
|
||||
return process_check_code_result(fetch_result<telegram_api::account_changePhone>(std::move(net_query)));
|
||||
case Type::VerifyPhone:
|
||||
return process_check_code_result(fetch_result<telegram_api::account_verifyPhone>(std::move(net_query)));
|
||||
case Type::ConfirmPhone:
|
||||
return process_check_code_result(fetch_result<telegram_api::account_confirmPhone>(std::move(net_query)));
|
||||
default:
|
||||
UNREACHABLE();
|
||||
}
|
||||
}
|
||||
|
||||
void PhoneNumberManager::on_send_code_result(NetQueryPtr &&net_query) {
|
||||
auto r_sent_code = [&] {
|
||||
switch (type_) {
|
||||
case Type::ChangePhone:
|
||||
return fetch_result<telegram_api::account_sendChangePhoneCode>(std::move(net_query));
|
||||
case Type::VerifyPhone:
|
||||
return fetch_result<telegram_api::account_sendVerifyPhoneCode>(std::move(net_query));
|
||||
case Type::ConfirmPhone:
|
||||
return fetch_result<telegram_api::account_sendConfirmPhoneCode>(std::move(net_query));
|
||||
auto ptr = result_ptr.move_as_ok();
|
||||
switch (ptr->get_id()) {
|
||||
case telegram_api::auth_sentCodeSuccess::ID:
|
||||
return on_error(Status::Error(500, "Receive invalid response"));
|
||||
case telegram_api::auth_sentCode::ID:
|
||||
return promise_.set_value(telegram_api::move_object_as<telegram_api::auth_sentCode>(ptr));
|
||||
default:
|
||||
UNREACHABLE();
|
||||
return fetch_result<telegram_api::account_sendChangePhoneCode>(std::move(net_query));
|
||||
}
|
||||
}();
|
||||
if (r_sent_code.is_error()) {
|
||||
return on_current_query_error(r_sent_code.move_as_error());
|
||||
}
|
||||
auto sent_code_ptr = r_sent_code.move_as_ok();
|
||||
auto sent_code_id = sent_code_ptr->get_id();
|
||||
if (sent_code_id != telegram_api::auth_sentCode::ID) {
|
||||
CHECK(sent_code_id == telegram_api::auth_sentCodeSuccess::ID);
|
||||
return on_current_query_error(Status::Error(500, "Receive invalid response"));
|
||||
}
|
||||
auto sent_code = telegram_api::move_object_as<telegram_api::auth_sentCode>(sent_code_ptr);
|
||||
|
||||
LOG(INFO) << "Receive " << to_string(sent_code);
|
||||
|
||||
switch (sent_code->type_->get_id()) {
|
||||
case telegram_api::auth_sentCodeTypeSetUpEmailRequired::ID:
|
||||
case telegram_api::auth_sentCodeTypeEmailCode::ID:
|
||||
return on_current_query_error(Status::Error(500, "Receive incorrect response"));
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
send_code_helper_.on_sent_code(std::move(sent_code));
|
||||
|
||||
state_ = State::WaitCode;
|
||||
on_current_query_ok();
|
||||
}
|
||||
|
||||
void PhoneNumberManager::on_result(NetQueryPtr net_query) {
|
||||
NetQueryType type = NetQueryType::None;
|
||||
if (net_query->id() == net_query_id_) {
|
||||
net_query_id_ = 0;
|
||||
type = net_query_type_;
|
||||
net_query_type_ = NetQueryType::None;
|
||||
void on_error(Status status) final {
|
||||
promise_.set_error(std::move(status));
|
||||
}
|
||||
switch (type) {
|
||||
case NetQueryType::None:
|
||||
net_query->clear();
|
||||
break;
|
||||
case NetQueryType::SendCode:
|
||||
on_send_code_result(std::move(net_query));
|
||||
break;
|
||||
case NetQueryType::CheckCode:
|
||||
on_check_code_result(std::move(net_query));
|
||||
break;
|
||||
default:
|
||||
UNREACHABLE();
|
||||
};
|
||||
|
||||
class ChangePhoneQuery final : public Td::ResultHandler {
|
||||
Promise<Unit> promise_;
|
||||
|
||||
public:
|
||||
explicit ChangePhoneQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
|
||||
}
|
||||
|
||||
void send(const string &phone_number, const string &phone_code_hash, const string &code) {
|
||||
send_query(G()->net_query_creator().create(telegram_api::account_changePhone(phone_number, phone_code_hash, code)));
|
||||
}
|
||||
|
||||
void on_result(BufferSlice packet) final {
|
||||
auto result_ptr = fetch_result<telegram_api::account_changePhone>(packet);
|
||||
if (result_ptr.is_error()) {
|
||||
return on_error(result_ptr.move_as_error());
|
||||
}
|
||||
|
||||
td_->user_manager_->on_get_user(result_ptr.move_as_ok(), "ChangePhoneQuery");
|
||||
promise_.set_value(Unit());
|
||||
}
|
||||
|
||||
void on_error(Status status) final {
|
||||
promise_.set_error(std::move(status));
|
||||
}
|
||||
};
|
||||
|
||||
class VerifyPhoneQuery final : public Td::ResultHandler {
|
||||
Promise<Unit> promise_;
|
||||
|
||||
public:
|
||||
explicit VerifyPhoneQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
|
||||
}
|
||||
|
||||
void send(const string &phone_number, const string &phone_code_hash, const string &code) {
|
||||
send_query(G()->net_query_creator().create(telegram_api::account_verifyPhone(phone_number, phone_code_hash, code)));
|
||||
}
|
||||
|
||||
void on_result(BufferSlice packet) final {
|
||||
auto result_ptr = fetch_result<telegram_api::account_verifyPhone>(packet);
|
||||
if (result_ptr.is_error()) {
|
||||
return on_error(result_ptr.move_as_error());
|
||||
}
|
||||
|
||||
promise_.set_value(Unit());
|
||||
}
|
||||
|
||||
void on_error(Status status) final {
|
||||
promise_.set_error(std::move(status));
|
||||
}
|
||||
};
|
||||
|
||||
class ConfirmPhoneQuery final : public Td::ResultHandler {
|
||||
Promise<Unit> promise_;
|
||||
|
||||
public:
|
||||
explicit ConfirmPhoneQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
|
||||
}
|
||||
|
||||
void send(const string &phone_code_hash, const string &code) {
|
||||
send_query(G()->net_query_creator().create(telegram_api::account_confirmPhone(phone_code_hash, code)));
|
||||
}
|
||||
|
||||
void on_result(BufferSlice packet) final {
|
||||
auto result_ptr = fetch_result<telegram_api::account_confirmPhone>(packet);
|
||||
if (result_ptr.is_error()) {
|
||||
return on_error(result_ptr.move_as_error());
|
||||
}
|
||||
|
||||
promise_.set_value(Unit());
|
||||
}
|
||||
|
||||
void on_error(Status status) final {
|
||||
promise_.set_error(std::move(status));
|
||||
}
|
||||
};
|
||||
|
||||
PhoneNumberManager::PhoneNumberManager(Td *td, ActorShared<> parent) : td_(td), parent_(std::move(parent)) {
|
||||
}
|
||||
|
||||
void PhoneNumberManager::tear_down() {
|
||||
parent_.reset();
|
||||
}
|
||||
|
||||
void PhoneNumberManager::inc_generation() {
|
||||
generation_++;
|
||||
state_ = State::Ok;
|
||||
send_code_helper_ = {};
|
||||
}
|
||||
|
||||
void PhoneNumberManager::send_new_send_code_query(
|
||||
const telegram_api::Function &send_code, Promise<td_api::object_ptr<td_api::authenticationCodeInfo>> &&promise) {
|
||||
auto query_promise =
|
||||
PromiseCreator::lambda([actor_id = actor_id(this), generation = generation_, promise = std::move(promise)](
|
||||
Result<telegram_api::object_ptr<telegram_api::auth_sentCode>> r_sent_code) mutable {
|
||||
send_closure(actor_id, &PhoneNumberManager::on_send_code_result, std::move(r_sent_code), generation,
|
||||
std::move(promise));
|
||||
});
|
||||
td_->create_handler<SendCodeQuery>(std::move(query_promise))->send(send_code);
|
||||
}
|
||||
|
||||
void PhoneNumberManager::on_send_code_result(Result<telegram_api::object_ptr<telegram_api::auth_sentCode>> r_sent_code,
|
||||
int64 generation,
|
||||
Promise<td_api::object_ptr<td_api::authenticationCodeInfo>> &&promise) {
|
||||
G()->ignore_result_if_closing(r_sent_code);
|
||||
if (r_sent_code.is_error()) {
|
||||
return promise.set_error(r_sent_code.move_as_error());
|
||||
}
|
||||
if (generation != generation_) {
|
||||
return promise.set_error(Status::Error(500, "Request was canceled"));
|
||||
}
|
||||
auto sent_code = r_sent_code.move_as_ok();
|
||||
|
||||
LOG(INFO) << "Receive " << to_string(sent_code);
|
||||
|
||||
switch (sent_code->type_->get_id()) {
|
||||
case telegram_api::auth_sentCodeTypeSetUpEmailRequired::ID:
|
||||
case telegram_api::auth_sentCodeTypeEmailCode::ID:
|
||||
return promise.set_error(Status::Error(500, "Receive incorrect response"));
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
send_code_helper_.on_sent_code(std::move(sent_code));
|
||||
state_ = State::WaitCode;
|
||||
|
||||
promise.set_value(send_code_helper_.get_authentication_code_info_object());
|
||||
}
|
||||
|
||||
void PhoneNumberManager::set_phone_number(Type type, string phone_number,
|
||||
td_api::object_ptr<td_api::phoneNumberAuthenticationSettings> settings,
|
||||
Promise<td_api::object_ptr<td_api::authenticationCodeInfo>> &&promise) {
|
||||
if (phone_number.empty()) {
|
||||
return promise.set_error(Status::Error(400, "Phone number must be non-empty"));
|
||||
}
|
||||
|
||||
inc_generation();
|
||||
type_ = type;
|
||||
switch (type_) {
|
||||
case Type::ChangePhone:
|
||||
send_closure(G()->config_manager(), &ConfigManager::hide_suggested_action,
|
||||
SuggestedAction{SuggestedAction::Type::CheckPhoneNumber});
|
||||
return send_new_send_code_query(send_code_helper_.send_change_phone_code(phone_number, settings),
|
||||
std::move(promise));
|
||||
case Type::VerifyPhone:
|
||||
return send_new_send_code_query(send_code_helper_.send_verify_phone_code(phone_number, settings),
|
||||
std::move(promise));
|
||||
case Type::ConfirmPhone:
|
||||
default:
|
||||
UNREACHABLE();
|
||||
}
|
||||
}
|
||||
|
||||
void PhoneNumberManager::set_phone_number_and_hash(
|
||||
string hash, string phone_number, td_api::object_ptr<td_api::phoneNumberAuthenticationSettings> settings,
|
||||
Promise<td_api::object_ptr<td_api::authenticationCodeInfo>> &&promise) {
|
||||
if (phone_number.empty()) {
|
||||
return promise.set_error(Status::Error(400, "Phone number must be non-empty"));
|
||||
}
|
||||
if (hash.empty()) {
|
||||
return promise.set_error(Status::Error(400, "Hash must be non-empty"));
|
||||
}
|
||||
|
||||
inc_generation();
|
||||
type_ = Type::ConfirmPhone;
|
||||
send_new_send_code_query(send_code_helper_.send_confirm_phone_code(hash, phone_number, settings), std::move(promise));
|
||||
}
|
||||
|
||||
void PhoneNumberManager::resend_authentication_code(
|
||||
Promise<td_api::object_ptr<td_api::authenticationCodeInfo>> &&promise) {
|
||||
if (state_ != State::WaitCode) {
|
||||
return promise.set_error(Status::Error(400, "Can't resend code"));
|
||||
}
|
||||
|
||||
auto r_resend_code = send_code_helper_.resend_code();
|
||||
if (r_resend_code.is_error()) {
|
||||
return promise.set_error(r_resend_code.move_as_error());
|
||||
}
|
||||
|
||||
send_new_send_code_query(r_resend_code.move_as_ok(), std::move(promise));
|
||||
}
|
||||
|
||||
void PhoneNumberManager::check_code(string code, Promise<Unit> &&promise) {
|
||||
if (state_ != State::WaitCode) {
|
||||
return promise.set_error(Status::Error(400, "Can't check code"));
|
||||
}
|
||||
|
||||
auto query_promise = PromiseCreator::lambda(
|
||||
[actor_id = actor_id(this), generation = generation_, promise = std::move(promise)](Result<Unit> result) mutable {
|
||||
send_closure(actor_id, &PhoneNumberManager::on_check_code_result, std::move(result), generation,
|
||||
std::move(promise));
|
||||
});
|
||||
switch (type_) {
|
||||
case Type::ChangePhone:
|
||||
td_->create_handler<ChangePhoneQuery>(std::move(query_promise))
|
||||
->send(send_code_helper_.phone_number().str(), send_code_helper_.phone_code_hash().str(), code);
|
||||
break;
|
||||
case Type::VerifyPhone:
|
||||
td_->create_handler<VerifyPhoneQuery>(std::move(query_promise))
|
||||
->send(send_code_helper_.phone_number().str(), send_code_helper_.phone_code_hash().str(), code);
|
||||
break;
|
||||
case Type::ConfirmPhone:
|
||||
td_->create_handler<ConfirmPhoneQuery>(std::move(query_promise))
|
||||
->send(send_code_helper_.phone_code_hash().str(), code);
|
||||
break;
|
||||
default:
|
||||
UNREACHABLE();
|
||||
}
|
||||
}
|
||||
|
||||
void PhoneNumberManager::on_check_code_result(Result<Unit> result, int64 generation, Promise<Unit> &&promise) {
|
||||
G()->ignore_result_if_closing(result);
|
||||
if (result.is_error()) {
|
||||
return promise.set_error(result.move_as_error());
|
||||
}
|
||||
if (generation != generation_) {
|
||||
return promise.set_error(Status::Error(500, "Request was canceled"));
|
||||
}
|
||||
|
||||
inc_generation();
|
||||
|
||||
promise.set_value(Unit());
|
||||
}
|
||||
|
||||
} // namespace td
|
||||
|
@ -6,8 +6,6 @@
|
||||
//
|
||||
#pragma once
|
||||
|
||||
#include "td/telegram/net/NetActor.h"
|
||||
#include "td/telegram/net/NetQuery.h"
|
||||
#include "td/telegram/SendCodeHelper.h"
|
||||
#include "td/telegram/td_api.h"
|
||||
#include "td/telegram/telegram_api.h"
|
||||
@ -19,57 +17,47 @@
|
||||
|
||||
namespace td {
|
||||
|
||||
class PhoneNumberManager final : public NetActor {
|
||||
class Td;
|
||||
|
||||
class PhoneNumberManager final : public Actor {
|
||||
public:
|
||||
PhoneNumberManager(Td *td, ActorShared<> parent);
|
||||
|
||||
enum class Type : int32 { ChangePhone, VerifyPhone, ConfirmPhone };
|
||||
PhoneNumberManager(Type type, ActorShared<> parent);
|
||||
|
||||
using Settings = td_api::object_ptr<td_api::phoneNumberAuthenticationSettings>;
|
||||
void set_phone_number(Type type, string phone_number,
|
||||
td_api::object_ptr<td_api::phoneNumberAuthenticationSettings> settings,
|
||||
Promise<td_api::object_ptr<td_api::authenticationCodeInfo>> &&promise);
|
||||
|
||||
void set_phone_number(uint64 query_id, string phone_number, Settings settings);
|
||||
void set_phone_number_and_hash(uint64 query_id, string hash, string phone_number, Settings settings);
|
||||
void set_phone_number_and_hash(string hash, string phone_number,
|
||||
td_api::object_ptr<td_api::phoneNumberAuthenticationSettings> settings,
|
||||
Promise<td_api::object_ptr<td_api::authenticationCodeInfo>> &&promise);
|
||||
|
||||
void resend_authentication_code(uint64 query_id);
|
||||
void check_code(uint64 query_id, string code);
|
||||
void resend_authentication_code(Promise<td_api::object_ptr<td_api::authenticationCodeInfo>> &&promise);
|
||||
|
||||
void check_code(string code, Promise<Unit> &&promise);
|
||||
|
||||
private:
|
||||
Type type_;
|
||||
|
||||
enum class State : int32 { Ok, WaitCode } state_ = State::Ok;
|
||||
enum class NetQueryType : int32 { None, SendCode, CheckCode };
|
||||
|
||||
ActorShared<> parent_;
|
||||
uint64 query_id_ = 0;
|
||||
uint64 net_query_id_ = 0;
|
||||
NetQueryType net_query_type_ = NetQueryType::None;
|
||||
|
||||
SendCodeHelper send_code_helper_;
|
||||
|
||||
void on_new_query(uint64 query_id);
|
||||
|
||||
void on_current_query_ok();
|
||||
|
||||
void on_current_query_error(Status status);
|
||||
|
||||
static void on_query_error(uint64 id, Status status);
|
||||
|
||||
void start_net_query(NetQueryType net_query_type, NetQueryPtr net_query);
|
||||
|
||||
void send_new_send_code_query(uint64 query_id, const telegram_api::Function &send_code);
|
||||
|
||||
void send_new_check_code_query(const telegram_api::Function &check_code);
|
||||
|
||||
void process_check_code_result(Result<tl_object_ptr<telegram_api::User>> &&result);
|
||||
|
||||
void process_check_code_result(Result<bool> &&result);
|
||||
|
||||
void on_result(NetQueryPtr net_query) final;
|
||||
|
||||
void on_send_code_result(NetQueryPtr &&net_query);
|
||||
|
||||
void on_check_code_result(NetQueryPtr &&net_query);
|
||||
|
||||
void tear_down() final;
|
||||
|
||||
void inc_generation();
|
||||
|
||||
void send_new_send_code_query(const telegram_api::Function &send_code,
|
||||
Promise<td_api::object_ptr<td_api::authenticationCodeInfo>> &&promise);
|
||||
|
||||
void on_send_code_result(Result<telegram_api::object_ptr<telegram_api::auth_sentCode>> r_sent_code, int64 generation,
|
||||
Promise<td_api::object_ptr<td_api::authenticationCodeInfo>> &&promise);
|
||||
|
||||
void on_check_code_result(Result<Unit> result, int64 generation, Promise<Unit> &&promise);
|
||||
|
||||
Td *td_;
|
||||
ActorShared<> parent_;
|
||||
|
||||
Type type_;
|
||||
SendCodeHelper send_code_helper_;
|
||||
int64 generation_ = 0;
|
||||
};
|
||||
|
||||
} // namespace td
|
||||
|
@ -3239,6 +3239,7 @@ void Td::dec_actor_refcnt() {
|
||||
reset_manager(notification_manager_, "NotificationManager");
|
||||
reset_manager(notification_settings_manager_, "NotificationSettingsManager");
|
||||
reset_manager(people_nearby_manager_, "PeopleNearbyManager");
|
||||
reset_manager(phone_number_manager_, "PhoneNumberManager");
|
||||
reset_manager(poll_manager_, "PollManager");
|
||||
reset_manager(privacy_manager_, "PrivacyManager");
|
||||
reset_manager(quick_reply_manager_, "QuickReplyManager");
|
||||
@ -3364,9 +3365,7 @@ void Td::clear() {
|
||||
|
||||
// close all pure actors
|
||||
reset_actor(ActorOwn<Actor>(std::move(call_manager_)));
|
||||
reset_actor(ActorOwn<Actor>(std::move(change_phone_number_manager_)));
|
||||
reset_actor(ActorOwn<Actor>(std::move(config_manager_)));
|
||||
reset_actor(ActorOwn<Actor>(std::move(confirm_phone_number_manager_)));
|
||||
reset_actor(ActorOwn<Actor>(std::move(device_token_manager_)));
|
||||
reset_actor(ActorOwn<Actor>(std::move(hashtag_hints_)));
|
||||
reset_actor(ActorOwn<Actor>(std::move(language_pack_manager_)));
|
||||
@ -3375,7 +3374,6 @@ void Td::clear() {
|
||||
reset_actor(ActorOwn<Actor>(std::move(secure_manager_)));
|
||||
reset_actor(ActorOwn<Actor>(std::move(secret_chats_manager_)));
|
||||
reset_actor(ActorOwn<Actor>(std::move(storage_manager_)));
|
||||
reset_actor(ActorOwn<Actor>(std::move(verify_phone_number_manager_)));
|
||||
|
||||
G()->set_connection_creator(ActorOwn<ConnectionCreator>());
|
||||
LOG(DEBUG) << "ConnectionCreator was cleared" << timer;
|
||||
@ -3415,6 +3413,7 @@ void Td::clear() {
|
||||
reset_actor(ActorOwn<Actor>(std::move(notification_manager_actor_)));
|
||||
reset_actor(ActorOwn<Actor>(std::move(notification_settings_manager_actor_)));
|
||||
reset_actor(ActorOwn<Actor>(std::move(people_nearby_manager_actor_)));
|
||||
reset_actor(ActorOwn<Actor>(std::move(phone_number_manager_actor_)));
|
||||
reset_actor(ActorOwn<Actor>(std::move(poll_manager_actor_)));
|
||||
reset_actor(ActorOwn<Actor>(std::move(privacy_manager_actor_)));
|
||||
reset_actor(ActorOwn<Actor>(std::move(quick_reply_manager_actor_)));
|
||||
@ -3950,6 +3949,8 @@ void Td::init_managers() {
|
||||
people_nearby_manager_ = make_unique<PeopleNearbyManager>(this, create_reference());
|
||||
people_nearby_manager_actor_ = register_actor("PeopleNearbyManager", people_nearby_manager_.get());
|
||||
G()->set_people_nearby_manager(people_nearby_manager_actor_.get());
|
||||
phone_number_manager_ = make_unique<PhoneNumberManager>(this, create_reference());
|
||||
phone_number_manager_actor_ = register_actor("PhoneNumberManager", phone_number_manager_.get());
|
||||
poll_manager_ = make_unique<PollManager>(this, create_reference());
|
||||
poll_manager_actor_ = register_actor("PollManager", poll_manager_.get());
|
||||
privacy_manager_ = make_unique<PrivacyManager>(this, create_reference());
|
||||
@ -4006,10 +4007,6 @@ void Td::init_managers() {
|
||||
void Td::init_pure_actor_managers() {
|
||||
call_manager_ = create_actor<CallManager>("CallManager", create_reference());
|
||||
G()->set_call_manager(call_manager_.get());
|
||||
change_phone_number_manager_ = create_actor<PhoneNumberManager>(
|
||||
"ChangePhoneNumberManager", PhoneNumberManager::Type::ChangePhone, create_reference());
|
||||
confirm_phone_number_manager_ = create_actor<PhoneNumberManager>(
|
||||
"ConfirmPhoneNumberManager", PhoneNumberManager::Type::ConfirmPhone, create_reference());
|
||||
device_token_manager_ = create_actor<DeviceTokenManager>("DeviceTokenManager", create_reference());
|
||||
hashtag_hints_ = create_actor<HashtagHints>("HashtagHints", "text", create_reference());
|
||||
language_pack_manager_ = create_actor<LanguagePackManager>("LanguagePackManager", create_reference());
|
||||
@ -4017,8 +4014,6 @@ void Td::init_pure_actor_managers() {
|
||||
password_manager_ = create_actor<PasswordManager>("PasswordManager", create_reference());
|
||||
G()->set_password_manager(password_manager_.get());
|
||||
secure_manager_ = create_actor<SecureManager>("SecureManager", create_reference());
|
||||
verify_phone_number_manager_ = create_actor<PhoneNumberManager>(
|
||||
"VerifyPhoneNumberManager", PhoneNumberManager::Type::VerifyPhone, create_reference());
|
||||
}
|
||||
|
||||
void Td::send_update(tl_object_ptr<td_api::Update> &&object) {
|
||||
@ -4618,19 +4613,22 @@ void Td::on_request(uint64 id, td_api::deleteAccount &request) {
|
||||
void Td::on_request(uint64 id, td_api::changePhoneNumber &request) {
|
||||
CHECK_IS_USER();
|
||||
CLEAN_INPUT_STRING(request.phone_number_);
|
||||
send_closure(change_phone_number_manager_, &PhoneNumberManager::set_phone_number, id,
|
||||
std::move(request.phone_number_), std::move(request.settings_));
|
||||
CREATE_REQUEST_PROMISE();
|
||||
phone_number_manager_->set_phone_number(PhoneNumberManager::Type::ChangePhone, std::move(request.phone_number_),
|
||||
std::move(request.settings_), std::move(promise));
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, td_api::checkChangePhoneNumberCode &request) {
|
||||
CHECK_IS_USER();
|
||||
CLEAN_INPUT_STRING(request.code_);
|
||||
send_closure(change_phone_number_manager_, &PhoneNumberManager::check_code, id, std::move(request.code_));
|
||||
CREATE_OK_REQUEST_PROMISE();
|
||||
phone_number_manager_->check_code(std::move(request.code_), std::move(promise));
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, td_api::resendChangePhoneNumberCode &request) {
|
||||
CHECK_IS_USER();
|
||||
send_closure(change_phone_number_manager_, &PhoneNumberManager::resend_authentication_code, id);
|
||||
CREATE_REQUEST_PROMISE();
|
||||
phone_number_manager_->resend_authentication_code(std::move(promise));
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, const td_api::getUserLink &request) {
|
||||
@ -9093,19 +9091,22 @@ void Td::on_request(uint64 id, td_api::getPreferredCountryLanguage &request) {
|
||||
void Td::on_request(uint64 id, td_api::sendPhoneNumberVerificationCode &request) {
|
||||
CHECK_IS_USER();
|
||||
CLEAN_INPUT_STRING(request.phone_number_);
|
||||
send_closure(verify_phone_number_manager_, &PhoneNumberManager::set_phone_number, id,
|
||||
std::move(request.phone_number_), std::move(request.settings_));
|
||||
CREATE_REQUEST_PROMISE();
|
||||
phone_number_manager_->set_phone_number(PhoneNumberManager::Type::VerifyPhone, std::move(request.phone_number_),
|
||||
std::move(request.settings_), std::move(promise));
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, const td_api::resendPhoneNumberVerificationCode &request) {
|
||||
CHECK_IS_USER();
|
||||
send_closure(verify_phone_number_manager_, &PhoneNumberManager::resend_authentication_code, id);
|
||||
CREATE_REQUEST_PROMISE();
|
||||
phone_number_manager_->resend_authentication_code(std::move(promise));
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, td_api::checkPhoneNumberVerificationCode &request) {
|
||||
CHECK_IS_USER();
|
||||
CLEAN_INPUT_STRING(request.code_);
|
||||
send_closure(verify_phone_number_manager_, &PhoneNumberManager::check_code, id, std::move(request.code_));
|
||||
CREATE_OK_REQUEST_PROMISE();
|
||||
phone_number_manager_->check_code(std::move(request.code_), std::move(promise));
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, td_api::sendEmailAddressVerificationCode &request) {
|
||||
@ -9186,19 +9187,22 @@ void Td::on_request(uint64 id, td_api::sendPhoneNumberConfirmationCode &request)
|
||||
CHECK_IS_USER();
|
||||
CLEAN_INPUT_STRING(request.phone_number_);
|
||||
CLEAN_INPUT_STRING(request.hash_);
|
||||
send_closure(confirm_phone_number_manager_, &PhoneNumberManager::set_phone_number_and_hash, id,
|
||||
std::move(request.hash_), std::move(request.phone_number_), std::move(request.settings_));
|
||||
CREATE_REQUEST_PROMISE();
|
||||
phone_number_manager_->set_phone_number_and_hash(std::move(request.hash_), std::move(request.phone_number_),
|
||||
std::move(request.settings_), std::move(promise));
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, const td_api::resendPhoneNumberConfirmationCode &request) {
|
||||
CHECK_IS_USER();
|
||||
send_closure(confirm_phone_number_manager_, &PhoneNumberManager::resend_authentication_code, id);
|
||||
CREATE_REQUEST_PROMISE();
|
||||
phone_number_manager_->resend_authentication_code(std::move(promise));
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, td_api::checkPhoneNumberConfirmationCode &request) {
|
||||
CHECK_IS_USER();
|
||||
CLEAN_INPUT_STRING(request.code_);
|
||||
send_closure(confirm_phone_number_manager_, &PhoneNumberManager::check_code, id, std::move(request.code_));
|
||||
CREATE_OK_REQUEST_PROMISE();
|
||||
phone_number_manager_->check_code(std::move(request.code_), std::move(promise));
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, const td_api::getSupportUser &request) {
|
||||
|
@ -234,6 +234,8 @@ class Td final : public Actor {
|
||||
ActorOwn<PrivacyManager> privacy_manager_actor_;
|
||||
unique_ptr<PeopleNearbyManager> people_nearby_manager_;
|
||||
ActorOwn<PeopleNearbyManager> people_nearby_manager_actor_;
|
||||
unique_ptr<PhoneNumberManager> phone_number_manager_;
|
||||
ActorOwn<PhoneNumberManager> phone_number_manager_actor_;
|
||||
unique_ptr<QuickReplyManager> quick_reply_manager_;
|
||||
ActorOwn<QuickReplyManager> quick_reply_manager_actor_;
|
||||
unique_ptr<ReactionManager> reaction_manager_;
|
||||
@ -270,9 +272,7 @@ class Td final : public Actor {
|
||||
ActorOwn<WebPagesManager> web_pages_manager_actor_;
|
||||
|
||||
ActorOwn<CallManager> call_manager_;
|
||||
ActorOwn<PhoneNumberManager> change_phone_number_manager_;
|
||||
ActorOwn<ConfigManager> config_manager_;
|
||||
ActorOwn<PhoneNumberManager> confirm_phone_number_manager_;
|
||||
ActorOwn<DeviceTokenManager> device_token_manager_;
|
||||
ActorOwn<HashtagHints> hashtag_hints_;
|
||||
ActorOwn<LanguagePackManager> language_pack_manager_;
|
||||
@ -282,7 +282,6 @@ class Td final : public Actor {
|
||||
ActorOwn<SecureManager> secure_manager_;
|
||||
ActorOwn<StateManager> state_manager_;
|
||||
ActorOwn<StorageManager> storage_manager_;
|
||||
ActorOwn<PhoneNumberManager> verify_phone_number_manager_;
|
||||
|
||||
class ResultHandler : public std::enable_shared_from_this<ResultHandler> {
|
||||
public:
|
||||
@ -422,9 +421,8 @@ class Td final : public Actor {
|
||||
void on_get_promo_data(Result<telegram_api::object_ptr<telegram_api::help_PromoData>> r_promo_data, bool dummy);
|
||||
|
||||
template <class T>
|
||||
friend class RequestActor; // uses send_result/send_error
|
||||
friend class AuthManager; // uses send_result/send_error, TODO pass Promise<>
|
||||
friend class PhoneNumberManager; // uses send_result/send_error, TODO pass Promise<>
|
||||
friend class RequestActor; // uses send_result/send_error
|
||||
friend class AuthManager; // uses send_result/send_error, TODO pass Promise<>
|
||||
|
||||
void add_handler(uint64 id, std::shared_ptr<ResultHandler> handler);
|
||||
std::shared_ptr<ResultHandler> extract_handler(uint64 id);
|
||||
|
Loading…
Reference in New Issue
Block a user