mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-22 14:20:20 +00:00
Refactoring
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
import Foundation
|
||||
import Postbox
|
||||
import TelegramApi
|
||||
import SwiftSignalKit
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
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())
|
||||
}
|
||||
}
|
||||
|
||||
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())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user