From 77772caabb5f5f201ffca9aabcd191708b025437 Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 12 Aug 2022 22:08:59 +0300 Subject: [PATCH] Update API scheme on layer 145. --- Telegram/Resources/tl/api.tl | 27 +++++++++++++--- .../SourceFiles/api/api_confirm_phone.cpp | 18 +++++++---- .../SourceFiles/boxes/change_phone_box.cpp | 21 +++++++----- Telegram/SourceFiles/intro/intro_code.cpp | 4 ++- Telegram/SourceFiles/intro/intro_step.cpp | 13 ++++++-- .../passport/passport_form_controller.cpp | 32 ++++++++++++------- 6 files changed, 81 insertions(+), 34 deletions(-) diff --git a/Telegram/Resources/tl/api.tl b/Telegram/Resources/tl/api.tl index 1455ec1f3..13b655aab 100644 --- a/Telegram/Resources/tl/api.tl +++ b/Telegram/Resources/tl/api.tl @@ -393,6 +393,7 @@ updateBotMenuButton#14b85813 bot_id:long button:BotMenuButton = Update; updateSavedRingtones#74d8be99 = Update; updateTranscribedAudio#84cd5a flags:# pending:flags.0?true peer:Peer msg_id:int transcription_id:long text:string = Update; updateReadFeaturedEmojiStickers#fb4c496c = Update; +updateRecentEmojiStatuses#30f443db = Update; updates.state#a56c2a3e pts:int qts:int date:int seq:int unread_count:int = updates.State; @@ -557,7 +558,7 @@ authorization#ad01d61d flags:# current:flags.0?true official_app:flags.1?true pa account.authorizations#4bff8ea0 authorization_ttl_days:int authorizations:Vector = account.Authorizations; -account.password#185b184f flags:# has_recovery:flags.0?true has_secure_values:flags.1?true has_password:flags.2?true current_algo:flags.2?PasswordKdfAlgo srp_B:flags.2?bytes srp_id:flags.2?long hint:flags.3?string email_unconfirmed_pattern:flags.4?string new_algo:PasswordKdfAlgo new_secure_algo:SecurePasswordKdfAlgo secure_random:bytes pending_reset_date:flags.5?int = account.Password; +account.password#957b50fb flags:# has_recovery:flags.0?true has_secure_values:flags.1?true has_password:flags.2?true current_algo:flags.2?PasswordKdfAlgo srp_B:flags.2?bytes srp_id:flags.2?long hint:flags.3?string email_unconfirmed_pattern:flags.4?string new_algo:PasswordKdfAlgo new_secure_algo:SecurePasswordKdfAlgo secure_random:bytes pending_reset_date:flags.5?int login_email_pattern:flags.6?string = account.Password; account.passwordSettings#9a5c33e5 flags:# email:flags.0?string secure_settings:flags.1?SecureSecretSettings = account.PasswordSettings; @@ -716,6 +717,8 @@ auth.sentCodeTypeSms#c000bba2 length:int = auth.SentCodeType; auth.sentCodeTypeCall#5353e5a7 length:int = auth.SentCodeType; auth.sentCodeTypeFlashCall#ab03c6d9 pattern:string = auth.SentCodeType; auth.sentCodeTypeMissedCall#82006484 prefix:string length:int = auth.SentCodeType; +auth.sentCodeTypeEmailCode#5a159841 flags:# apple_signin_allowed:flags.0?true google_signin_allowed:flags.1?true email_pattern:string length:int next_phone_login_date:flags.2?int = auth.SentCodeType; +auth.sentCodeTypeSetUpEmailRequired#a5491dea flags:# apple_signin_allowed:flags.0?true google_signin_allowed:flags.1?true = auth.SentCodeType; messages.botCallbackAnswer#36585ea4 flags:# alert:flags.1?true has_url:flags.3?true native_ui:flags.4?true message:flags.0?string url:flags.2?string cache_time:int = messages.BotCallbackAnswer; @@ -1406,6 +1409,20 @@ paymentFormMethod#88f8f21b url:string title:string = PaymentFormMethod; emojiStatusEmpty#2de11aae = EmojiStatus; emojiStatus#929b619d document_id:long = EmojiStatus; +account.emojiStatusesNotModified#d08ce645 = account.EmojiStatuses; +account.emojiStatuses#90c467d1 hash:long statuses:Vector = account.EmojiStatuses; + +emailVerifyPurposeLoginSetup#4345be73 phone_number:string phone_code_hash:string = EmailVerifyPurpose; +emailVerifyPurposeLoginChange#527d22eb = EmailVerifyPurpose; +emailVerifyPurposePassport#bbf51685 = EmailVerifyPurpose; + +emailVerificationCode#922e55a9 code:string = EmailVerification; +emailVerificationGoogle#db909ec2 token:string = EmailVerification; +emailVerificationApple#96d074fd token:string = EmailVerification; + +account.emailVerified#2b96cd1b email:string = account.EmailVerified; +account.emailVerifiedLogin#e1bb0d61 email:string sent_code:auth.SentCode = account.EmailVerified; + ---functions--- invokeAfterMsg#cb9f372d {X:Type} msg_id:long query:!X = X; @@ -1418,7 +1435,7 @@ invokeWithTakeout#aca9fd2e {X:Type} takeout_id:long query:!X = X; auth.sendCode#a677244f phone_number:string api_id:int api_hash:string settings:CodeSettings = auth.SentCode; auth.signUp#80eee427 phone_number:string phone_code_hash:string first_name:string last_name:string = auth.Authorization; -auth.signIn#bcd51581 phone_number:string phone_code_hash:string phone_code:string = auth.Authorization; +auth.signIn#8d52a951 flags:# phone_number:string phone_code_hash:string phone_code:flags.0?string email_verification:flags.1?EmailVerification = auth.Authorization; auth.logOut#3e72ba19 = auth.LoggedOut; auth.resetAuthorizations#9fab0d1a = Bool; auth.exportAuthorization#e5bfffcd dc_id:int = auth.ExportedAuthorization; @@ -1474,8 +1491,8 @@ account.getAuthorizationForm#a929597a bot_id:long scope:string public_key:string account.acceptAuthorization#f3ed4c73 bot_id:long scope:string public_key:string value_hashes:Vector credentials:SecureCredentialsEncrypted = Bool; account.sendVerifyPhoneCode#a5a356f9 phone_number:string settings:CodeSettings = auth.SentCode; account.verifyPhone#4dd3a7f6 phone_number:string phone_code_hash:string phone_code:string = Bool; -account.sendVerifyEmailCode#7011509f email:string = account.SentEmailCode; -account.verifyEmail#ecba39db email:string code:string = Bool; +account.sendVerifyEmailCode#98e037bb purpose:EmailVerifyPurpose email:string = account.SentEmailCode; +account.verifyEmail#32da4cf purpose:EmailVerifyPurpose verification:EmailVerification = account.EmailVerified; account.initTakeoutSession#8ef3eab0 flags:# contacts:flags.0?true message_users:flags.1?true message_chats:flags.2?true message_megagroups:flags.3?true message_channels:flags.4?true files:flags.5?true file_max_size:flags.5?long = account.Takeout; account.finishTakeoutSession#1d2652ee flags:# success:flags.0?true = Bool; account.confirmPasswordEmail#8fdf1920 code:string = Bool; @@ -1513,6 +1530,8 @@ account.getSavedRingtones#e1902288 hash:long = account.SavedRingtones; account.saveRingtone#3dea5b03 id:InputDocument unsave:Bool = account.SavedRingtone; account.uploadRingtone#831a83a2 file:InputFile file_name:string mime_type:string = Document; account.updateEmojiStatus#fbd3de6b emoji_status:EmojiStatus = Bool; +account.getEmojiStatuses#266dca30 flags:# default:flags.0?true recent:flags.1?true hash:long = account.EmojiStatuses; +account.clearRecentEmojiStatuses#18201aae = Bool; users.getUsers#d91a548 id:Vector = Vector; users.getFullUser#b60f5918 id:InputUser = users.UserFull; diff --git a/Telegram/SourceFiles/api/api_confirm_phone.cpp b/Telegram/SourceFiles/api/api_confirm_phone.cpp index 224f06b4f..748d1f011 100644 --- a/Telegram/SourceFiles/api/api_confirm_phone.cpp +++ b/Telegram/SourceFiles/api/api_confirm_phone.cpp @@ -35,6 +35,10 @@ void ConfirmPhone::resolve( _sendRequestId = 0; result.match([&](const MTPDauth_sentCode &data) { + const auto bad = [](const char *type) { + LOG(("API Error: Should not be '%1'.").arg(type)); + return 0; + }; const auto sentCodeLength = data.vtype().match([&]( const MTPDauth_sentCodeTypeApp &data) { LOG(("Error: should not be in-app code!")); @@ -43,12 +47,14 @@ void ConfirmPhone::resolve( return data.vlength().v; }, [&](const MTPDauth_sentCodeTypeCall &data) { return data.vlength().v; - }, [&](const MTPDauth_sentCodeTypeFlashCall &data) { - LOG(("Error: should not be flashcall!")); - return 0; - }, [&](const MTPDauth_sentCodeTypeMissedCall &data) { - LOG(("Error: should not be missedcall!")); - return 0; + }, [&](const MTPDauth_sentCodeTypeFlashCall &) { + return bad("FlashCall"); + }, [&](const MTPDauth_sentCodeTypeMissedCall &) { + return bad("MissedCall"); + }, [&](const MTPDauth_sentCodeTypeEmailCode &) { + return bad("EmailCode"); + }, [&](const MTPDauth_sentCodeTypeSetUpEmailRequired &) { + return bad("SetUpEmailRequired"); }); const auto phoneHash = qs(data.vphone_code_hash()); const auto timeout = [&]() -> std::optional { diff --git a/Telegram/SourceFiles/boxes/change_phone_box.cpp b/Telegram/SourceFiles/boxes/change_phone_box.cpp index dead1d2c3..ed83a6408 100644 --- a/Telegram/SourceFiles/boxes/change_phone_box.cpp +++ b/Telegram/SourceFiles/boxes/change_phone_box.cpp @@ -215,6 +215,11 @@ void ChangePhone::EnterPhone::sendPhoneDone( return data; }); + const auto bad = [&](const char *type) { + LOG(("API Error: Should not be '%1'.").arg(type)); + showError(Lang::Hard::ServerError()); + return false; + }; auto codeLength = 0; const auto hasLength = data.vtype().match([&]( const MTPDauth_sentCodeTypeApp &typeData) { @@ -227,14 +232,14 @@ void ChangePhone::EnterPhone::sendPhoneDone( }, [&](const MTPDauth_sentCodeTypeCall &typeData) { codeLength = typeData.vlength().v; return true; - }, [&](const MTPDauth_sentCodeTypeFlashCall &typeData) { - LOG(("Error: should not be flashcall!")); - showError(Lang::Hard::ServerError()); - return false; - }, [&](const MTPDauth_sentCodeTypeMissedCall &data) { - LOG(("Error: should not be missedcall!")); - showError(Lang::Hard::ServerError()); - return false; + }, [&](const MTPDauth_sentCodeTypeFlashCall &) { + return bad("FlashCall"); + }, [&](const MTPDauth_sentCodeTypeMissedCall &) { + return bad("MissedCall"); + }, [&](const MTPDauth_sentCodeTypeEmailCode &) { + return bad("EmailCode"); + }, [&](const MTPDauth_sentCodeTypeSetUpEmailRequired &) { + return bad("SetUpEmailRequired"); }); if (!hasLength) { return; diff --git a/Telegram/SourceFiles/intro/intro_code.cpp b/Telegram/SourceFiles/intro/intro_code.cpp index 47baa5c49..b09292934 100644 --- a/Telegram/SourceFiles/intro/intro_code.cpp +++ b/Telegram/SourceFiles/intro/intro_code.cpp @@ -381,9 +381,11 @@ void CodeWidget::submit() { _sentCode = text; getData()->pwdState = Core::CloudPasswordState(); _sentRequest = api().request(MTPauth_SignIn( + MTP_flags(MTPauth_SignIn::Flag::f_phone_code), MTP_string(getData()->phone), MTP_bytes(getData()->phoneHash), - MTP_string(_sentCode) + MTP_string(_sentCode), + MTPEmailVerification() )).done([=](const MTPauth_Authorization &result) { codeSubmitDone(result); }).fail([=](const MTP::Error &error) { diff --git a/Telegram/SourceFiles/intro/intro_step.cpp b/Telegram/SourceFiles/intro/intro_step.cpp index a78431ceb..15e322d94 100644 --- a/Telegram/SourceFiles/intro/intro_step.cpp +++ b/Telegram/SourceFiles/intro/intro_step.cpp @@ -311,6 +311,9 @@ bool Step::paintAnimated(Painter &p, QRect clip) { } void Step::fillSentCodeData(const MTPDauth_sentCode &data) { + const auto bad = [](const char *type) { + LOG(("API Error: Should not be '%1'.").arg(type)); + }; data.vtype().match([&](const MTPDauth_sentCodeTypeApp &data) { getData()->codeByTelegram = true; getData()->codeLength = data.vlength().v; @@ -321,9 +324,13 @@ void Step::fillSentCodeData(const MTPDauth_sentCode &data) { getData()->codeByTelegram = false; getData()->codeLength = data.vlength().v; }, [&](const MTPDauth_sentCodeTypeFlashCall &) { - LOG(("Error: should not be flashcall!")); - }, [&](const MTPDauth_sentCodeTypeMissedCall &data) { - LOG(("Error: should not be missedcall!")); + bad("FlashCall"); + }, [&](const MTPDauth_sentCodeTypeMissedCall &) { + bad("MissedCall"); + }, [&](const MTPDauth_sentCodeTypeEmailCode &) { + bad("EmailCode"); + }, [&](const MTPDauth_sentCodeTypeSetUpEmailRequired &) { + bad("SetUpEmailRequired"); }); } diff --git a/Telegram/SourceFiles/passport/passport_form_controller.cpp b/Telegram/SourceFiles/passport/passport_form_controller.cpp index 28fe296c7..5ec8d0aba 100644 --- a/Telegram/SourceFiles/passport/passport_form_controller.cpp +++ b/Telegram/SourceFiles/passport/passport_form_controller.cpp @@ -1719,9 +1719,9 @@ void FormController::verify( }).send(); case Value::Type::Email: return _api.request(MTPaccount_VerifyEmail( - MTP_string(getEmailFromValue(nonconst)), - MTP_string(prepared) - )).done([=](const MTPBool &result) { + MTP_emailVerifyPurposePassport(), + MTP_emailVerificationCode(MTP_string(prepared)) + )).done([=](const MTPaccount_EmailVerified &result) { savePlainTextValue(nonconst); clearValueVerification(nonconst); }).fail([=](const MTP::Error &error) { @@ -2174,15 +2174,13 @@ void FormController::startPhoneVerification(not_null value) { const auto timeout = data.vtimeout(); value->verification.requestId = 0; value->verification.phoneCodeHash = qs(data.vphone_code_hash()); + const auto bad = [](const char *type) { + LOG(("API Error: Should not be '%1' " + "in FormController::startPhoneVerification.").arg(type)); + }; data.vtype().match([&](const MTPDauth_sentCodeTypeApp &) { LOG(("API Error: sentCodeTypeApp not expected " "in FormController::startPhoneVerification.")); - }, [&](const MTPDauth_sentCodeTypeFlashCall &) { - LOG(("API Error: sentCodeTypeFlashCall not expected " - "in FormController::startPhoneVerification.")); - }, [&](const MTPDauth_sentCodeTypeMissedCall &data) { - LOG(("API Error: sentCodeTypeMissedCall not expected " - "in FormController::startPhoneVerification.")); }, [&](const MTPDauth_sentCodeTypeCall &data) { value->verification.codeLength = (data.vlength().v > 0) ? data.vlength().v @@ -2208,6 +2206,14 @@ void FormController::startPhoneVerification(not_null value) { timeout.value_or(60), }); } + }, [&](const MTPDauth_sentCodeTypeFlashCall &) { + bad("FlashCall"); + }, [&](const MTPDauth_sentCodeTypeMissedCall &) { + bad("MissedCall"); + }, [&](const MTPDauth_sentCodeTypeEmailCode &) { + bad("EmailCode"); + }, [&](const MTPDauth_sentCodeTypeSetUpEmailRequired &) { + bad("SetUpEmailRequired"); }); _verificationNeeded.fire_copy(value); }); @@ -2218,9 +2224,11 @@ void FormController::startPhoneVerification(not_null value) { } void FormController::startEmailVerification(not_null value) { - value->verification.requestId = _api.request(MTPaccount_SendVerifyEmailCode( - MTP_string(getEmailFromValue(value)) - )).done([=](const MTPaccount_SentEmailCode &result) { + value->verification.requestId = _api.request( + MTPaccount_SendVerifyEmailCode( + MTP_emailVerifyPurposePassport(), + MTP_string(getEmailFromValue(value))) + ).done([=](const MTPaccount_SentEmailCode &result) { Expects(result.type() == mtpc_account_sentEmailCode); value->verification.requestId = 0;