mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2026-02-21 10:03:03 +00:00
Types refactored: - 70-79: contactStatus, dataJSON, dcOption, defaultHistoryTTL, dialog, dialogFolder, dialogFilter, dialogFilterChatlist, dialogFilterSuggested, dialogPeer, dialogPeerFolder, disallowedGiftsSettings, document, documentEmpty - 80-89: documentAttribute* (Audio, CustomEmoji, Filename, ImageSize, Sticker, Video), draftMessage, draftMessageEmpty, emailVerification* (Apple, Code, Google), emailVerifyPurposeLoginSetup, emoji* (Group, GroupGreeting, GroupPremium, Keyword, KeywordDeleted, KeywordsDifference, Language, List, Status, StatusCollectible), inputEmojiStatusCollectible Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
47 lines
2.1 KiB
Swift
47 lines
2.1 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(hash, 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
|
|
}
|
|
}
|
|
}
|
|
}
|