mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
[Temp] Control temp keys with app_config
This commit is contained in:
parent
cf40afc5a9
commit
a0c42a3e63
@ -4,21 +4,27 @@ public struct NetworkSettings: PreferencesEntry, Equatable {
|
||||
public var reducedBackupDiscoveryTimeout: Bool
|
||||
public var applicationUpdateUrlPrefix: String?
|
||||
public var backupHostOverride: String?
|
||||
public var defaultEnableTempKeys: Bool
|
||||
public var userEnableTempKeys: Bool?
|
||||
|
||||
public static var defaultSettings: NetworkSettings {
|
||||
return NetworkSettings(reducedBackupDiscoveryTimeout: false, applicationUpdateUrlPrefix: nil, backupHostOverride: nil)
|
||||
return NetworkSettings(reducedBackupDiscoveryTimeout: false, applicationUpdateUrlPrefix: nil, backupHostOverride: nil, defaultEnableTempKeys: true, userEnableTempKeys: nil)
|
||||
}
|
||||
|
||||
public init(reducedBackupDiscoveryTimeout: Bool, applicationUpdateUrlPrefix: String?, backupHostOverride: String?) {
|
||||
public init(reducedBackupDiscoveryTimeout: Bool, applicationUpdateUrlPrefix: String?, backupHostOverride: String?, defaultEnableTempKeys: Bool, userEnableTempKeys: Bool?) {
|
||||
self.reducedBackupDiscoveryTimeout = reducedBackupDiscoveryTimeout
|
||||
self.applicationUpdateUrlPrefix = applicationUpdateUrlPrefix
|
||||
self.backupHostOverride = backupHostOverride
|
||||
self.defaultEnableTempKeys = defaultEnableTempKeys
|
||||
self.userEnableTempKeys = userEnableTempKeys
|
||||
}
|
||||
|
||||
public init(decoder: PostboxDecoder) {
|
||||
self.reducedBackupDiscoveryTimeout = decoder.decodeInt32ForKey("reducedBackupDiscoveryTimeout", orElse: 0) != 0
|
||||
self.applicationUpdateUrlPrefix = decoder.decodeOptionalStringForKey("applicationUpdateUrlPrefix")
|
||||
self.backupHostOverride = decoder.decodeOptionalStringForKey("backupHostOverride")
|
||||
self.defaultEnableTempKeys = decoder.decodeBoolForKey("defaultEnableTempKeys", orElse: true)
|
||||
self.userEnableTempKeys = decoder.decodeOptionalBoolForKey("userEnableTempKeys")
|
||||
}
|
||||
|
||||
public func encode(_ encoder: PostboxEncoder) {
|
||||
@ -33,6 +39,12 @@ public struct NetworkSettings: PreferencesEntry, Equatable {
|
||||
} else {
|
||||
encoder.encodeNil(forKey: "backupHostOverride")
|
||||
}
|
||||
encoder.encodeBool(self.defaultEnableTempKeys, forKey: "defaultEnableTempKeys")
|
||||
if let userEnableTempKeys = self.userEnableTempKeys {
|
||||
encoder.encodeBool(userEnableTempKeys, forKey: "userEnableTempKeys")
|
||||
} else {
|
||||
encoder.encodeNil(forKey: "userEnableTempKeys")
|
||||
}
|
||||
}
|
||||
|
||||
public func isEqual(to: PreferencesEntry) -> Bool {
|
||||
|
@ -23,6 +23,15 @@ func updateAppConfigurationOnce(postbox: Postbox, network: Network) -> Signal<Vo
|
||||
configuration.data = data
|
||||
return configuration
|
||||
})
|
||||
var defaultEnableTempKeys = true
|
||||
if let value = data["disable_pfs"] as? Bool {
|
||||
defaultEnableTempKeys = false
|
||||
}
|
||||
updateNetworkSettingsInteractively(transaction: transaction, network: nil, { settings in
|
||||
var settings = settings
|
||||
settings.defaultEnableTempKeys = defaultEnableTempKeys
|
||||
return settings
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -474,6 +474,17 @@ func initializedNetwork(accountId: AccountRecordId, arguments: NetworkInitializa
|
||||
}
|
||||
}
|
||||
|
||||
let useTempAuthKeys: Bool
|
||||
if let networkSettings = networkSettings {
|
||||
if let userEnableTempKeys = networkSettings.userEnableTempKeys {
|
||||
useTempAuthKeys = userEnableTempKeys
|
||||
} else {
|
||||
useTempAuthKeys = networkSettings.defaultEnableTempKeys
|
||||
}
|
||||
} else {
|
||||
useTempAuthKeys = true
|
||||
}
|
||||
|
||||
var contextValue: MTContext?
|
||||
sharedContexts.with { store in
|
||||
let key = SharedContextStore.Key(accountId: accountId)
|
||||
@ -483,7 +494,7 @@ func initializedNetwork(accountId: AccountRecordId, arguments: NetworkInitializa
|
||||
context = current
|
||||
context.updateApiEnvironment({ _ in return apiEnvironment})
|
||||
} else {
|
||||
context = MTContext(serialization: serialization, encryptionProvider: arguments.encryptionProvider, apiEnvironment: apiEnvironment, isTestingEnvironment: testingEnvironment, useTempAuthKeys: true)!
|
||||
context = MTContext(serialization: serialization, encryptionProvider: arguments.encryptionProvider, apiEnvironment: apiEnvironment, isTestingEnvironment: testingEnvironment, useTempAuthKeys: useTempAuthKeys)!
|
||||
store.contexts[key] = context
|
||||
}
|
||||
contextValue = context
|
||||
|
@ -17,7 +17,7 @@ extension NetworkSettings {
|
||||
}
|
||||
}
|
||||
|
||||
public func updateNetworkSettingsInteractively(transaction: Transaction, network: Network, _ f: @escaping (NetworkSettings) -> NetworkSettings) {
|
||||
public func updateNetworkSettingsInteractively(transaction: Transaction, network: Network?, _ f: @escaping (NetworkSettings) -> NetworkSettings) {
|
||||
var updateNetwork = false
|
||||
var updatedSettings: NetworkSettings?
|
||||
transaction.updatePreferencesEntry(key: PreferencesKeys.networkSettings, { current in
|
||||
@ -33,7 +33,7 @@ public func updateNetworkSettingsInteractively(transaction: Transaction, network
|
||||
return updated
|
||||
})
|
||||
|
||||
if updateNetwork, let updatedSettings = updatedSettings {
|
||||
if let network = network, updateNetwork, let updatedSettings = updatedSettings {
|
||||
network.context.updateApiEnvironment { current in
|
||||
return current?.withUpdatedNetworkSettings(updatedSettings.mtNetworkSettings)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user