From b1545c9f176cc0c93df1d8dbdf05133a9b50165e Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Fri, 3 Mar 2023 14:38:07 +0400 Subject: [PATCH] Fix already logged in accounts check --- ...AuthorizationSequencePhoneEntryController.swift | 6 +++--- .../PhoneNumberFormat/Sources/PhoneNumbers.swift | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/submodules/AuthorizationUI/Sources/AuthorizationSequencePhoneEntryController.swift b/submodules/AuthorizationUI/Sources/AuthorizationSequencePhoneEntryController.swift index 92033d4a8e..fd51831d55 100644 --- a/submodules/AuthorizationUI/Sources/AuthorizationSequencePhoneEntryController.swift +++ b/submodules/AuthorizationUI/Sources/AuthorizationSequencePhoneEntryController.swift @@ -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() diff --git a/submodules/PhoneNumberFormat/Sources/PhoneNumbers.swift b/submodules/PhoneNumberFormat/Sources/PhoneNumbers.swift index 4ff9d7f6d6..468652c8a6 100644 --- a/submodules/PhoneNumberFormat/Sources/PhoneNumbers.swift +++ b/submodules/PhoneNumberFormat/Sources/PhoneNumbers.swift @@ -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)