mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
51 lines
1.6 KiB
Swift
51 lines
1.6 KiB
Swift
import Foundation
|
|
import Postbox
|
|
import TelegramApi
|
|
import SwiftSignalKit
|
|
|
|
public func requestRecentAccountSessions(account: Account) -> Signal<[RecentAccountSession], NoError> {
|
|
return account.network.request(Api.functions.account.getAuthorizations())
|
|
|> retryRequest
|
|
|> map { result -> [RecentAccountSession] in
|
|
var sessions: [RecentAccountSession] = []
|
|
switch result {
|
|
case let .authorizations(authorizations):
|
|
for authorization in authorizations {
|
|
sessions.append(RecentAccountSession(apiAuthorization: authorization))
|
|
}
|
|
}
|
|
return sessions
|
|
}
|
|
}
|
|
|
|
public enum TerminateSessionError {
|
|
case generic
|
|
case freshReset
|
|
}
|
|
|
|
public func terminateAccountSession(account: Account, hash: Int64) -> Signal<Void, TerminateSessionError> {
|
|
return account.network.request(Api.functions.account.resetAuthorization(hash: hash))
|
|
|> mapError { error -> TerminateSessionError in
|
|
if error.errorCode == 406 {
|
|
return .freshReset
|
|
}
|
|
return .generic
|
|
}
|
|
|> mapToSignal { _ -> Signal<Void, TerminateSessionError> in
|
|
return .single(Void())
|
|
}
|
|
}
|
|
|
|
public func terminateOtherAccountSessions(account: Account) -> Signal<Void, TerminateSessionError> {
|
|
return account.network.request(Api.functions.auth.resetAuthorizations())
|
|
|> mapError { error -> TerminateSessionError in
|
|
if error.errorCode == 406 {
|
|
return .freshReset
|
|
}
|
|
return .generic
|
|
}
|
|
|> mapToSignal { _ -> Signal<Void, TerminateSessionError> in
|
|
return .single(Void())
|
|
}
|
|
}
|