Fetch result from NetQuery in AuthManager.
This commit is contained in:
parent
db8f41eacf
commit
77baf0d770
@ -876,7 +876,7 @@ void AuthManager::on_sent_code(telegram_api::object_ptr<telegram_api::auth_SentC
|
|||||||
}
|
}
|
||||||
|
|
||||||
void AuthManager::on_send_code_result(NetQueryPtr &result) {
|
void AuthManager::on_send_code_result(NetQueryPtr &result) {
|
||||||
auto r_sent_code = fetch_result<telegram_api::auth_sendCode>(result->ok());
|
auto r_sent_code = fetch_result<telegram_api::auth_sendCode>(std::move(result));
|
||||||
if (r_sent_code.is_error()) {
|
if (r_sent_code.is_error()) {
|
||||||
return on_query_error(r_sent_code.move_as_error());
|
return on_query_error(r_sent_code.move_as_error());
|
||||||
}
|
}
|
||||||
@ -884,7 +884,7 @@ void AuthManager::on_send_code_result(NetQueryPtr &result) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void AuthManager::on_send_email_code_result(NetQueryPtr &result) {
|
void AuthManager::on_send_email_code_result(NetQueryPtr &result) {
|
||||||
auto r_sent_code = fetch_result<telegram_api::account_sendVerifyEmailCode>(result->ok());
|
auto r_sent_code = fetch_result<telegram_api::account_sendVerifyEmailCode>(std::move(result));
|
||||||
if (r_sent_code.is_error()) {
|
if (r_sent_code.is_error()) {
|
||||||
return on_query_error(r_sent_code.move_as_error());
|
return on_query_error(r_sent_code.move_as_error());
|
||||||
}
|
}
|
||||||
@ -902,7 +902,7 @@ void AuthManager::on_send_email_code_result(NetQueryPtr &result) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void AuthManager::on_verify_email_address_result(NetQueryPtr &result) {
|
void AuthManager::on_verify_email_address_result(NetQueryPtr &result) {
|
||||||
auto r_email_verified = fetch_result<telegram_api::account_verifyEmail>(result->ok());
|
auto r_email_verified = fetch_result<telegram_api::account_verifyEmail>(std::move(result));
|
||||||
if (r_email_verified.is_error()) {
|
if (r_email_verified.is_error()) {
|
||||||
return on_query_error(r_email_verified.move_as_error());
|
return on_query_error(r_email_verified.move_as_error());
|
||||||
}
|
}
|
||||||
@ -920,7 +920,7 @@ void AuthManager::on_verify_email_address_result(NetQueryPtr &result) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void AuthManager::on_reset_email_address_result(NetQueryPtr &result) {
|
void AuthManager::on_reset_email_address_result(NetQueryPtr &result) {
|
||||||
auto r_sent_code = fetch_result<telegram_api::auth_resetLoginEmail>(result->ok());
|
auto r_sent_code = fetch_result<telegram_api::auth_resetLoginEmail>(std::move(result));
|
||||||
if (r_sent_code.is_error()) {
|
if (r_sent_code.is_error()) {
|
||||||
if (reset_available_period_ > 0 && reset_pending_date_ == -1 &&
|
if (reset_available_period_ > 0 && reset_pending_date_ == -1 &&
|
||||||
r_sent_code.error().message() == "TASK_ALREADY_EXISTS") {
|
r_sent_code.error().message() == "TASK_ALREADY_EXISTS") {
|
||||||
@ -934,9 +934,7 @@ void AuthManager::on_reset_email_address_result(NetQueryPtr &result) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void AuthManager::on_request_qr_code_result(NetQueryPtr &result, bool is_import) {
|
void AuthManager::on_request_qr_code_result(NetQueryPtr &result, bool is_import) {
|
||||||
Status status;
|
auto r_login_token = fetch_result<telegram_api::auth_exportLoginToken>(std::move(result));
|
||||||
if (result->is_ok()) {
|
|
||||||
auto r_login_token = fetch_result<telegram_api::auth_exportLoginToken>(result->ok());
|
|
||||||
if (r_login_token.is_ok()) {
|
if (r_login_token.is_ok()) {
|
||||||
auto login_token = r_login_token.move_as_ok();
|
auto login_token = r_login_token.move_as_ok();
|
||||||
|
|
||||||
@ -949,12 +947,7 @@ void AuthManager::on_request_qr_code_result(NetQueryPtr &result, bool is_import)
|
|||||||
on_get_login_token(std::move(login_token));
|
on_get_login_token(std::move(login_token));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
auto status = r_login_token.move_as_error();
|
||||||
status = r_login_token.move_as_error();
|
|
||||||
} else {
|
|
||||||
status = std::move(result->error());
|
|
||||||
}
|
|
||||||
CHECK(status.is_error());
|
|
||||||
|
|
||||||
LOG(INFO) << "Receive " << status << " for login token " << (is_import ? "import" : "export");
|
LOG(INFO) << "Receive " << status << " for login token " << (is_import ? "import" : "export");
|
||||||
if (is_import) {
|
if (is_import) {
|
||||||
@ -1012,12 +1005,7 @@ void AuthManager::on_get_login_token(tl_object_ptr<telegram_api::auth_LoginToken
|
|||||||
}
|
}
|
||||||
|
|
||||||
void AuthManager::on_get_password_result(NetQueryPtr &result) {
|
void AuthManager::on_get_password_result(NetQueryPtr &result) {
|
||||||
Result<telegram_api::object_ptr<telegram_api::account_password>> r_password;
|
auto r_password = fetch_result<telegram_api::account_getPassword>(std::move(result));
|
||||||
if (result->is_error()) {
|
|
||||||
r_password = std::move(result->error());
|
|
||||||
} else {
|
|
||||||
r_password = fetch_result<telegram_api::account_getPassword>(result->ok());
|
|
||||||
}
|
|
||||||
if (r_password.is_error() && query_id_ != 0) {
|
if (r_password.is_error() && query_id_ != 0) {
|
||||||
return on_query_error(r_password.move_as_error());
|
return on_query_error(r_password.move_as_error());
|
||||||
}
|
}
|
||||||
@ -1100,7 +1088,7 @@ void AuthManager::on_get_password_result(NetQueryPtr &result) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void AuthManager::on_request_password_recovery_result(NetQueryPtr &result) {
|
void AuthManager::on_request_password_recovery_result(NetQueryPtr &result) {
|
||||||
auto r_email_address_pattern = fetch_result<telegram_api::auth_requestPasswordRecovery>(result->ok());
|
auto r_email_address_pattern = fetch_result<telegram_api::auth_requestPasswordRecovery>(std::move(result));
|
||||||
if (r_email_address_pattern.is_error()) {
|
if (r_email_address_pattern.is_error()) {
|
||||||
return on_query_error(r_email_address_pattern.move_as_error());
|
return on_query_error(r_email_address_pattern.move_as_error());
|
||||||
}
|
}
|
||||||
@ -1112,7 +1100,7 @@ void AuthManager::on_request_password_recovery_result(NetQueryPtr &result) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void AuthManager::on_check_password_recovery_code_result(NetQueryPtr &result) {
|
void AuthManager::on_check_password_recovery_code_result(NetQueryPtr &result) {
|
||||||
auto r_success = fetch_result<telegram_api::auth_checkRecoveryPassword>(result->ok());
|
auto r_success = fetch_result<telegram_api::auth_checkRecoveryPassword>(std::move(result));
|
||||||
if (r_success.is_error()) {
|
if (r_success.is_error()) {
|
||||||
return on_query_error(r_success.move_as_error());
|
return on_query_error(r_success.move_as_error());
|
||||||
}
|
}
|
||||||
@ -1123,7 +1111,7 @@ void AuthManager::on_check_password_recovery_code_result(NetQueryPtr &result) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void AuthManager::on_request_firebase_sms_result(NetQueryPtr &result) {
|
void AuthManager::on_request_firebase_sms_result(NetQueryPtr &result) {
|
||||||
auto r_bool = fetch_result<telegram_api::auth_requestFirebaseSms>(result->ok());
|
auto r_bool = fetch_result<telegram_api::auth_requestFirebaseSms>(std::move(result));
|
||||||
if (r_bool.is_error()) {
|
if (r_bool.is_error()) {
|
||||||
return on_query_error(r_bool.move_as_error());
|
return on_query_error(r_bool.move_as_error());
|
||||||
}
|
}
|
||||||
@ -1131,7 +1119,7 @@ void AuthManager::on_request_firebase_sms_result(NetQueryPtr &result) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void AuthManager::on_authentication_result(NetQueryPtr &result, bool is_from_current_query) {
|
void AuthManager::on_authentication_result(NetQueryPtr &result, bool is_from_current_query) {
|
||||||
auto r_sign_in = fetch_result<telegram_api::auth_signIn>(result->ok());
|
auto r_sign_in = fetch_result<telegram_api::auth_signIn>(std::move(result));
|
||||||
if (r_sign_in.is_error()) {
|
if (r_sign_in.is_error()) {
|
||||||
if (is_from_current_query && query_id_ != 0) {
|
if (is_from_current_query && query_id_ != 0) {
|
||||||
return on_query_error(r_sign_in.move_as_error());
|
return on_query_error(r_sign_in.move_as_error());
|
||||||
@ -1142,22 +1130,16 @@ void AuthManager::on_authentication_result(NetQueryPtr &result, bool is_from_cur
|
|||||||
}
|
}
|
||||||
|
|
||||||
void AuthManager::on_log_out_result(NetQueryPtr &result) {
|
void AuthManager::on_log_out_result(NetQueryPtr &result) {
|
||||||
Status status;
|
auto r_log_out = fetch_result<telegram_api::auth_logOut>(std::move(result));
|
||||||
if (result->is_ok()) {
|
|
||||||
auto r_log_out = fetch_result<telegram_api::auth_logOut>(result->ok());
|
|
||||||
if (r_log_out.is_ok()) {
|
if (r_log_out.is_ok()) {
|
||||||
auto logged_out = r_log_out.move_as_ok();
|
auto logged_out = r_log_out.move_as_ok();
|
||||||
if (!logged_out->future_auth_token_.empty()) {
|
if (!logged_out->future_auth_token_.empty()) {
|
||||||
td_->option_manager_->set_option_string("authentication_token",
|
td_->option_manager_->set_option_string("authentication_token",
|
||||||
base64url_encode(logged_out->future_auth_token_.as_slice()));
|
base64url_encode(logged_out->future_auth_token_.as_slice()));
|
||||||
}
|
}
|
||||||
} else {
|
} else if (r_log_out.error().code() != 401) {
|
||||||
status = r_log_out.move_as_error();
|
LOG(ERROR) << "Receive error for auth.logOut: " << r_log_out.error();
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
status = std::move(result->error());
|
|
||||||
}
|
|
||||||
LOG_IF(ERROR, status.is_error() && status.code() != 401) << "Receive error for auth.logOut: " << status;
|
|
||||||
// state_ will stay LoggingOut, so no queries will work.
|
// state_ will stay LoggingOut, so no queries will work.
|
||||||
destroy_auth_keys();
|
destroy_auth_keys();
|
||||||
if (query_id_ != 0) {
|
if (query_id_ != 0) {
|
||||||
@ -1196,32 +1178,28 @@ void AuthManager::destroy_auth_keys() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void AuthManager::on_delete_account_result(NetQueryPtr &result) {
|
void AuthManager::on_delete_account_result(NetQueryPtr &result) {
|
||||||
Status status;
|
auto r_delete_account = fetch_result<telegram_api::account_deleteAccount>(std::move(result));
|
||||||
if (result->is_ok()) {
|
|
||||||
auto r_delete_account = fetch_result<telegram_api::account_deleteAccount>(result->ok());
|
|
||||||
if (r_delete_account.is_ok()) {
|
if (r_delete_account.is_ok()) {
|
||||||
if (!r_delete_account.ok()) {
|
if (!r_delete_account.ok()) {
|
||||||
// status = Status::Error(500, "Receive false as result of the request");
|
// status = Status::Error(500, "Receive false as result of the request");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
status = r_delete_account.move_as_error();
|
auto status = r_delete_account.move_as_error();
|
||||||
}
|
if (status.message() != "USER_DEACTIVATED") {
|
||||||
} else {
|
|
||||||
status = std::move(result->error());
|
|
||||||
}
|
|
||||||
if (status.is_error() && status.message() != "USER_DEACTIVATED") {
|
|
||||||
LOG(WARNING) << "Request account.deleteAccount failed: " << status;
|
LOG(WARNING) << "Request account.deleteAccount failed: " << status;
|
||||||
// TODO handle some errors
|
// TODO handle some errors
|
||||||
if (query_id_ != 0) {
|
if (query_id_ != 0) {
|
||||||
on_query_error(std::move(status));
|
on_query_error(std::move(status));
|
||||||
}
|
}
|
||||||
} else {
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
destroy_auth_keys();
|
destroy_auth_keys();
|
||||||
if (query_id_ != 0) {
|
if (query_id_ != 0) {
|
||||||
on_query_ok();
|
on_query_ok();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void AuthManager::on_get_authorization(tl_object_ptr<telegram_api::auth_Authorization> auth_ptr) {
|
void AuthManager::on_get_authorization(tl_object_ptr<telegram_api::auth_Authorization> auth_ptr) {
|
||||||
if (state_ == State::Ok) {
|
if (state_ == State::Ok) {
|
||||||
@ -1347,7 +1325,7 @@ void AuthManager::on_result(NetQueryPtr result) {
|
|||||||
was_qr_code_request_ = false;
|
was_qr_code_request_ = false;
|
||||||
was_check_bot_token_ = false;
|
was_check_bot_token_ = false;
|
||||||
}
|
}
|
||||||
on_query_error(std::move(result->error()));
|
on_query_error(result->move_as_error());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (type != NetQueryType::RequestQrCode && type != NetQueryType::ImportQrCode &&
|
if (type != NetQueryType::RequestQrCode && type != NetQueryType::ImportQrCode &&
|
||||||
|
@ -296,7 +296,7 @@ Result<std::pair<NetQueryPtr, bool>> FileUploader::start_part(Part part, int32 p
|
|||||||
|
|
||||||
Result<size_t> FileUploader::process_part(Part part, NetQueryPtr net_query) {
|
Result<size_t> FileUploader::process_part(Part part, NetQueryPtr net_query) {
|
||||||
if (net_query->is_error()) {
|
if (net_query->is_error()) {
|
||||||
return std::move(net_query->error());
|
return net_query->move_as_error();
|
||||||
}
|
}
|
||||||
Result<bool> result = [&] {
|
Result<bool> result = [&] {
|
||||||
if (big_flag_) {
|
if (big_flag_) {
|
||||||
|
Loading…
Reference in New Issue
Block a user