mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-09-17 09:10:30 +00:00
Refactoring
This commit is contained in:
parent
2f9189d220
commit
9e4853d9a7
@ -202,7 +202,6 @@ private enum PreferencesKeyValues: Int32 {
|
||||
case globalNotifications = 0
|
||||
case suggestedLocalization = 3
|
||||
case limitsConfiguration = 4
|
||||
case coreSettings = 7
|
||||
case contentPrivacySettings = 8
|
||||
case networkSettings = 9
|
||||
case remoteStorageConfiguration = 10
|
||||
@ -251,12 +250,6 @@ public struct PreferencesKeys {
|
||||
return key
|
||||
}()
|
||||
|
||||
public static let coreSettings: ValueBoxKey = {
|
||||
let key = ValueBoxKey(length: 4)
|
||||
key.setInt32(0, value: PreferencesKeyValues.coreSettings.rawValue)
|
||||
return key
|
||||
}()
|
||||
|
||||
public static let contentPrivacySettings: ValueBoxKey = {
|
||||
let key = ValueBoxKey(length: 4)
|
||||
key.setInt32(0, value: PreferencesKeyValues.contentPrivacySettings.rawValue)
|
||||
|
@ -1,59 +0,0 @@
|
||||
import Foundation
|
||||
import Postbox
|
||||
import SwiftSignalKit
|
||||
import MtProtoKit
|
||||
|
||||
import SyncCore
|
||||
|
||||
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
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user