Fix already logged in accounts check

This commit is contained in:
Ilya Laktyushin 2023-03-03 14:38:07 +04:00
parent 4f5d1445ae
commit b1545c9f17
2 changed files with 17 additions and 3 deletions

View File

@ -254,17 +254,17 @@ public final class AuthorizationSequencePhoneEntryController: ViewController, MF
@objc func nextPressed() { @objc func nextPressed() {
let (_, _, number) = self.controllerNode.codeAndNumber let (_, _, number) = self.controllerNode.codeAndNumber
if !number.isEmpty { if !number.isEmpty {
let logInNumber = formatPhoneNumber(self.controllerNode.currentNumber) let logInNumber = cleanPhoneNumber(self.controllerNode.currentNumber, removePlus: true)
var existing: (String, AccountRecordId)? var existing: (String, AccountRecordId)?
for (number, id, isTestingEnvironment) in self.otherAccountPhoneNumbers.1 { 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) existing = (number, id)
} }
} }
if let (_, id) = existing { if let (_, id) = existing {
var actions: [TextAlertAction] = [] 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 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?.sharedContext.switchToAccount(id: id, fromSettingsController: nil, withChatListController: nil)
self?.back() self?.back()

View File

@ -5,6 +5,20 @@ import TelegramCore
private let phoneNumberUtil = NBPhoneNumberUtil() 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 { public func formatPhoneNumber(_ string: String) -> String {
do { do {
let number = try phoneNumberUtil.parse("+" + string, defaultRegion: nil) let number = try phoneNumberUtil.parse("+" + string, defaultRegion: nil)