Simplify SendCodeHelper::send_code.

GitOrigin-RevId: c89daaa0958aebd4fc09cf9690369b80721cafb3
This commit is contained in:
levlam 2019-12-18 19:08:05 +03:00
parent 0594b9e795
commit 205e68bf8b
3 changed files with 8 additions and 15 deletions

View File

@ -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) {

View File

@ -53,11 +53,8 @@ telegram_api::object_ptr<telegram_api::codeSettings> SendCodeHelper::get_input_c
false /*ignored*/);
}
Result<telegram_api::auth_sendCode> 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));
}

View File

@ -25,8 +25,8 @@ class SendCodeHelper {
using Settings = td_api::object_ptr<td_api::phoneNumberAuthenticationSettings>;
Result<telegram_api::auth_sendCode> 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);