Files
Swiftgram/submodules/TelegramCore/Sources/TelegramEngine/SecureId/SecureIdConfiguration.swift
Isaac a78b2c0db2 Refactor Api types 70-89 to use struct-wrapped constructors
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>
2026-01-16 02:12:20 +08:00

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
}
}
}
}