mirror of
https://github.com/GLEGram/GLEGram-iOS.git
synced 2026-04-24 20:06:39 +02:00
4647310322
Based on Swiftgram 12.5 (Telegram iOS 12.5). All GLEGram features ported and organized in GLEGram/ folder. Features: Ghost Mode, Saved Deleted Messages, Content Protection Bypass, Font Replacement, Fake Profile, Chat Export, Plugin System, and more. See CHANGELOG_12.5.md for full details.
48 lines
2.2 KiB
Swift
48 lines
2.2 KiB
Swift
import Foundation
|
|
import Postbox
|
|
import MtProtoKit
|
|
import SwiftSignalKit
|
|
import TelegramApi
|
|
|
|
|
|
public func secureIdConfiguration(postbox: Postbox, network: Network) -> Signal<SecureIdConfiguration, NoError> {
|
|
let cached: Signal<CachedSecureIdConfiguration?, NoError> = postbox.transaction { transaction -> CachedSecureIdConfiguration? in
|
|
if let entry = transaction.retrieveItemCacheEntry(id: ItemCacheEntryId(collectionId: Namespaces.CachedItemCollection.cachedSecureIdConfiguration, key: ValueBoxKey(length: 0)))?.get(CachedSecureIdConfiguration.self) {
|
|
return entry
|
|
} else {
|
|
return nil
|
|
}
|
|
}
|
|
return cached
|
|
|> mapToSignal { cached -> Signal<SecureIdConfiguration, NoError> in
|
|
return network.request(Api.functions.help.getPassportConfig(hash: cached?.hash ?? 0))
|
|
|> retryRequest
|
|
|> mapToSignal { result -> Signal<SecureIdConfiguration, NoError> in
|
|
let parsed: CachedSecureIdConfiguration
|
|
switch result {
|
|
case .passportConfigNotModified:
|
|
if let cached = cached {
|
|
return .single(cached.value)
|
|
} else {
|
|
assertionFailure()
|
|
return .complete()
|
|
}
|
|
case let .passportConfig(passportConfigData):
|
|
let (hash, countriesLangs) = (passportConfigData.hash, passportConfigData.countriesLangs)
|
|
switch countriesLangs {
|
|
case let .dataJSON(dataJSONData):
|
|
let data = dataJSONData.data
|
|
let value = SecureIdConfiguration(jsonString: data)
|
|
parsed = CachedSecureIdConfiguration(value: value, hash: hash)
|
|
}
|
|
}
|
|
return postbox.transaction { transaction -> SecureIdConfiguration in
|
|
if let entry = CodableEntry(parsed) {
|
|
transaction.putItemCacheEntry(id: ItemCacheEntryId(collectionId: Namespaces.CachedItemCollection.cachedSecureIdConfiguration, key: ValueBoxKey(length: 0)), entry: entry)
|
|
}
|
|
return parsed.value
|
|
}
|
|
}
|
|
}
|
|
}
|