mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
52 lines
1.7 KiB
Swift
52 lines
1.7 KiB
Swift
import Foundation
|
|
#if os(macOS)
|
|
import PostboxMac
|
|
import SwiftSignalKitMac
|
|
import MtProtoKitMac
|
|
#else
|
|
import Postbox
|
|
import SwiftSignalKit
|
|
#if BUCK
|
|
import MtProtoKit
|
|
#else
|
|
import MtProtoKitDynamic
|
|
#endif
|
|
#endif
|
|
|
|
import SyncCore
|
|
|
|
public func updateNetworkSettingsInteractively(postbox: Postbox, network: Network, _ f: @escaping (NetworkSettings) -> NetworkSettings) -> Signal<Void, NoError> {
|
|
return postbox.transaction { transaction -> Void in
|
|
updateNetworkSettingsInteractively(transaction: transaction, network: network, f)
|
|
}
|
|
}
|
|
|
|
extension NetworkSettings {
|
|
var mtNetworkSettings: MTNetworkSettings {
|
|
return MTNetworkSettings(reducedBackupDiscoveryTimeout: self.reducedBackupDiscoveryTimeout)
|
|
}
|
|
}
|
|
|
|
public func updateNetworkSettingsInteractively(transaction: Transaction, network: Network, _ f: @escaping (NetworkSettings) -> NetworkSettings) {
|
|
var updateNetwork = false
|
|
var updatedSettings: NetworkSettings?
|
|
transaction.updatePreferencesEntry(key: PreferencesKeys.networkSettings, { current in
|
|
let previous = (current as? NetworkSettings) ?? NetworkSettings.defaultSettings
|
|
let updated = f(previous)
|
|
updatedSettings = updated
|
|
if updated.reducedBackupDiscoveryTimeout != previous.reducedBackupDiscoveryTimeout {
|
|
updateNetwork = true
|
|
}
|
|
if updated.backupHostOverride != previous.backupHostOverride {
|
|
updateNetwork = true
|
|
}
|
|
return updated
|
|
})
|
|
|
|
if updateNetwork, let updatedSettings = updatedSettings {
|
|
network.context.updateApiEnvironment { current in
|
|
return current?.withUpdatedNetworkSettings(updatedSettings.mtNetworkSettings)
|
|
}
|
|
}
|
|
}
|