mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
46 lines
1.3 KiB
Swift
46 lines
1.3 KiB
Swift
import Foundation
|
|
import Postbox
|
|
import SwiftSignalKit
|
|
|
|
public struct VoipDerivedState: Equatable, PreferencesEntry {
|
|
public var data: Data
|
|
|
|
public static var `default`: VoipDerivedState {
|
|
return VoipDerivedState(data: Data())
|
|
}
|
|
|
|
public init(data: Data) {
|
|
self.data = data
|
|
}
|
|
|
|
public init(decoder: PostboxDecoder) {
|
|
self.data = decoder.decodeDataForKey("data") ?? Data()
|
|
}
|
|
|
|
public func encode(_ encoder: PostboxEncoder) {
|
|
encoder.encodeData(self.data, forKey: "data")
|
|
}
|
|
|
|
public func isEqual(to: PreferencesEntry) -> Bool {
|
|
if let to = to as? VoipDerivedState {
|
|
return self == to
|
|
} else {
|
|
return false
|
|
}
|
|
}
|
|
}
|
|
|
|
public func updateVoipDerivedStateInteractively(postbox: Postbox, _ f: @escaping (VoipDerivedState) -> VoipDerivedState) -> Signal<Void, NoError> {
|
|
return postbox.transaction { transaction -> Void in
|
|
transaction.updatePreferencesEntry(key: ApplicationSpecificPreferencesKeys.voipDerivedState, { entry in
|
|
let currentSettings: VoipDerivedState
|
|
if let entry = entry as? VoipDerivedState {
|
|
currentSettings = entry
|
|
} else {
|
|
currentSettings = .default
|
|
}
|
|
return f(currentSettings)
|
|
})
|
|
}
|
|
}
|