From 205e68bf8b2e0a1ca5060e9311bdfd1180027b0c Mon Sep 17 00:00:00 2001 From: levlam Date: Wed, 18 Dec 2019 19:08:05 +0300 Subject: [PATCH] Simplify SendCodeHelper::send_code. GitOrigin-RevId: c89daaa0958aebd4fc09cf9690369b80721cafb3 --- td/telegram/AuthManager.cpp | 12 ++++-------- td/telegram/SendCodeHelper.cpp | 7 ++----- td/telegram/SendCodeHelper.h | 4 ++-- 3 files changed, 8 insertions(+), 15 deletions(-) diff --git a/td/telegram/AuthManager.cpp b/td/telegram/AuthManager.cpp index 2caac554..bd23636c 100644 --- a/td/telegram/AuthManager.cpp +++ b/td/telegram/AuthManager.cpp @@ -261,21 +261,17 @@ void AuthManager::set_phone_number(uint64 query_id, string phone_number, other_user_ids_.clear(); was_qr_code_request_ = false; - auto r_send_code = send_code_helper_.send_code(phone_number, settings, api_id_, api_hash_); - if (r_send_code.is_error()) { + if (send_code_helper_.phone_number() != phone_number) { send_code_helper_ = SendCodeHelper(); terms_of_service_ = TermsOfService(); - r_send_code = send_code_helper_.send_code(phone_number, settings, api_id_, api_hash_); - if (r_send_code.is_error()) { - return on_query_error(query_id, r_send_code.move_as_error()); - } } on_new_query(query_id); start_net_query(NetQueryType::SendCode, - G()->net_query_creator().create(create_storer(r_send_code.move_as_ok()), DcId::main(), - NetQuery::Type::Common, NetQuery::AuthFlag::Off)); + G()->net_query_creator().create( + create_storer(send_code_helper_.send_code(phone_number, settings, api_id_, api_hash_)), + DcId::main(), NetQuery::Type::Common, NetQuery::AuthFlag::Off)); } void AuthManager::resend_authentication_code(uint64 query_id) { diff --git a/td/telegram/SendCodeHelper.cpp b/td/telegram/SendCodeHelper.cpp index c5fe9b1f..e0ff47c8 100644 --- a/td/telegram/SendCodeHelper.cpp +++ b/td/telegram/SendCodeHelper.cpp @@ -53,11 +53,8 @@ telegram_api::object_ptr SendCodeHelper::get_input_c false /*ignored*/); } -Result SendCodeHelper::send_code(Slice phone_number, const Settings &settings, - int32 api_id, const string &api_hash) { - if (!phone_number_.empty()) { - return Status::Error(8, "Can't change phone"); - } +telegram_api::auth_sendCode SendCodeHelper::send_code(Slice phone_number, const Settings &settings, int32 api_id, + const string &api_hash) { phone_number_ = phone_number.str(); return telegram_api::auth_sendCode(phone_number_, api_id, api_hash, get_input_code_settings(settings)); } diff --git a/td/telegram/SendCodeHelper.h b/td/telegram/SendCodeHelper.h index 9a403572..6c7c76f0 100644 --- a/td/telegram/SendCodeHelper.h +++ b/td/telegram/SendCodeHelper.h @@ -25,8 +25,8 @@ class SendCodeHelper { using Settings = td_api::object_ptr; - Result send_code(Slice phone_number, const Settings &settings, int32 api_id, - const string &api_hash); + telegram_api::auth_sendCode send_code(Slice phone_number, const Settings &settings, int32 api_id, + const string &api_hash); telegram_api::account_sendChangePhoneCode send_change_phone_code(Slice phone_number, const Settings &settings);