Peter 5c1613d104 Add 'submodules/TelegramCore/' from commit '9561227540acef69894e6546395ab223a6233600'
git-subtree-dir: submodules/TelegramCore
git-subtree-mainline: 971273e8f8f49a47f14b251d2f35e3445a61fc3f
git-subtree-split: 9561227540acef69894e6546395ab223a6233600
2019-06-11 18:59:08 +01:00

68 lines
1.8 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
public final class CoreSettings: PreferencesEntry, Equatable {
public let fastForward: Bool
public static var defaultSettings = CoreSettings(fastForward: true)
public init(fastForward: Bool) {
self.fastForward = fastForward
}
public init(decoder: PostboxDecoder) {
self.fastForward = decoder.decodeInt32ForKey("fastForward", orElse: 0) != 0
}
public func encode(_ encoder: PostboxEncoder) {
encoder.encodeInt32(self.fastForward ? 1 : 0, forKey: "fastForward")
}
public func withUpdatedFastForward(_ fastForward: Bool) -> CoreSettings {
return CoreSettings(fastForward: fastForward)
}
public func isEqual(to: PreferencesEntry) -> Bool {
guard let to = to as? CoreSettings else {
return false
}
return self == to
}
public static func ==(lhs: CoreSettings, rhs: CoreSettings) -> Bool {
if lhs.fastForward != rhs.fastForward {
return false
}
return true
}
}
public func updateCoreSettings(postbox: Postbox, _ f: @escaping (CoreSettings) -> CoreSettings) -> Signal<Void, NoError> {
return postbox.transaction { transaction -> Void in
var updated: CoreSettings?
transaction.updatePreferencesEntry(key: PreferencesKeys.coreSettings, { current in
if let current = current as? CoreSettings {
updated = f(current)
return updated
} else {
updated = f(CoreSettings.defaultSettings)
return updated
}
})
}
}