mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
25 lines
815 B
Swift
25 lines
815 B
Swift
import Foundation
|
|
import Postbox
|
|
import SwiftSignalKit
|
|
|
|
public enum AddressNameValidationStatus: Equatable {
|
|
case checking
|
|
case invalidFormat(AddressNameFormatError)
|
|
case availability(AddressNameAvailability)
|
|
}
|
|
|
|
public func validateAddressNameInteractive(account: Account, domain: AddressNameDomain, name: String) -> Signal<AddressNameValidationStatus, NoError> {
|
|
if let error = checkAddressNameFormat(name) {
|
|
return .single(.invalidFormat(error))
|
|
} else {
|
|
return .single(.checking)
|
|
|> then(
|
|
addressNameAvailability(account: account, domain: domain, name: name)
|
|
|> delay(0.3, queue: Queue.concurrentDefaultQueue())
|
|
|> map { result -> AddressNameValidationStatus in
|
|
.availability(result)
|
|
}
|
|
)
|
|
}
|
|
}
|