Phone number change improvements

This commit is contained in:
Ilya Laktyushin
2022-11-27 21:48:44 +04:00
parent a73a704910
commit c2f42f03e5
12 changed files with 452 additions and 422 deletions

View File

@@ -120,7 +120,7 @@ public final class AuthorizationSequenceController: NavigationController, MFMail
let masterDatacenterId = strongSelf.account.masterDatacenterId
let isTestingEnvironment = strongSelf.account.testingEnvironment
let countryCode = defaultCountryCode()
let countryCode = AuthorizationSequenceController.defaultCountryCode()
let _ = TelegramEngineUnauthorized(account: strongSelf.account).auth.setState(state: UnauthorizedAccountState(isTestingEnvironment: isTestingEnvironment, masterDatacenterId: masterDatacenterId, contents: .phoneEntry(countryCode: countryCode, number: ""))).start()
}
@@ -275,13 +275,11 @@ public final class AuthorizationSequenceController: NavigationController, MFMail
if let currentController = currentController {
controller = currentController
} else {
controller = AuthorizationSequenceCodeEntryController(presentationData: self.presentationData, openUrl: { [weak self] url in
self?.openUrl(url)
}, back: { [weak self] in
controller = AuthorizationSequenceCodeEntryController(presentationData: self.presentationData, back: { [weak self] in
guard let strongSelf = self else {
return
}
let countryCode = defaultCountryCode()
let countryCode = AuthorizationSequenceController.defaultCountryCode()
let _ = TelegramEngineUnauthorized(account: strongSelf.account).auth.setState(state: UnauthorizedAccountState(isTestingEnvironment: strongSelf.account.testingEnvironment, masterDatacenterId: strongSelf.account.masterDatacenterId, contents: .phoneEntry(countryCode: countryCode, number: ""))).start()
})
@@ -542,7 +540,7 @@ public final class AuthorizationSequenceController: NavigationController, MFMail
guard let strongSelf = self else {
return
}
let countryCode = defaultCountryCode()
let countryCode = AuthorizationSequenceController.defaultCountryCode()
let _ = TelegramEngineUnauthorized(account: strongSelf.account).auth.setState(state: UnauthorizedAccountState(isTestingEnvironment: strongSelf.account.testingEnvironment, masterDatacenterId: strongSelf.account.masterDatacenterId, contents: .phoneEntry(countryCode: countryCode, number: ""))).start()
})
@@ -707,7 +705,7 @@ public final class AuthorizationSequenceController: NavigationController, MFMail
guard let strongSelf = self else {
return
}
let countryCode = defaultCountryCode()
let countryCode = AuthorizationSequenceController.defaultCountryCode()
let _ = TelegramEngineUnauthorized(account: strongSelf.account).auth.setState(state: UnauthorizedAccountState(isTestingEnvironment: strongSelf.account.testingEnvironment, masterDatacenterId: strongSelf.account.masterDatacenterId, contents: .phoneEntry(countryCode: countryCode, number: ""))).start()
})
@@ -852,7 +850,7 @@ public final class AuthorizationSequenceController: NavigationController, MFMail
guard let strongSelf = self else {
return
}
let countryCode = defaultCountryCode()
let countryCode = AuthorizationSequenceController.defaultCountryCode()
let _ = TelegramEngineUnauthorized(account: strongSelf.account).auth.setState(state: UnauthorizedAccountState(isTestingEnvironment: strongSelf.account.testingEnvironment, masterDatacenterId: strongSelf.account.masterDatacenterId, contents: .phoneEntry(countryCode: countryCode, number: ""))).start()
})
@@ -912,7 +910,7 @@ public final class AuthorizationSequenceController: NavigationController, MFMail
guard let strongSelf = self else {
return
}
let countryCode = defaultCountryCode()
let countryCode = AuthorizationSequenceController.defaultCountryCode()
let _ = TelegramEngineUnauthorized(account: strongSelf.account).auth.setState(state: UnauthorizedAccountState(isTestingEnvironment: strongSelf.account.testingEnvironment, masterDatacenterId: strongSelf.account.masterDatacenterId, contents: .phoneEntry(countryCode: countryCode, number: ""))).start()
}, displayCancel: displayCancel)
@@ -1022,7 +1020,7 @@ public final class AuthorizationSequenceController: NavigationController, MFMail
if self.otherAccountPhoneNumbers.1.isEmpty {
controllers.append(self.splashController())
} else {
controllers.append(self.phoneEntryController(countryCode: defaultCountryCode(), number: "", splashController: nil))
controllers.append(self.phoneEntryController(countryCode: AuthorizationSequenceController.defaultCountryCode(), number: "", splashController: nil))
}
self.setViewControllers(controllers, animated: !self.viewControllers.isEmpty)
}
@@ -1050,7 +1048,7 @@ public final class AuthorizationSequenceController: NavigationController, MFMail
if !self.otherAccountPhoneNumbers.1.isEmpty {
controllers.append(self.splashController())
}
controllers.append(self.phoneEntryController(countryCode: defaultCountryCode(), number: "", splashController: nil))
controllers.append(self.phoneEntryController(countryCode: AuthorizationSequenceController.defaultCountryCode(), number: "", splashController: nil))
if case let .emailSetupRequired(appleSignInAllowed) = type {
self.appleSignInAllowed = appleSignInAllowed
controllers.append(self.emailSetupController(number: number, appleSignInAllowed: appleSignInAllowed))
@@ -1156,30 +1154,30 @@ public final class AuthorizationSequenceController: NavigationController, MFMail
self?.presentingViewController?.dismiss(animated: false, completion: nil)
})
}
}
private func defaultCountryCode() -> Int32 {
var countryId: String? = nil
let networkInfo = CTTelephonyNetworkInfo()
if let carrier = networkInfo.subscriberCellularProvider {
countryId = carrier.isoCountryCode
}
if countryId == nil {
countryId = (Locale.current as NSLocale).object(forKey: .countryCode) as? String
}
var countryCode: Int32 = 1
if let countryId = countryId {
let normalizedId = countryId.uppercased()
for (code, idAndName) in countryCodeToIdAndName {
if idAndName.0 == normalizedId {
countryCode = Int32(code)
break
public static func defaultCountryCode() -> Int32 {
var countryId: String? = nil
let networkInfo = CTTelephonyNetworkInfo()
if let carrier = networkInfo.subscriberCellularProvider {
countryId = carrier.isoCountryCode
}
if countryId == nil {
countryId = (Locale.current as NSLocale).object(forKey: .countryCode) as? String
}
var countryCode: Int32 = 1
if let countryId = countryId {
let normalizedId = countryId.uppercased()
for (code, idAndName) in countryCodeToIdAndName {
if idAndName.0 == normalizedId {
countryCode = Int32(code)
break
}
}
}
return countryCode
}
return countryCode
}