mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-08-17 11:00:07 +00:00

Added support for "contact joined" service messages Updated password recovery API Updated Localization APIs Added limited contact presence polling after getDifference
50 lines
1.5 KiB
Swift
50 lines
1.5 KiB
Swift
import Foundation
|
|
#if os(macOS)
|
|
import SwiftSignalKitMac
|
|
import MtProtoKitMac
|
|
#else
|
|
import SwiftSignalKit
|
|
import MtProtoKitDynamic
|
|
#endif
|
|
|
|
public enum ConfirmTwoStepRecoveryEmailError {
|
|
case invalidEmail
|
|
case invalidCode
|
|
case flood
|
|
case expired
|
|
case generic
|
|
}
|
|
|
|
public func confirmTwoStepRecoveryEmail(network: Network, code: String) -> Signal<Never, ConfirmTwoStepRecoveryEmailError> {
|
|
return network.request(Api.functions.account.confirmPasswordEmail(code: code), automaticFloodWait: false)
|
|
|> mapError { error -> ConfirmTwoStepRecoveryEmailError in
|
|
if error.errorDescription == "EMAIL_INVALID" {
|
|
return .invalidEmail
|
|
} else if error.errorDescription == "CODE_INVALID" {
|
|
return .invalidCode
|
|
} else if error.errorDescription == "EMAIL_HASH_EXPIRED" {
|
|
return .expired
|
|
} else if error.errorDescription.hasPrefix("FLOOD_WAIT") {
|
|
return .flood
|
|
}
|
|
return .generic
|
|
}
|
|
|> ignoreValues
|
|
}
|
|
|
|
public enum ResendTwoStepRecoveryEmailError {
|
|
case flood
|
|
case generic
|
|
}
|
|
|
|
public func resendTwoStepRecoveryEmail(network: Network) -> Signal<Never, ResendTwoStepRecoveryEmailError> {
|
|
return network.request(Api.functions.account.resendPasswordEmail(), automaticFloodWait: false)
|
|
|> mapError { error -> ResendTwoStepRecoveryEmailError in
|
|
if error.errorDescription.hasPrefix("FLOOD_WAIT") {
|
|
return .flood
|
|
}
|
|
return .generic
|
|
}
|
|
|> ignoreValues
|
|
}
|