mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
Fix already logged in accounts check
This commit is contained in:
parent
4f5d1445ae
commit
b1545c9f17
@ -254,17 +254,17 @@ public final class AuthorizationSequencePhoneEntryController: ViewController, MF
|
||||
@objc func nextPressed() {
|
||||
let (_, _, number) = self.controllerNode.codeAndNumber
|
||||
if !number.isEmpty {
|
||||
let logInNumber = formatPhoneNumber(self.controllerNode.currentNumber)
|
||||
let logInNumber = cleanPhoneNumber(self.controllerNode.currentNumber, removePlus: true)
|
||||
var existing: (String, AccountRecordId)?
|
||||
for (number, id, isTestingEnvironment) in self.otherAccountPhoneNumbers.1 {
|
||||
if isTestingEnvironment == self.isTestingEnvironment && formatPhoneNumber(number) == logInNumber {
|
||||
if isTestingEnvironment == self.isTestingEnvironment && cleanPhoneNumber(number, removePlus: true) == logInNumber {
|
||||
existing = (number, id)
|
||||
}
|
||||
}
|
||||
|
||||
if let (_, id) = existing {
|
||||
var actions: [TextAlertAction] = []
|
||||
if let (current, _, _) = self.otherAccountPhoneNumbers.0, logInNumber != formatPhoneNumber(current) {
|
||||
if let (current, _, _) = self.otherAccountPhoneNumbers.0, logInNumber != cleanPhoneNumber(current, removePlus: true) {
|
||||
actions.append(TextAlertAction(type: .genericAction, title: self.presentationData.strings.Login_PhoneNumberAlreadyAuthorizedSwitch, action: { [weak self] in
|
||||
self?.sharedContext.switchToAccount(id: id, fromSettingsController: nil, withChatListController: nil)
|
||||
self?.back()
|
||||
|
@ -5,6 +5,20 @@ import TelegramCore
|
||||
|
||||
private let phoneNumberUtil = NBPhoneNumberUtil()
|
||||
|
||||
public func cleanPhoneNumber(_ text: String, removePlus: Bool = false) -> String {
|
||||
var result = ""
|
||||
for c in text {
|
||||
if c == "+" && !removePlus {
|
||||
if result.isEmpty {
|
||||
result += String(c)
|
||||
}
|
||||
} else if c >= "0" && c <= "9" {
|
||||
result += String(c)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
public func formatPhoneNumber(_ string: String) -> String {
|
||||
do {
|
||||
let number = try phoneNumberUtil.parse("+" + string, defaultRegion: nil)
|
||||
|
Loading…
x
Reference in New Issue
Block a user