Swiftgram/TelegramUI/ExperimentalUISettings.swift
Peter 6b8adfc5b0 ChatListNode: improved archive handling
ItemListEditableNode: improved swipe actions
2019-04-21 23:53:32 +04:00

54 lines
2.2 KiB
Swift

import Foundation
import Postbox
import SwiftSignalKit
public struct ExperimentalUISettings: Equatable, PreferencesEntry {
public var keepChatNavigationStack: Bool
public var skipReadHistory: Bool
public var crashOnLongQueries: Bool
public static var defaultSettings: ExperimentalUISettings {
return ExperimentalUISettings(keepChatNavigationStack: false, skipReadHistory: false, crashOnLongQueries: false)
}
public init(keepChatNavigationStack: Bool, skipReadHistory: Bool, crashOnLongQueries: Bool) {
self.keepChatNavigationStack = keepChatNavigationStack
self.skipReadHistory = skipReadHistory
self.crashOnLongQueries = crashOnLongQueries
}
public init(decoder: PostboxDecoder) {
self.keepChatNavigationStack = decoder.decodeInt32ForKey("keepChatNavigationStack", orElse: 0) != 0
self.skipReadHistory = decoder.decodeInt32ForKey("skipReadHistory", orElse: 0) != 0
self.crashOnLongQueries = decoder.decodeInt32ForKey("crashOnLongQueries", orElse: 0) != 0
}
public func encode(_ encoder: PostboxEncoder) {
encoder.encodeInt32(self.keepChatNavigationStack ? 1 : 0, forKey: "keepChatNavigationStack")
encoder.encodeInt32(self.skipReadHistory ? 1 : 0, forKey: "skipReadHistory")
encoder.encodeInt32(self.crashOnLongQueries ? 1 : 0, forKey: "crashOnLongQueries")
}
public func isEqual(to: PreferencesEntry) -> Bool {
if let to = to as? ExperimentalUISettings {
return self == to
} else {
return false
}
}
}
func updateExperimentalUISettingsInteractively(accountManager: AccountManager, _ f: @escaping (ExperimentalUISettings) -> ExperimentalUISettings) -> Signal<Void, NoError> {
return accountManager.transaction { transaction -> Void in
transaction.updateSharedData(ApplicationSpecificSharedDataKeys.experimentalUISettings, { entry in
let currentSettings: ExperimentalUISettings
if let entry = entry as? ExperimentalUISettings {
currentSettings = entry
} else {
currentSettings = .defaultSettings
}
return f(currentSettings)
})
}
}